From 7324823b3eb93fb1f2d9db793b2ca8940171dbe5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 5 Nov 2025 15:52:38 -0500 Subject: [PATCH] emscripten: Send resize events when screen orientation changes. The canvas _might_ be changing sizes, if you've set up your own CSS for it, or are using SDL_HINT_EMSCRIPTEN_FILL_DOCUMENT. Reference Issue #7359. --- src/video/emscripten/SDL_emscriptenevents.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 7e5a7e561b..87f0cf1b31 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -612,6 +612,19 @@ static EM_BOOL Emscripten_HandleOrientationChange(int eventType, const Emscripte SDL_WindowData *window_data = (SDL_WindowData *) userData; SDL_SendDisplayEvent(SDL_GetVideoDisplayForWindow(window_data->window), SDL_EVENT_DISPLAY_ORIENTATION, orientation, 0); + // fake a UI event so we can tell the app the canvas might have resized. + EmscriptenUiEvent uiEvent; + SDL_zero(uiEvent); + uiEvent.documentBodyClientWidth = MAIN_THREAD_EM_ASM_INT( { return document.body.clientWidth; } ); + uiEvent.documentBodyClientHeight = MAIN_THREAD_EM_ASM_INT( { return document.body.clientHeight; } ); + uiEvent.windowInnerWidth = MAIN_THREAD_EM_ASM_INT( { return window.innerWidth; } ); + uiEvent.windowInnerHeight = MAIN_THREAD_EM_ASM_INT( { return window.innerHeight; } ); + uiEvent.windowOuterWidth = MAIN_THREAD_EM_ASM_INT( { return window.outerWidth; } ); + uiEvent.windowOuterHeight = MAIN_THREAD_EM_ASM_INT( { return window.outerHeight; } ); + uiEvent.scrollTop = MAIN_THREAD_EM_ASM_INT( { return window.pageXOffset; } ); + uiEvent.scrollLeft = MAIN_THREAD_EM_ASM_INT( { return window.pageYOffset; } ); + Emscripten_HandleResize(EMSCRIPTEN_EVENT_RESIZE, &uiEvent, userData); + return 0; }