From 0f2d415dee649fce76d41c768a4afc033ea67ebf Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 17 Feb 2026 18:40:24 -0500
Subject: [PATCH] emscripten: Allow resize events on fullscreen windows.
Fixes browsers on phone that change screen orientation during fullscreen not
getting a resize event.
Fixes #15024.
---
src/video/emscripten/SDL_emscriptenevents.c | 71 +++++++++++----------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 4d91b7904ba35..ddd47d2b46960 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/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;