Fix GLFW3 not handling exit event while not focussed

This commit is contained in:
Clownacy 2020-04-13 15:32:34 +01:00
parent 8549fa561e
commit fd0733f6e7
4 changed files with 13 additions and 15 deletions

View file

@ -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 @@ void PlaybackBackend_EnableDragAndDrop(void)
glfwSetDropCallback(window, DragAndDropCallback);
}
BOOL Backend_SystemTask(void)
BOOL Backend_SystemTask(BOOL active)
{
if (glfwWindowShouldClose(window))
{
@ -280,9 +278,9 @@ BOOL Backend_SystemTask(void)
return FALSE;
}
glfwPollEvents();
while (!bActive)
if (active)
glfwPollEvents();
else
glfwWaitEvents();
return TRUE;

View file

@ -84,8 +84,6 @@ enum
BACKEND_KEYBOARD_TOTAL
};
extern BOOL bActive;
BOOL Backend_Init(void);
void Backend_Deinit(void);
void Backend_PostWindowCreation(void);
@ -94,7 +92,7 @@ void Backend_HideMouse(void);
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, ...);

View file

@ -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 @@ void PlaybackBackend_EnableDragAndDrop(void)
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;

View file

@ -33,6 +33,7 @@ BOOL gbUseJoystick = FALSE;
int gJoystickButtonTable[8];
static BOOL bActive = TRUE;
static BOOL bFps = FALSE;
static int windowWidth;
@ -388,8 +389,11 @@ BOOL SystemTask(void)
{
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);