diff --git a/src/platforms/rcore_android.c b/src/platforms/rcore_android.c index 55706c591..dd7291246 100644 --- a/src/platforms/rcore_android.c +++ b/src/platforms/rcore_android.c @@ -313,6 +313,11 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; +} + // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/platforms/rcore_desktop_glfw.c b/src/platforms/rcore_desktop_glfw.c index c6685846c..ac5e8c3a5 100644 --- a/src/platforms/rcore_desktop_glfw.c +++ b/src/platforms/rcore_desktop_glfw.c @@ -142,6 +142,12 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; + glfwSetWindowShouldClose(platform.handle, shouldClose); +} + // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/platforms/rcore_desktop_rgfw.c b/src/platforms/rcore_desktop_rgfw.c index 64ab432e6..a171707af 100644 --- a/src/platforms/rcore_desktop_rgfw.c +++ b/src/platforms/rcore_desktop_rgfw.c @@ -239,6 +239,12 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; + RGFW_window_setShouldClose(platform.window); +} + // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 794f9e6a0..cd84c01f4 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -244,6 +244,11 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; +} + // Toggle fullscreen mode void ToggleFullscreen(void) { @@ -1063,7 +1068,7 @@ void PollInputEvents(void) // All input events can be processed after polling switch (event.type) { - case SDL_QUIT: CORE.Window.shouldClose = true; break; + case SDL_QUIT: SetWindowShouldClose(true); break; case SDL_DROPFILE: // Dropped file { @@ -1150,7 +1155,7 @@ void PollInputEvents(void) // TODO: Put exitKey verification outside the switch? if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey]) { - CORE.Window.shouldClose = true; + SetWindowShouldClose(true); } } break; diff --git a/src/platforms/rcore_drm.c b/src/platforms/rcore_drm.c index 291fd93c7..d23e666fa 100644 --- a/src/platforms/rcore_drm.c +++ b/src/platforms/rcore_drm.c @@ -206,7 +206,7 @@ static const short linuxToRaylibMap[KEYMAP_SIZE] = { [BTN_TL] = GAMEPAD_BUTTON_LEFT_TRIGGER_1, [BTN_TL2] = GAMEPAD_BUTTON_LEFT_TRIGGER_2, [BTN_TR] = GAMEPAD_BUTTON_RIGHT_TRIGGER_1, - [BTN_TR2] GAMEPAD_BUTTON_RIGHT_TRIGGER_2, + [BTN_TR2] = GAMEPAD_BUTTON_RIGHT_TRIGGER_2, [BTN_SELECT] = GAMEPAD_BUTTON_MIDDLE_LEFT, [BTN_MODE] = GAMEPAD_BUTTON_MIDDLE, [BTN_START] = GAMEPAD_BUTTON_MIDDLE_RIGHT, @@ -253,6 +253,11 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; +} + // Toggle fullscreen mode void ToggleFullscreen(void) { @@ -668,7 +673,7 @@ void PollInputEvents(void) #endif // Check exit key - if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) CORE.Window.shouldClose = true; + if (CORE.Input.Keyboard.currentKeyState[CORE.Input.Keyboard.exitKey] == 1) SetWindowShouldClose(true); // Register previous mouse position if (platform.cursorRelative) CORE.Input.Mouse.currentPosition = (Vector2){ 0.0f, 0.0f }; @@ -1139,7 +1144,7 @@ void ClosePlatform(void) platform.device = EGL_NO_DISPLAY; } - CORE.Window.shouldClose = true; // Added to force threads to exit when the close window is called + SetWindowShouldClose(true); // Added to force threads to exit when the close window is called // Close the evdev devices diff --git a/src/platforms/rcore_template.c b/src/platforms/rcore_template.c index 938f4ed7d..4d25565d1 100644 --- a/src/platforms/rcore_template.c +++ b/src/platforms/rcore_template.c @@ -90,6 +90,12 @@ bool WindowShouldClose(void) else return true; } +void SetWindowShouldClose(bool shouldClose) +{ + CORE.Window.shouldClose = shouldClose; + TRACELOG(LOG_WARNING, "SetWindowShouldClose() not available on target platform"); +} + // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index ff7a92dbc..4ce7d4b27 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -160,6 +160,11 @@ bool WindowShouldClose(void) return false; } +void SetWindowShouldClose(bool shouldClose) +{ + TRACELOG(LOG_WARNING, "SetWindowShouldClose() has no effect on Web"); +} + // Toggle fullscreen mode void ToggleFullscreen(void) { diff --git a/src/raylib.h b/src/raylib.h index 30ba8bd2a..fdf0197d1 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -958,6 +958,7 @@ extern "C" { // Prevents name mangling of functions RLAPI void InitWindow(int width, int height, const char *title); // Initialize window and OpenGL context RLAPI void CloseWindow(void); // Close window and unload OpenGL context RLAPI bool WindowShouldClose(void); // Check if application should close (KEY_ESCAPE pressed or windows close icon clicked) +RLAPI void SetWindowShouldClose(bool); // Set "Window Should Close" state RLAPI bool IsWindowReady(void); // Check if window has been initialized successfully RLAPI bool IsWindowFullscreen(void); // Check if window is currently fullscreen RLAPI bool IsWindowHidden(void); // Check if window is currently hidden (only PLATFORM_DESKTOP) diff --git a/src/rcore.c b/src/rcore.c index 972d58600..adfabd93f 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -678,7 +678,7 @@ void InitWindow(int width, int height, const char *title) #endif CORE.Time.frameCounter = 0; - CORE.Window.shouldClose = false; + SetWindowShouldClose(false); // Initialize random seed SetRandomSeed((unsigned int)time(NULL)); @@ -2736,7 +2736,7 @@ void PlayAutomationEvent(AutomationEvent event) case INPUT_GESTURE: GESTURES.current = event.params[0]; break; // param[0]: gesture (enum Gesture) -> rgestures.h: GESTURES.current #endif // Window event - case WINDOW_CLOSE: CORE.Window.shouldClose = true; break; + case WINDOW_CLOSE: SetWindowShouldClose(true); break; case WINDOW_MAXIMIZE: MaximizeWindow(); break; case WINDOW_MINIMIZE: MinimizeWindow(); break; case WINDOW_RESIZE: SetWindowSize(event.params[0], event.params[1]); break;