11"""Neovim Gtk+ UI."""
22from __future__ import print_function , division
33import math
4+ import sys
45
56from functools import partial
67
@@ -79,7 +80,6 @@ class GtkUI(object):
7980
8081 def __init__ (self , font ):
8182 """Initialize the UI instance."""
82- self ._last_cursor = (1 , 1 )
8383 self ._redraw_arg = None
8484 self ._foreground = - 1
8585 self ._background = - 1
@@ -94,9 +94,9 @@ def __init__(self, font):
9494 self ._pressed = None
9595 self ._invalid = None
9696 self ._reset_cache ()
97+ self ._curgrid = 0
9798 self .grids = {}
9899 self .g = None
99- self .g_focus = None
100100
101101 def create_drawing_area (self , handle ):
102102 self .g = Grid ()
@@ -138,8 +138,7 @@ def start(self, bridge):
138138 im_context .set_use_preedit (False ) # TODO: preedit at cursor position
139139 im_context .connect ('commit' , self ._gtk_input )
140140 self ._im_context = im_context
141- self ._nvim_set_grid (1 )
142- self ._nvim_set_grid_focus (1 )
141+ self .create_drawing_area (1 )
143142 self ._bridge = bridge
144143 Gtk .main ()
145144
@@ -153,6 +152,11 @@ def wrapper():
153152 apply_updates ()
154153 self ._flush ()
155154 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 ())
156160 #self._screen_invalid()
157161 for g in self .grids .values ():
158162 g ._drawing_area .queue_draw ()
@@ -161,25 +165,20 @@ def wrapper():
161165 def _screen_invalid (self ):
162166 self .g ._drawing_area .queue_draw ()
163167
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 )
166170 self ._curgrid = handle
167171 if handle not in self .grids :
168172 self .create_drawing_area (handle )
169173 self .g = self .grids [handle ]
170174 self ._screen = self .g ._screen
171- # HACK, cursor is really shared, not grid specific
172175 if self ._screen is not None :
173- row , col = self . _last_cursor
176+ # TODO: this should really be asserted on the nvim side
174177 row , col = min (row , self ._screen .rows ), min (col , self ._screen .columns )
175178 self ._screen .cursor_goto (row ,col )
176179 self ._drawing_area = self .g ._drawing_area
177180 self ._window = self .g ._window
178- self ._nvim_set_grid_focus (handle )
179181
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 ())
183182
184183 def _nvim_resize (self , columns , rows ):
185184 print ("da" )
@@ -221,7 +220,6 @@ def _nvim_eol_clear(self):
221220 self ._screen .eol_clear ()
222221
223222 def _nvim_cursor_goto (self , row , col ):
224- self ._last_cursor = (row , col )
225223 self ._screen .cursor_goto (row , col )
226224
227225 def _nvim_busy_start (self ):
@@ -306,7 +304,6 @@ def _nvim_put(self, text):
306304 #self._redraw_glitch_fix()
307305 # Update internal screen
308306 self ._screen .put (self ._get_pango_text (text ), self ._attrs )
309- self ._last_cursor = (self ._screen .row , self ._screen .col )
310307 self .g ._pending [1 ] = min (self ._screen .col - 1 , self .g ._pending [1 ])
311308 self .g ._pending [2 ] = max (self ._screen .col , self .g ._pending [2 ])
312309
@@ -347,14 +344,12 @@ def _gtk_draw(self, g, wid, cr):
347344 cr .set_source_surface (g ._cairo_surface , 0 , 0 )
348345 cr .paint ()
349346 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 :
351348 # Cursor is drawn separately in the window. This approach is
352349 # simpler because it doesn't taint the internal cairo surface,
353350 # 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 ()
358353 self ._pango_draw (g , row , col , [(text , attrs ,)], cr = cr , cursor = True )
359354 x , y = self ._get_coords (row , col )
360355 currect = Rectangle (x , y , self ._cell_pixel_width ,
@@ -464,7 +459,7 @@ def _gtk_input(self, widget, input_str, *args):
464459 def _start_blinking (self ):
465460 def blink (* args ):
466461 self ._blink = not self ._blink
467- self .g_focus ._drawing_area .queue_draw ()
462+ self .g ._drawing_area .queue_draw ()
468463 #self._screen_invalid()
469464 self ._blink_timer_id = GLib .timeout_add (500 , blink )
470465 if self ._blink_timer_id :
@@ -540,7 +535,7 @@ def _pango_draw(self, g, row, col, data, cr=None, cursor=False):
540535 if not cr :
541536 cr = g ._cairo_context
542537 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 :
544539 cr .rectangle (x , y , self ._cell_pixel_width / 4 ,
545540 self ._cell_pixel_height )
546541 cr .clip ()
0 commit comments