SDL
SDL copied to clipboard
Emscripten chrome SDL_GetWindowFlags bug
The fullscreen flag is stuck on after pressing the escape key on chrome. The bug was introduced in https://github.com/libsdl-org/SDL/commit/d6d2c958a4d1fd5a95e1243c05a4c218444ded2b. The bug was fixed for safari/firefox but wasn't fixed for chrome in https://github.com/libsdl-org/SDL/commit/6711caa4312b95d90ce216123b786a34457f9f52. Here's how to reproduce the bug:
- call SDL_SetWindowFullscreen(window, true);
- press the escape button to exit fullscreen
- SDL_GetWindowFlags(window) is returning SDL_WINDOW_FULLSCREEN even though the screen is no longer fullscreen
This is on M3 macbook air macOS 15.7.2
I did some more testing, this function is failing after pressing the escape key. Emscripten_GetFocusedWindow returns NULL and Emscripten_HandleFullscreenChange never gets called.
https://github.com/libsdl-org/SDL/blob/62639fdf88ce364a97a9f9ff06f32f0d0c6f4c0d/src/video/emscripten/SDL_emscriptenevents.c#L497-L505
I was able to fix this and https://github.com/libsdl-org/SDL/issues/14627 by replacing 'Emscripten_GetFocusedWindow(device);' with 'device->windows'. This was the behavior before https://github.com/libsdl-org/SDL/commit/d6d2c958a4d1fd5a95e1243c05a4c218444ded2b when it was using SDL_WindowData for the userData parameter.
Oh, interesting.
I'm going to close #14627 as a dupe and deal with this here.
This block is failing:
https://github.com/libsdl-org/SDL/blob/62639fdf88ce364a97a9f9ff06f32f0d0c6f4c0d/src/video/emscripten/SDL_emscriptenevents.c#L273-L276
document.activeElement is <body> and document.querySelector(id) is <canvas>. Once I added 'tabindex=-1' to my canvas element this problem goes away.
So I think checking for the focused window is wrong here in any case; EmscriptenFullscreenChangeEvent can tell us the element that was entering/existing fullscreen, so we can probably find the canvas id of an existing window that matches that...but also, device->windows is at least a safe check for 3.4.0, because we only allow a single SDL_Window at the moment anyhow.
Okay, this should be fixed now, please try the latest from revision control and let me know if it's still having problems!
That fixed it, thanks!