floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.53k stars 467 forks source link

Toggling fullscreen stalls event updates (macOS) #1052

Open GoldenbergDaniel opened 1 month ago

GoldenbergDaniel commented 1 month ago

When I toggle fullscreen on a key_down event, the key_up event does not trigger unless I release the key after the window finishes resizing, which means that I need to press the key twice to toggle fullscreen. This probably means that during the resize event, no other events get triggered at all. Is this behavior intended or a bug? I found that if I resize the window on a key_up event, I am able to toggle fullscreen as normal, so it isn't a huge issue but other apps (such as VS Code) can resize on key_down.

GoldenbergDaniel commented 1 month ago

I think this issue is related to #1046. The suggested solution is to check if the window has been unfocused, but I'm not sure if toggling fullscreen actually unfocuses the window on mac or if something else is going on.

floooh commented 1 month ago

I'll try to investigate soon-ish. When testing in the events-sapp sample, the focused/unfocused events don't seem to be fired reliably when going into and out of fullscreen via the window chrome buttons (which is a strange thing on its own).

The resize event seems to be reliably fired though which could be used after a fullscreen toggle to discard your buffered input state (or just generally when a RESIZE event is received - thinking about it, it's probably a good idea to discard buffered input on the following events: RESIZED, ICONIFIED, RESTORED, FOCUSED, UNFOCUSED, SUSPENDED, RESUMED).

I'll see if I can investigate a bit more soon-ish. My guess is that since the fullscreen toggling takes some time to animate that I'm not receiving any input events from macOS during that time until the resize is finished, and that input events are also not queued inside macOS (so they would be lost).

sokol_app.h directly forwards KEYUP and KEYDOWN events from the macOS event callbacks:

...so any strange behaviour should already happen "up" in macOS.