@@ -147,7 +147,7 @@ def get_physical_size(window):
147
147
148
148
149
149
def enable_glfw ():
150
- glfw .init ()
150
+ glfw .init () # this also resets all window hints
151
151
glfw ._rc_alive = True
152
152
153
153
@@ -180,13 +180,15 @@ def __init__(self, *args, present_method=None, **kwargs):
180
180
# Set window hints
181
181
glfw .window_hint (glfw .CLIENT_API , glfw .NO_API )
182
182
glfw .window_hint (glfw .RESIZABLE , True )
183
+ glfw .window_hint (glfw .VISIBLE , False ) # start hidden
183
184
184
185
# Create the window (the initial size may not be in logical pixels)
185
186
self ._window = glfw .create_window (640 , 480 , "" , None , None )
186
187
187
188
# Other internal variables
188
189
self ._changing_pixel_ratio = False
189
190
self ._is_minimized = False
191
+ self ._is_in_poll_events = False
190
192
191
193
# Register callbacks. We may get notified too often, but that's
192
194
# ok, they'll result in a single draw.
@@ -218,6 +220,9 @@ def __init__(self, *args, present_method=None, **kwargs):
218
220
# Set size, title, etc.
219
221
self ._final_canvas_init ()
220
222
223
+ # Now show the window
224
+ glfw .show_window (self ._window )
225
+
221
226
def _on_window_dirty (self , * args ):
222
227
self .request_draw ()
223
228
@@ -297,7 +302,11 @@ def _set_logical_size(self, new_logical_size):
297
302
298
303
def _rc_gui_poll (self ):
299
304
glfw .post_empty_event () # Awake the event loop, if it's in wait-mode
300
- glfw .poll_events ()
305
+ try :
306
+ self ._is_in_poll_events = True
307
+ glfw .poll_events () # Note: this blocks when the window is being resized
308
+ finally :
309
+ self ._is_in_poll_events = False
301
310
self ._maybe_close ()
302
311
303
312
def _rc_get_present_methods (self ):
@@ -368,6 +377,15 @@ def _on_pixelratio_change(self, *args):
368
377
def _on_size_change (self , * args ):
369
378
self ._determine_size ()
370
379
self .request_draw ()
380
+ # During a resize, the glfw.poll_events() function blocks, so
381
+ # our event-loop is on pause. However, glfw still sends resize
382
+ # events, and we can use these to draw, to get a smoother
383
+ # experience. Note that if the user holds the mouse still while
384
+ # resizing, there are no draws. Also note that any animations
385
+ # that rely on the event-loop are paused (only animations
386
+ # updated in the draw callback are alive).
387
+ if self ._is_in_poll_events and not self ._is_minimized :
388
+ self ._draw_frame_and_present ()
371
389
372
390
def _on_mouse_button (self , window , but , action , mods ):
373
391
# Map button being changed, which we use to update self._pointer_buttons.
0 commit comments