diff --git a/src/rcore.c b/src/rcore.c index 39fc144bb..8cac4c765 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -419,41 +419,6 @@ const char *TextFormat(const char *text, ...); // Formatting of text with // Module Functions Definition - Window and OpenGL Context Functions //---------------------------------------------------------------------------------- -// Check if KEY_ESCAPE pressed or Close icon pressed -bool WindowShouldClose(void) -{ -#if defined(PLATFORM_WEB) - // Emterpreter-Async required to run sync code - // https://github.com/emscripten-core/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code - // By default, this function is never called on a web-ready raylib example because we encapsulate - // frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously - // but now emscripten allows sync code to be executed in an interpreted way, using emterpreter! - emscripten_sleep(16); - return false; -#endif - -#if defined(PLATFORM_DESKTOP) - if (CORE.Window.ready) - { - // While window minimized, stop loop execution - while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents(); - - CORE.Window.shouldClose = glfwWindowShouldClose(CORE.Window.handle); - - // Reset close status for next frame - glfwSetWindowShouldClose(CORE.Window.handle, GLFW_FALSE); - - return CORE.Window.shouldClose; - } - else return true; -#endif - -#if defined(PLATFORM_ANDROID) || defined(PLATFORM_DRM) - if (CORE.Window.ready) return CORE.Window.shouldClose; - else return true; -#endif -} - // Check if window has been initialized successfully bool IsWindowReady(void) { diff --git a/src/rcore_android.c b/src/rcore_android.c index 5694a9653..aa4e68c4a 100644 --- a/src/rcore_android.c +++ b/src/rcore_android.c @@ -1284,4 +1284,12 @@ void CloseWindow(void) CORE.Window.ready = false; TRACELOG(LOG_INFO, "Window closed successfully"); +} + + +// Check if KEY_ESCAPE pressed or Close icon pressed +bool WindowShouldClose(void) +{ + if (CORE.Window.ready) return CORE.Window.shouldClose; + else return true; } \ No newline at end of file diff --git a/src/rcore_desktop.c b/src/rcore_desktop.c index 8d29e14e1..a881f20d8 100644 --- a/src/rcore_desktop.c +++ b/src/rcore_desktop.c @@ -500,4 +500,24 @@ void CloseWindow(void) CORE.Window.ready = false; TRACELOG(LOG_INFO, "Window closed successfully"); +} + + + +// Check if KEY_ESCAPE pressed or Close icon pressed +bool WindowShouldClose(void) +{ + if (CORE.Window.ready) + { + // While window minimized, stop loop execution + while (IsWindowState(FLAG_WINDOW_MINIMIZED) && !IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) glfwWaitEvents(); + + CORE.Window.shouldClose = glfwWindowShouldClose(CORE.Window.handle); + + // Reset close status for next frame + glfwSetWindowShouldClose(CORE.Window.handle, GLFW_FALSE); + + return CORE.Window.shouldClose; + } + else return true; } \ No newline at end of file diff --git a/src/rcore_drm.c b/src/rcore_drm.c index b90cf7005..73d7f83ee 100644 --- a/src/rcore_drm.c +++ b/src/rcore_drm.c @@ -1001,4 +1001,13 @@ void CloseWindow(void) CORE.Window.ready = false; TRACELOG(LOG_INFO, "Window closed successfully"); +} + + + +// Check if KEY_ESCAPE pressed or Close icon pressed +bool WindowShouldClose(void) +{ + if (CORE.Window.ready) return CORE.Window.shouldClose; + else return true; } \ No newline at end of file diff --git a/src/rcore_web.c b/src/rcore_web.c index 10c94412e..7687275ea 100644 --- a/src/rcore_web.c +++ b/src/rcore_web.c @@ -1073,4 +1073,18 @@ void CloseWindow(void) CORE.Window.ready = false; TRACELOG(LOG_INFO, "Window closed successfully"); +} + + + +// Check if KEY_ESCAPE pressed or Close icon pressed +bool WindowShouldClose(void) +{ + // Emterpreter-Async required to run sync code + // https://github.com/emscripten-core/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code + // By default, this function is never called on a web-ready raylib example because we encapsulate + // frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously + // but now emscripten allows sync code to be executed in an interpreted way, using emterpreter! + emscripten_sleep(16); + return false; } \ No newline at end of file