Explorar el Código

emscripten: Allow resize events on fullscreen windows.

Fixes browsers on phone that change screen orientation during fullscreen not
getting a resize event.

Fixes #15024.
Ryan C. Gordon hace 2 semanas
padre
commit
0f2d415dee
Se han modificado 1 ficheros con 36 adiciones y 35 borrados
  1. 36 35
      src/video/emscripten/SDL_emscriptenevents.c

+ 36 - 35
src/video/emscripten/SDL_emscriptenevents.c

@@ -519,47 +519,48 @@ static EM_BOOL Emscripten_HandleResize(int eventType, const EmscriptenUiEvent *u
 {
     SDL_WindowData *window_data = userData;
 
-    if (!(window_data->window->flags & SDL_WINDOW_FULLSCREEN)) {
-        bool force = false;
-
-        // update pixel ratio
-        if (window_data->window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
-            if (window_data->pixel_ratio != emscripten_get_device_pixel_ratio()) {
-                window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
-                force = true;
-            }
-        }
-        const bool fill_document = (Emscripten_fill_document_window == window_data->window);
-        if (fill_document || (window_data->window->flags & SDL_WINDOW_RESIZABLE)) {
-            double w, h;
-            if (fill_document) {
-                w = (double) uiEvent->windowInnerWidth;
-                h = (double) uiEvent->windowInnerHeight;
-            } else {
-                SDL_assert(window_data->window->flags & SDL_WINDOW_RESIZABLE);
-                w = window_data->window->w;
-                h = window_data->window->h;
-                // this will only work if the canvas size is set through css
-                if (window_data->external_size) {
-                    emscripten_get_element_css_size(window_data->canvas_id, &w, &h);
-                }
-            }
+    bool force = false;
 
-            emscripten_set_canvas_element_size(window_data->canvas_id, SDL_lroundf(w * window_data->pixel_ratio), SDL_lroundf(h * window_data->pixel_ratio));
+    // update pixel ratio
+    if (window_data->window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
+        if (window_data->pixel_ratio != emscripten_get_device_pixel_ratio()) {
+            window_data->pixel_ratio = emscripten_get_device_pixel_ratio();
+            force = true;
+        }
+    }
 
-            // set_canvas_size unsets this
-            if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
-                emscripten_set_element_css_size(window_data->canvas_id, w, h);
+    const bool fill_document = (Emscripten_fill_document_window == window_data->window);
+    const bool fullscreen = (window_data->window->flags & SDL_WINDOW_FULLSCREEN) != 0;  // fullscreen windows can resize on Emscripten, and the canvas should fill it.
+    const bool resizable = (window_data->window->flags & SDL_WINDOW_RESIZABLE) != 0;
+    if (fill_document || fullscreen || resizable) {
+        double w, h;
+        if (fill_document || fullscreen) {
+            w = (double) uiEvent->windowInnerWidth;
+            h = (double) uiEvent->windowInnerHeight;
+        } else {
+            SDL_assert(window_data->window->flags & SDL_WINDOW_RESIZABLE);
+            w = window_data->window->w;
+            h = window_data->window->h;
+            // this will only work if the canvas size is set through css
+            if (window_data->external_size) {
+                emscripten_get_element_css_size(window_data->canvas_id, &w, &h);
             }
+        }
 
-            if (force) {
-                // force the event to trigger, so pixel ratio changes can be handled
-                window_data->window->w = 0;
-                window_data->window->h = 0;
-            }
+        emscripten_set_canvas_element_size(window_data->canvas_id, SDL_lroundf(w * window_data->pixel_ratio), SDL_lroundf(h * window_data->pixel_ratio));
 
-            SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, SDL_lroundf(w), SDL_lroundf(h));
+        // set_canvas_size unsets this
+        if (!window_data->external_size && window_data->pixel_ratio != 1.0f) {
+            emscripten_set_element_css_size(window_data->canvas_id, w, h);
         }
+
+        if (force) {
+            // force the event to trigger, so pixel ratio changes can be handled
+            window_data->window->w = 0;
+            window_data->window->h = 0;
+        }
+
+        SDL_SendWindowEvent(window_data->window, SDL_EVENT_WINDOW_RESIZED, SDL_lroundf(w), SDL_lroundf(h));
     }
 
     return 0;