commit afe0c972341d0e3a722b721b2a7628d216998253
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sat Dec 17 21:21:23 2016 -0500
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Sat Dec 17 21:21:23 2016 -0500
textscreen: Stop tracking modifier state.
SDL2 has an API to read the current modifier state, so we can just
use this and eliminate the code for tracking state based on key
presses.
---
textscreen/txt_sdl.c | 63 +++++++++++-----------------------------------------
1 file changed, 13 insertions(+), 50 deletions(-)
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 20830254..752e56ec 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -64,8 +64,6 @@ static int screen_image_w, screen_image_h;
static TxtSDLEventCallbackFunc event_callback;
static void *event_callback_data;
-static int modifier_state[TXT_NUM_MODIFIERS];
-
// Font we are using:
static const txt_font_t *font;
@@ -616,44 +614,6 @@ static int MouseHasMoved(void)
}
}
-// Examine a key press/release and update the modifier key state
-// if necessary.
-
-static void UpdateModifierState(SDL_Keysym *sym, int pressed)
-{
- txt_modifier_t mod;
-
- switch (sym->sym)
- {
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- mod = TXT_MOD_SHIFT;
- break;
-
- case SDLK_LCTRL:
- case SDLK_RCTRL:
- mod = TXT_MOD_CTRL;
- break;
-
- case SDLK_LALT:
- case SDLK_RALT:
- mod = TXT_MOD_ALT;
- break;
-
- default:
- return;
- }
-
- if (pressed)
- {
- ++modifier_state[mod];
- }
- else
- {
- --modifier_state[mod];
- }
-}
-
signed int TXT_GetChar(void)
{
SDL_Event ev;
@@ -686,8 +646,6 @@ signed int TXT_GetChar(void)
return SDLWheelToTXTButton(&ev.wheel);
case SDL_KEYDOWN:
- UpdateModifierState(&ev.key.keysym, 1);
-
switch (input_mode)
{
case TXT_INPUT_RAW:
@@ -707,10 +665,6 @@ signed int TXT_GetChar(void)
}
break;
- case SDL_KEYUP:
- UpdateModifierState(&ev.key.keysym, 0);
- break;
-
case SDL_TEXTINPUT:
if (input_mode == TXT_INPUT_TEXT)
{
@@ -739,12 +693,21 @@ signed int TXT_GetChar(void)
int TXT_GetModifierState(txt_modifier_t mod)
{
- if (mod < TXT_NUM_MODIFIERS)
+ SDL_Keymod state;
+
+ state = SDL_GetModState();
+
+ switch (mod)
{
- return modifier_state[mod] > 0;
+ case TXT_MOD_SHIFT:
+ return (state & KMOD_SHIFT) != 0;
+ case TXT_MOD_CTRL:
+ return (state & KMOD_CTRL) != 0;
+ case TXT_MOD_ALT:
+ return (state & KMOD_ALT) != 0;
+ default:
+ return 0;
}
-
- return 0;
}
static const char *SpecialKeyName(int key)