3333 + "Did you apt install libglfw3-wayland?"
3434 )
3535
36+ # Some glfw functions are not always available
37+ set_window_content_scale_callback = lambda * args : None # noqa: E731
38+ set_window_maximize_callback = lambda * args : None # noqa: E731
39+ get_window_content_scale = lambda * args : (1 , 1 ) # noqa: E731
40+
41+ if hasattr (glfw , "set_window_content_scale_callback" ):
42+ set_window_content_scale_callback = glfw .set_window_content_scale_callback
43+ if hasattr (glfw , "set_window_maximize_callback" ):
44+ set_window_maximize_callback = glfw .set_window_maximize_callback
45+ if hasattr (glfw , "get_window_content_scale" ):
46+ get_window_content_scale = glfw .get_window_content_scale
47+
3648
3749all_glfw_canvases = weakref .WeakSet ()
3850
@@ -132,12 +144,12 @@ def __init__(self, *, size=None, title=None, **kwargs):
132144
133145 # Register callbacks. We may get notified too often, but that's
134146 # ok, they'll result in a single draw.
135- glfw .set_window_content_scale_callback (self ._window , self ._on_pixelratio_change )
136147 glfw .set_framebuffer_size_callback (self ._window , self ._on_size_change )
137148 glfw .set_window_close_callback (self ._window , self ._on_close )
138149 glfw .set_window_refresh_callback (self ._window , self ._on_window_dirty )
139150 glfw .set_window_focus_callback (self ._window , self ._on_window_dirty )
140- glfw .set_window_maximize_callback (self ._window , self ._on_window_dirty )
151+ set_window_content_scale_callback (self ._window , self ._on_pixelratio_change )
152+ set_window_maximize_callback (self ._window , self ._on_window_dirty )
141153
142154 # User input
143155 self ._key_modifiers = set ()
@@ -189,7 +201,7 @@ def _determine_size(self):
189201 # Because the value of get_window_size is in physical-pixels
190202 # on some systems and in logical-pixels on other, we use the
191203 # framebuffer size and pixel ratio to derive the logical size.
192- pixel_ratio = glfw . get_window_content_scale (self ._window )[0 ]
204+ pixel_ratio = get_window_content_scale (self ._window )[0 ]
193205 psize = glfw .get_framebuffer_size (self ._window )
194206 psize = int (psize [0 ]), int (psize [1 ])
195207
@@ -213,7 +225,7 @@ def _set_logical_size(self, new_logical_size):
213225 # Here, we simply do a quick test so we can compensate.
214226
215227 # The current screen size and physical size, and its ratio
216- pixel_ratio = glfw . get_window_content_scale (self ._window )[0 ]
228+ pixel_ratio = get_window_content_scale (self ._window )[0 ]
217229 ssize = glfw .get_window_size (self ._window )
218230 psize = glfw .get_framebuffer_size (self ._window )
219231
0 commit comments