SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Emscripten chrome SDL_GetWindowFlags bug

Open kyle-sylvestre opened this issue 1 month ago • 2 comments

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:

  1. call SDL_SetWindowFullscreen(window, true);
  2. press the escape button to exit fullscreen
  3. 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

kyle-sylvestre avatar Dec 09 '25 03:12 kyle-sylvestre

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

kyle-sylvestre avatar Dec 09 '25 06:12 kyle-sylvestre

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.

kyle-sylvestre avatar Dec 09 '25 07:12 kyle-sylvestre

Oh, interesting.

I'm going to close #14627 as a dupe and deal with this here.

icculus avatar Dec 12 '25 16:12 icculus

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.

kyle-sylvestre avatar Dec 12 '25 21:12 kyle-sylvestre

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.

icculus avatar Dec 15 '25 04:12 icculus

Okay, this should be fixed now, please try the latest from revision control and let me know if it's still having problems!

icculus avatar Dec 15 '25 17:12 icculus

That fixed it, thanks!

kyle-sylvestre avatar Dec 15 '25 20:12 kyle-sylvestre