From cf5854f919dab4b548cac7a3038c8cd746fbf1da Mon Sep 17 00:00:00 2001 From: asdqwe Date: Sun, 20 Oct 2024 19:45:45 -0300 Subject: [PATCH] Updates SetWindowState() and ClearWindowState() to handle FLAG_WINDOW_MAXIMIZED for PLATFORM_WEB --- src/platforms/rcore_web.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 73513d8e4..4d45c3e03 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -412,9 +412,20 @@ void SetWindowState(unsigned int flags) } // State change: FLAG_WINDOW_MAXIMIZED - if ((flags & FLAG_WINDOW_MAXIMIZED) > 0) + if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) != (flags & FLAG_WINDOW_MAXIMIZED)) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0)) { - TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform"); + if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) + { + platform.unmaximizedWidth = CORE.Window.screen.width; + platform.unmaximizedHeight = CORE.Window.screen.height; + + const int tabWidth = EM_ASM_INT( { return window.innerWidth; }, 0); + const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0); + + if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight); + + CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED; + } } // State change: FLAG_WINDOW_UNFOCUSED @@ -530,9 +541,14 @@ void ClearWindowState(unsigned int flags) } // State change: FLAG_WINDOW_MAXIMIZED - if ((flags & FLAG_WINDOW_MAXIMIZED) > 0) + if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0)) { - TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform"); + if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) + { + if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight); + + CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED; + } } // State change: FLAG_WINDOW_UNDECORATED