diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 7f0c39c086..90e63c8a19 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -497,10 +497,21 @@ static EM_BOOL Emscripten_HandleFullscreenChange(int eventType, const Emscripten static EM_BOOL Emscripten_HandleFullscreenChangeGlobal(int eventType, const EmscriptenFullscreenChangeEvent *fullscreenChangeEvent, void *userData) { SDL_VideoDevice *device = userData; - SDL_Window *window = Emscripten_GetFocusedWindow(device); + SDL_Window *window = NULL; + for (window = device->windows; window != NULL; window = window->next) { + const char *canvas_id = window->internal->canvas_id; + if (*canvas_id == '#') { + canvas_id++; + } + if (SDL_strcmp(fullscreenChangeEvent->id, canvas_id) == 0) { + break; // this is the window. + } + } + if (window) { return Emscripten_HandleFullscreenChange(eventType, fullscreenChangeEvent, window->internal); } + return EM_FALSE; }