summaryrefslogtreecommitdiff
path: root/src/gui-sdl/sdlgui.c
diff options
context:
space:
mode:
authorThomas Huth <huth@tuxfamily.org>2024-07-06 18:34:51 (GMT)
committerThomas Huth <huth@tuxfamily.org>2024-07-06 18:34:51 (GMT)
commitbd8a07aef850a0ff2abfd588fef5a1e07f464100 (patch)
tree8783cae0663ae99221993d3043303ef7f45f48e1 /src/gui-sdl/sdlgui.c
parent2680af99af9cb511e6fd177d2c50c6194814db39 (diff)
downloadhatari-bd8a07aef850a0ff2abfd588fef5a1e07f464100.zip
hatari-bd8a07aef850a0ff2abfd588fef5a1e07f464100.tar.gz
Ignore first key-up event in sdl gui in case the key had been pressed before
Otherwise we could exit the dialog immediately though the key was not meant for controlling the dialog, but rather for the emulation side.
Diffstat (limited to 'src/gui-sdl/sdlgui.c')
-rw-r--r--src/gui-sdl/sdlgui.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gui-sdl/sdlgui.c b/src/gui-sdl/sdlgui.c
index ceb554c..85b5449 100644
--- a/src/gui-sdl/sdlgui.c
+++ b/src/gui-sdl/sdlgui.c
@@ -1123,6 +1123,8 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
SDL_Surface *pBgSurface;
SDL_Rect dlgrect, bgrect;
SDL_Joystick *joy = NULL;
+ const Uint8 *keystates;
+ bool ignore_first_keyup;
/* either both, or neither of these should be present */
assert((isEventOut && pEventOut) || (!isEventOut && !pEventOut));
@@ -1177,6 +1179,16 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
/* (Re-)draw the dialog */
SDLGui_DrawDialog(dlg);
+ /* If one of the keys that could exit the dialog is already held
+ * before we start, then ignore the first keyup event since the
+ * key press does not belong to the dialog, but rather to whatever
+ * happened before the dialog */
+ keystates = SDL_GetKeyboardState(NULL);
+ ignore_first_keyup = keystates[SDL_SCANCODE_RETURN]
+ || keystates[SDL_SCANCODE_KP_ENTER]
+ || keystates[SDL_SCANCODE_SPACE]
+ || keystates[SDL_SCANCODE_ESCAPE];
+
/* Is the left mouse button still pressed? Yes -> Handle TOUCHEXIT objects here */
SDL_PumpEvents();
b = SDL_GetMouseState(&x, &y);
@@ -1401,9 +1413,19 @@ int SDLGui_DoDialogExt(SGOBJ *dlg, bool (*isEventOut)(SDL_EventType), SDL_Event
case SDLK_SPACE:
case SDLK_RETURN:
case SDLK_KP_ENTER:
+ if (ignore_first_keyup)
+ {
+ ignore_first_keyup = false;
+ break;
+ }
retbutton = SDLGui_HandleSelection(dlg, focused, focused);
break;
case SDLK_ESCAPE:
+ if (ignore_first_keyup)
+ {
+ ignore_first_keyup = false;
+ break;
+ }
retbutton = SDLGui_SearchFlags(dlg, SG_CANCEL);
break;
default: