ref: afe0c972341d0e3a722b721b2a7628d216998253
parent: c1ff9bfd5b0effd4377c0a9f669ca96093547d98
author: Simon Howard <[email protected]>
date: Sat Dec 17 16:21:23 EST 2016
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.
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -64,8 +64,6 @@
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 @@
}
}
-// 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 @@
return SDLWheelToTXTButton(&ev.wheel);
case SDL_KEYDOWN:
- UpdateModifierState(&ev.key.keysym, 1);
-
switch (input_mode)
{
case TXT_INPUT_RAW:
@@ -707,10 +665,6 @@
}
break;
- case SDL_KEYUP:
- UpdateModifierState(&ev.key.keysym, 0);
- break;
-
case SDL_TEXTINPUT:
if (input_mode == TXT_INPUT_TEXT)
{
@@ -739,12 +693,21 @@
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)