30
30
)
31
31
32
32
_GOBJECT_GE_3_47 = gi .version_info >= (3 , 47 , 0 )
33
+ _GTK_GE_4_12 = Gtk .check_version (4 , 12 , 0 ) is None
33
34
34
35
35
36
class FigureCanvasGTK4 (_FigureCanvasGTK , Gtk .DrawingArea ):
@@ -48,7 +49,10 @@ def __init__(self, figure=None):
48
49
49
50
self .set_draw_func (self ._draw_func )
50
51
self .connect ('resize' , self .resize_event )
51
- self .connect ('notify::scale-factor' , self ._update_device_pixel_ratio )
52
+ if _GTK_GE_4_12 :
53
+ self .connect ('realize' , self ._realize_event )
54
+ else :
55
+ self .connect ('notify::scale-factor' , self ._update_device_pixel_ratio )
52
56
53
57
click = Gtk .GestureClick ()
54
58
click .set_button (0 ) # All buttons.
@@ -237,10 +241,20 @@ def _get_key(self, keyval, keycode, state):
237
241
and not (mod == "shift" and unikey .isprintable ()))]
238
242
return "+" .join ([* mods , key ])
239
243
244
+ def _realize_event (self , obj ):
245
+ surface = self .get_native ().get_surface ()
246
+ surface .connect ('notify::scale' , self ._update_device_pixel_ratio )
247
+ self ._update_device_pixel_ratio ()
248
+
240
249
def _update_device_pixel_ratio (self , * args , ** kwargs ):
241
250
# We need to be careful in cases with mixed resolution displays if
242
251
# device_pixel_ratio changes.
243
- if self ._set_device_pixel_ratio (self .get_scale_factor ()):
252
+ if _GTK_GE_4_12 :
253
+ scale = self .get_native ().get_surface ().get_scale ()
254
+ else :
255
+ scale = self .get_scale_factor ()
256
+ assert scale is not None
257
+ if self ._set_device_pixel_ratio (scale ):
244
258
self .draw ()
245
259
246
260
def _draw_rubberband (self , rect ):
0 commit comments