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.
This commit is contained in:
Ryan C. Gordon
2025-11-05 15:52:38 -05:00
parent b09b557fc6
commit 7324823b3e

View File

@@ -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;
}