1
1
"""Neovim Gtk+ UI."""
2
2
from __future__ import print_function , division
3
3
import math
4
+ import sys
4
5
5
6
from functools import partial
6
7
@@ -79,7 +80,6 @@ class GtkUI(object):
79
80
80
81
def __init__ (self , font ):
81
82
"""Initialize the UI instance."""
82
- self ._last_cursor = (1 , 1 )
83
83
self ._redraw_arg = None
84
84
self ._foreground = - 1
85
85
self ._background = - 1
@@ -94,9 +94,9 @@ def __init__(self, font):
94
94
self ._pressed = None
95
95
self ._invalid = None
96
96
self ._reset_cache ()
97
+ self ._curgrid = 0
97
98
self .grids = {}
98
99
self .g = None
99
- self .g_focus = None
100
100
101
101
def create_drawing_area (self , handle ):
102
102
self .g = Grid ()
@@ -138,8 +138,7 @@ def start(self, bridge):
138
138
im_context .set_use_preedit (False ) # TODO: preedit at cursor position
139
139
im_context .connect ('commit' , self ._gtk_input )
140
140
self ._im_context = im_context
141
- self ._nvim_set_grid (1 )
142
- self ._nvim_set_grid_focus (1 )
141
+ self .create_drawing_area (1 )
143
142
self ._bridge = bridge
144
143
Gtk .main ()
145
144
@@ -153,6 +152,11 @@ def wrapper():
153
152
apply_updates ()
154
153
self ._flush ()
155
154
self ._start_blinking ()
155
+ try :
156
+ print ("ctx" , self ._curgrid , self ._screen .row , self ._screen .col , file = sys .stderr )
157
+ except Exception :
158
+ pass
159
+ self ._im_context .set_client_window (self .g ._drawing_area .get_window ())
156
160
#self._screen_invalid()
157
161
for g in self .grids .values ():
158
162
g ._drawing_area .queue_draw ()
@@ -161,25 +165,20 @@ def wrapper():
161
165
def _screen_invalid (self ):
162
166
self .g ._drawing_area .queue_draw ()
163
167
164
- def _nvim_set_grid (self , handle ):
165
- print ("I" ,handle )
168
+ def _nvim_grid_cursor_goto (self , handle , row , col ):
169
+ print ("I" ,handle , file = sys . stderr )
166
170
self ._curgrid = handle
167
171
if handle not in self .grids :
168
172
self .create_drawing_area (handle )
169
173
self .g = self .grids [handle ]
170
174
self ._screen = self .g ._screen
171
- # HACK, cursor is really shared, not grid specific
172
175
if self ._screen is not None :
173
- row , col = self . _last_cursor
176
+ # TODO: this should really be asserted on the nvim side
174
177
row , col = min (row , self ._screen .rows ), min (col , self ._screen .columns )
175
178
self ._screen .cursor_goto (row ,col )
176
179
self ._drawing_area = self .g ._drawing_area
177
180
self ._window = self .g ._window
178
- self ._nvim_set_grid_focus (handle )
179
181
180
- def _nvim_set_grid_focus (self , handle ):
181
- self .g_focus = self .grids [handle ]
182
- self ._im_context .set_client_window (self .g_focus ._drawing_area .get_window ())
183
182
184
183
def _nvim_resize (self , columns , rows ):
185
184
print ("da" )
@@ -221,7 +220,6 @@ def _nvim_eol_clear(self):
221
220
self ._screen .eol_clear ()
222
221
223
222
def _nvim_cursor_goto (self , row , col ):
224
- self ._last_cursor = (row , col )
225
223
self ._screen .cursor_goto (row , col )
226
224
227
225
def _nvim_busy_start (self ):
@@ -306,7 +304,6 @@ def _nvim_put(self, text):
306
304
#self._redraw_glitch_fix()
307
305
# Update internal screen
308
306
self ._screen .put (self ._get_pango_text (text ), self ._attrs )
309
- self ._last_cursor = (self ._screen .row , self ._screen .col )
310
307
self .g ._pending [1 ] = min (self ._screen .col - 1 , self .g ._pending [1 ])
311
308
self .g ._pending [2 ] = max (self ._screen .col , self .g ._pending [2 ])
312
309
@@ -347,14 +344,12 @@ def _gtk_draw(self, g, wid, cr):
347
344
cr .set_source_surface (g ._cairo_surface , 0 , 0 )
348
345
cr .paint ()
349
346
cr .restore ()
350
- if not self ._busy and self ._blink and g is self .g_focus :
347
+ if not self ._busy and self ._blink and g is self .g :
351
348
# Cursor is drawn separately in the window. This approach is
352
349
# simpler because it doesn't taint the internal cairo surface,
353
350
# which is used for scrolling
354
- # TODO: this is a hack
355
- row , col = self ._last_cursor
356
- row , col = min (row , g ._screen .rows ), min (col , g ._screen .columns )
357
- text , attrs = g ._screen .get_cell (row , col )
351
+ row , col = g ._screen .row , g ._screen .col
352
+ text , attrs = g ._screen .get_cursor ()
358
353
self ._pango_draw (g , row , col , [(text , attrs ,)], cr = cr , cursor = True )
359
354
x , y = self ._get_coords (row , col )
360
355
currect = Rectangle (x , y , self ._cell_pixel_width ,
@@ -464,7 +459,7 @@ def _gtk_input(self, widget, input_str, *args):
464
459
def _start_blinking (self ):
465
460
def blink (* args ):
466
461
self ._blink = not self ._blink
467
- self .g_focus ._drawing_area .queue_draw ()
462
+ self .g ._drawing_area .queue_draw ()
468
463
#self._screen_invalid()
469
464
self ._blink_timer_id = GLib .timeout_add (500 , blink )
470
465
if self ._blink_timer_id :
@@ -540,7 +535,7 @@ def _pango_draw(self, g, row, col, data, cr=None, cursor=False):
540
535
if not cr :
541
536
cr = g ._cairo_context
542
537
x , y = self ._get_coords (row , col )
543
- if cursor and self ._insert_cursor and g is self .g_focus :
538
+ if cursor and self ._insert_cursor and g is self .g :
544
539
cr .rectangle (x , y , self ._cell_pixel_width / 4 ,
545
540
self ._cell_pixel_height )
546
541
cr .clip ()
0 commit comments