shithub: cstory

Download patch

ref: fd0733f6e77a4d0ed07f3d198449e1d34dba12cb
parent: 8549fa561e0b1bccba910451808c22e52cefe5e4
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon Apr 13 11:32:34 EDT 2020

Fix GLFW3 not handling exit event while not focussed

--- a/src/Backends/GLFW3/Misc.cpp
+++ b/src/Backends/GLFW3/Misc.cpp
@@ -25,8 +25,6 @@
 		keyboard_state[BACKEND_KEY] = action == GLFW_PRESS; \
 		break;
 
-BOOL bActive = TRUE;
-
 static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
 
 static GLFWcursor* cursor;
@@ -272,7 +270,7 @@
 	glfwSetDropCallback(window, DragAndDropCallback);
 }
 
-BOOL Backend_SystemTask(void)
+BOOL Backend_SystemTask(BOOL active)
 {
 	if (glfwWindowShouldClose(window))
 	{
@@ -280,9 +278,9 @@
 		return FALSE;
 	}
 
-	glfwPollEvents();
-
-	while (!bActive)
+	if (active)
+		glfwPollEvents();
+	else
 		glfwWaitEvents();
 
 	return TRUE;
--- a/src/Backends/Misc.h
+++ b/src/Backends/Misc.h
@@ -84,8 +84,6 @@
 	BACKEND_KEYBOARD_TOTAL
 };
 
-extern BOOL bActive;
-
 BOOL Backend_Init(void);
 void Backend_Deinit(void);
 void Backend_PostWindowCreation(void);
@@ -94,7 +92,7 @@
 void Backend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
 void Backend_SetCursor(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
 void PlaybackBackend_EnableDragAndDrop(void);
-BOOL Backend_SystemTask(void);
+BOOL Backend_SystemTask(BOOL active);
 void Backend_GetKeyboardState(BOOL *keyboard_state);
 void Backend_ShowMessageBox(const char *title, const char *message);
 ATTRIBUTE_FORMAT_PRINTF(1, 2) void Backend_PrintError(const char *format, ...);
--- a/src/Backends/SDL2/Misc.cpp
+++ b/src/Backends/SDL2/Misc.cpp
@@ -23,8 +23,6 @@
 		keyboard_state[BACKEND_KEY] = event.key.type == SDL_KEYDOWN; \
 		break;
 
-BOOL bActive = TRUE;
-
 static BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
 
 static unsigned char *cursor_surface_pixels;
@@ -157,9 +155,9 @@
 	SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
 }
 
-BOOL Backend_SystemTask(void)
+BOOL Backend_SystemTask(BOOL active)
 {
-	while (SDL_PollEvent(NULL) || !bActive)
+	if (SDL_PollEvent(NULL) || !active)
 	{
 		SDL_Event event;
 
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -33,6 +33,7 @@
 
 int gJoystickButtonTable[8];
 
+static BOOL bActive = TRUE;
 static BOOL bFps = FALSE;
 
 static int windowWidth;
@@ -388,8 +389,11 @@
 {
 	static BOOL previous_keyboard_state[BACKEND_KEYBOARD_TOTAL];
 
-	if (!Backend_SystemTask())
-		return FALSE;
+	do
+	{
+		if (!Backend_SystemTask(bActive))
+			return FALSE;
+	} while(!bActive);
 
 	BOOL keyboard_state[BACKEND_KEYBOARD_TOTAL];
 	Backend_GetKeyboardState(keyboard_state);