Browse Source

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.
Ryan C. Gordon 1 month ago
parent
commit
7324823b3e
1 changed files with 13 additions and 0 deletions
  1. 13 0
      src/video/emscripten/SDL_emscriptenevents.c

+ 13 - 0
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_WindowData *window_data = (SDL_WindowData *) userData;
     SDL_SendDisplayEvent(SDL_GetVideoDisplayForWindow(window_data->window), SDL_EVENT_DISPLAY_ORIENTATION, orientation, 0);
     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;
     return 0;
 }
 }