Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] created SetWindowShouldClose #4290

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/platforms/rcore_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ bool WindowShouldClose(void)
else return true;
}

void SetWindowShouldClose(bool shouldClose)
{
CORE.Window.shouldClose = shouldClose;
}

// Toggle fullscreen mode
void ToggleFullscreen(void)
{
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/rcore_desktop_rgfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions src/platforms/rcore_desktop_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ bool WindowShouldClose(void)
else return true;
}

void SetWindowShouldClose(bool shouldClose)
{
CORE.Window.shouldClose = shouldClose;
}

// Toggle fullscreen mode
void ToggleFullscreen(void)
{
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;

Expand Down
11 changes: 8 additions & 3 deletions src/platforms/rcore_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -253,6 +253,11 @@ bool WindowShouldClose(void)
else return true;
}

void SetWindowShouldClose(bool shouldClose)
{
CORE.Window.shouldClose = shouldClose;
}

// Toggle fullscreen mode
void ToggleFullscreen(void)
{
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/platforms/rcore_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 5 additions & 0 deletions src/platforms/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
Loading