Skip to content

Commit 4290a0d

Browse files
authored
[rcore] [web] Updates SetWindowState() and ClearWindowState() to handle FLAG_WINDOW_MAXIMIZED for PLATFORM_WEB (#4402)
* Updates SetWindowState() and ClearWindowState() to handle FLAG_WINDOW_MAXIMIZED for PLATFORM_WEB * Update MaximizeWindow() and RestoreWindow() to set/unset the FLAG_WINDOW_MAXIMIZED
1 parent 6802386 commit 4290a0d

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/platforms/rcore_web.c

+24-4
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ void MaximizeWindow(void)
328328
const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0);
329329

330330
if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);
331+
332+
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED;
331333
}
332334
}
333335

@@ -343,6 +345,8 @@ void RestoreWindow(void)
343345
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
344346
{
345347
if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);
348+
349+
CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED;
346350
}
347351
}
348352

@@ -412,9 +416,20 @@ void SetWindowState(unsigned int flags)
412416
}
413417

414418
// State change: FLAG_WINDOW_MAXIMIZED
415-
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
419+
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) != (flags & FLAG_WINDOW_MAXIMIZED)) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
416420
{
417-
TRACELOG(LOG_WARNING, "SetWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
421+
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
422+
{
423+
platform.unmaximizedWidth = CORE.Window.screen.width;
424+
platform.unmaximizedHeight = CORE.Window.screen.height;
425+
426+
const int tabWidth = EM_ASM_INT( { return window.innerWidth; }, 0);
427+
const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0);
428+
429+
if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight);
430+
431+
CORE.Window.flags |= FLAG_WINDOW_MAXIMIZED;
432+
}
418433
}
419434

420435
// State change: FLAG_WINDOW_UNFOCUSED
@@ -530,9 +545,14 @@ void ClearWindowState(unsigned int flags)
530545
}
531546

532547
// State change: FLAG_WINDOW_MAXIMIZED
533-
if ((flags & FLAG_WINDOW_MAXIMIZED) > 0)
548+
if (((CORE.Window.flags & FLAG_WINDOW_MAXIMIZED) > 0) && ((flags & FLAG_WINDOW_MAXIMIZED) > 0))
534549
{
535-
TRACELOG(LOG_WARNING, "ClearWindowState(FLAG_WINDOW_MAXIMIZED) not available on target platform");
550+
if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE)
551+
{
552+
if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight);
553+
554+
CORE.Window.flags &= ~FLAG_WINDOW_MAXIMIZED;
555+
}
536556
}
537557

538558
// State change: FLAG_WINDOW_UNDECORATED

0 commit comments

Comments
 (0)