From b618d7b35bebc095b16af98a47acfa45f32d6f3d Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sat, 17 May 2025 21:08:07 -0400 Subject: [PATCH 1/5] use parentElement's dimensions for width/height --- src/platforms/rcore_web.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index bf5a6ba5a..cf2ce0065 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1681,9 +1681,9 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent * // This event is called whenever the window changes sizes, // so the size of the canvas object is explicitly retrieved below - int width = EM_ASM_INT( return window.innerWidth; ); - int height = EM_ASM_INT( return window.innerHeight; ); - + int width = EM_ASM_INT( return (!!document.fullscreenElement) ? window.innerWidth : Module.canvas.parentElement.clientWidth; ); + int height = EM_ASM_INT( return (!!document.fullscreenElement) ? window.innerHeight : Module.canvas.parentElement.clientHeight; ); + if (width < (int)CORE.Window.screenMin.width) width = CORE.Window.screenMin.width; else if ((width > (int)CORE.Window.screenMax.width) && (CORE.Window.screenMax.width > 0)) width = CORE.Window.screenMax.width; From d0d42e78ead76e870ae571e81978e67ce231c2d4 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sat, 17 May 2025 21:08:35 -0400 Subject: [PATCH 2/5] inform glfw that a change of window size has taken place --- src/platforms/rcore_web.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index cf2ce0065..ad64a2595 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1692,6 +1692,8 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent * emscripten_set_canvas_element_size(GetCanvasId(), width, height); + glfwSetWindowSize(platform.handle, width, height); // inform glfw of the new size + SetupViewport(width, height); // Reset viewport and projection matrix for new size CORE.Window.currentFbo.width = width; From 358917ffc3103fc0baba29fc4a7bce2ab4ba4bf0 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sat, 17 May 2025 21:08:57 -0400 Subject: [PATCH 3/5] trigger resize event when going into and out of fullscreen mode --- src/platforms/rcore_web.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index ad64a2595..cb77a8575 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1662,6 +1662,9 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte } } + // trigger resize event after a brief pause to ensure the canvas exists to resize + EM_ASM({ setTimeout(function() { window.dispatchEvent(new Event("resize")); }, 50); }); + return 1; // The event was consumed by the callback handler } From cf2099f18a59116e545e15db3e67aa3aee9b2770 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sat, 24 May 2025 20:33:27 -0400 Subject: [PATCH 4/5] the holy grail --- src/platforms/rcore_web.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index cb77a8575..117a2348e 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1131,7 +1131,15 @@ int InitPlatform(void) if ((CORE.Window.flags & FLAG_WINDOW_UNDECORATED) > 0) glfwWindowHint(GLFW_DECORATED, GLFW_FALSE); // Border and buttons on Window else glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); // Decorated window - if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window + if ((CORE.Window.flags & FLAG_WINDOW_RESIZABLE) > 0) + { + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // Resizable window + + // bypass hidpi code block in libglfw.js + // https://github.com/raysan5/raylib/pull/4945#issuecomment-2906956170 + //------------------------------------------------------------------------ + glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE); + } else glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); // Avoid window being resizable // Disable FLAG_WINDOW_MINIMIZED, not supported on initialization From 8ef6473d33f3b81e0c31bcc467c4ab6c594299e3 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sun, 25 May 2025 18:58:19 -0400 Subject: [PATCH 5/5] return to ray's expected resize behavior --- src/platforms/rcore_web.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 117a2348e..2e3ba9a17 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -1692,8 +1692,8 @@ static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent * // This event is called whenever the window changes sizes, // so the size of the canvas object is explicitly retrieved below - int width = EM_ASM_INT( return (!!document.fullscreenElement) ? window.innerWidth : Module.canvas.parentElement.clientWidth; ); - int height = EM_ASM_INT( return (!!document.fullscreenElement) ? window.innerHeight : Module.canvas.parentElement.clientHeight; ); + int width = EM_ASM_INT( return window.innerWidth; ); + int height = EM_ASM_INT( return window.innerHeight; ); if (width < (int)CORE.Window.screenMin.width) width = CORE.Window.screenMin.width; else if ((width > (int)CORE.Window.screenMax.width) && (CORE.Window.screenMax.width > 0)) width = CORE.Window.screenMax.width;