From 36cfa0205e5a618c59e2e24c1c6650597a59ddca Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 4 Jan 2014 13:50:39 +0100 Subject: [PATCH] rnd-20140104-2-src * fixed remaining text input problems for non-ASCII keys with modifier --- ChangeLog | 4 ++++ src/conftime.h | 2 +- src/events.c | 31 ++++++++++++++++++++++++++----- src/libgame/misc.c | 14 +++++++++++++- src/libgame/sdl.h | 11 ++++++++++- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e650a73..203831c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ +2014-01-04 + * fixed remaining text input problems for non-ASCII keys with modifier + 2014-01-03 * fixed key code problems with certain keys for SDL2 + (keypad keys not being in numerical order; number of function keys) * fixed text input problems for text characters using modifier keys 2014-01-02 diff --git a/src/conftime.h b/src/conftime.h index 09eada1e..59500ab8 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-01-04 02:29" +#define COMPILE_DATE_STRING "2014-01-04 13:44" diff --git a/src/events.c b/src/events.c index 50a39762..6fc55ea5 100644 --- a/src/events.c +++ b/src/events.c @@ -477,19 +477,35 @@ void HandleFingerEvent(FingerEvent *event) #endif } +static boolean checkTextInputKeyModState() +{ + // when playing, only handle raw key events and ignore text input + if (game_status == GAME_MODE_PLAYING) + return FALSE; + + return ((GetKeyModState() & KMOD_TextInput) != KMOD_None); +} + void HandleTextEvent(TextEvent *event) { char *text = event->text; Key key = getKeyFromKeyName(text); #if DEBUG_EVENTS - Error(ERR_DEBUG, "TEXT EVENT: text == '%s', resulting key == %d (%s)", + Error(ERR_DEBUG, "TEXT EVENT: text == '%s' [%d byte(s), '%c'/%d], resulting key == %d (%s)", text, + strlen(text), + text[0], (int)(text[0]), key, getKeyNameFromKey(key)); #endif - if (game_status != GAME_MODE_PLAYING && GetKeyModState() != KMOD_None) + // if (game_status != GAME_MODE_PLAYING && GetKeyModState() != KMOD_None) + /* + if (game_status != GAME_MODE_PLAYING && + (GetKeyModState() & KMOD_TextInput) != KMOD_None) + */ + if (checkTextInputKeyModState()) { HandleKey(key, KEY_PRESSED); HandleKey(key, KEY_RELEASED); @@ -528,13 +544,18 @@ void HandleKeyEvent(KeyEvent *event) key = KSYM_Escape; #endif -#if defined(TARGET_SDL2) HandleKeyModState(keymod, key_status); - if (game_status == GAME_MODE_PLAYING || GetKeyModState() == KMOD_None) +#if defined(TARGET_SDL2) + + // if (game_status == GAME_MODE_PLAYING || GetKeyModState() == KMOD_None) + /* + if (game_status == GAME_MODE_PLAYING || + (GetKeyModState() & KMOD_TextInput) == KMOD_None) + */ + if (!checkTextInputKeyModState()) HandleKey(key, key_status); #else - HandleKeyModState(keymod, key_status); HandleKey(key, key_status); #endif } diff --git a/src/libgame/misc.c b/src/libgame/misc.c index d0746a46..36bf1ce9 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1644,7 +1644,7 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) { KSYM_braceright, "XK_braceright", "brace right" }, { KSYM_asciitilde, "XK_asciitilde", "~" }, - /* special (non-ASCII) keys */ + /* special (non-ASCII) keys (ISO-Latin-1) */ { KSYM_degree, "XK_degree", "°" }, { KSYM_Adiaeresis, "XK_Adiaeresis", "Ä" }, { KSYM_Odiaeresis, "XK_Odiaeresis", "Ö" }, @@ -1654,6 +1654,18 @@ void translate_keyname(Key *keysym, char **x11name, char **name, int mode) { KSYM_udiaeresis, "XK_udiaeresis", "ü" }, { KSYM_ssharp, "XK_ssharp", "sharp s" }, +#if defined(TARGET_SDL2) + /* special (non-ASCII) keys (UTF-8, for reverse mapping only) */ + { KSYM_degree, "XK_degree", "\xc2\xb0" }, + { KSYM_Adiaeresis, "XK_Adiaeresis", "\xc3\x84" }, + { KSYM_Odiaeresis, "XK_Odiaeresis", "\xc3\x96" }, + { KSYM_Udiaeresis, "XK_Udiaeresis", "\xc3\x9c" }, + { KSYM_adiaeresis, "XK_adiaeresis", "\xc3\xa4" }, + { KSYM_odiaeresis, "XK_odiaeresis", "\xc3\xb6" }, + { KSYM_udiaeresis, "XK_udiaeresis", "\xc3\xbc" }, + { KSYM_ssharp, "XK_ssharp", "\xc3\x9f" }, +#endif + #if defined(TARGET_SDL2) /* keypad keys are not in numerical order in SDL2 */ { KSYM_KP_0, "XK_KP_0", "keypad 0" }, diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 254b9927..16c62c0f 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -201,7 +201,13 @@ struct MouseCursorInfo #define KSYM_quotedbl SDLK_QUOTEDBL #define KSYM_numbersign SDLK_HASH #define KSYM_dollar SDLK_DOLLAR -#define KSYM_percent KSYM_UNDEFINED /* undefined */ + +#if defined(TARGET_SDL2) +#define KSYM_percent SDLK_PERCENT +#else +#define KSYM_percent 37 /* undefined in SDL */ +#endif + #define KSYM_ampersand SDLK_AMPERSAND #define KSYM_apostrophe SDLK_QUOTE #define KSYM_parenleft SDLK_LEFTPAREN @@ -411,6 +417,9 @@ struct MouseCursorInfo #define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R) #define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R) +#if defined(TARGET_SDL2) +#define KMOD_TextInput (KMOD_Shift | KMOD_Alt_R) +#endif /* SDL function definitions */ -- 2.34.1