From 2365dfa9c081189db2d247e2c71213ff3f235f97 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Thu, 3 Jun 2021 22:14:50 +0200 Subject: [PATCH] Flush the SDL_QUIT event when Cmd+W is detected in SDL_KEYDOWN as well (#248) On macos 11.2.3 with sdl 2.0.14 the keyup handler for cmd+w was not enough. Maybe the quit event started to be triggered from the keydown handler? In any case, flushing the quit event there too helped. --- src/api/system.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/system.c b/src/api/system.c index 89c037c2..bbe0801b 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -152,6 +152,14 @@ top: return 4; case SDL_KEYDOWN: +#ifdef __APPLE__ + /* on macos 11.2.3 with sdl 2.0.14 the keyup handler for cmd+w below + ** was not enough. Maybe the quit event started to be triggered from the + ** keydown handler? In any case, flushing the quit event here too helped. */ + if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) { + SDL_FlushEvent(SDL_QUIT); + } +#endif lua_pushstring(L, "keypressed"); lua_pushstring(L, key_name(buf, e.key.keysym.sym)); return 2; @@ -162,8 +170,7 @@ top: ** we want to flush this event and let the keymapper ** handle this key combination. ** Thanks to mathewmariani, taken from his lite-macos github repository. */ - if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) - { + if ((e.key.keysym.sym == SDLK_w) && (e.key.keysym.mod & KMOD_GUI)) { SDL_FlushEvent(SDL_QUIT); } #endif