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.
This commit is contained in:
Ferdinand Prantl 2021-06-03 22:14:50 +02:00 committed by Francesco Abbate
parent d941535600
commit 2365dfa9c0
1 changed files with 9 additions and 2 deletions

View File

@ -152,6 +152,14 @@ top:
return 4; return 4;
case SDL_KEYDOWN: 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, "keypressed");
lua_pushstring(L, key_name(buf, e.key.keysym.sym)); lua_pushstring(L, key_name(buf, e.key.keysym.sym));
return 2; return 2;
@ -162,8 +170,7 @@ top:
** we want to flush this event and let the keymapper ** we want to flush this event and let the keymapper
** handle this key combination. ** handle this key combination.
** Thanks to mathewmariani, taken from his lite-macos github repository. */ ** 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); SDL_FlushEvent(SDL_QUIT);
} }
#endif #endif