[PATCH 10/13] Fix/improve keymap file SDL key name parsing

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Interpret key names in keymap file as symbolic ones, otherwise it's
too confusing for users and would break backwards compatibility.

Accept any kind of symbolic SDL key names.  Besides adding some [1]
support for special characters, this is needed also for non-ASCII
alphabetic characters. Hatari could be run in a locale where those are
not recognized as alphabetic characters, or it could be built with a
C-library missing proper locale support.

[1] Following still need to be specified using SDL scancodes:

* Numbers and other characters ("#;, ") used in keymap syntax

* Keys for which SDL does not have scancode with *host* keyboard
  mapping, such as dead keys and virtual ones:
  https://wiki.libsdl.org/SDL_Keycode

TODO: update also documentation and keymap sample file!
---
 src/keymap.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index 0e29a34f..e934be63 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -592,8 +592,8 @@ static bool HostSpecToKeymap(const char *spec, KeyMapping* mapping)
 	     token = strtok_r(NULL, "|", &saveptr))
 	{
 		token = Str_Trim(token);
-		/* text description? */
-		if (isalpha(token[0]))
+		/* not a number? */
+		if (!isdigit(token[0]))
 		{
 			SDL_Scancode code;
 			SDL_Keymod mod;
@@ -610,8 +610,8 @@ static bool HostSpecToKeymap(const char *spec, KeyMapping* mapping)
 				mods = mod;
 				continue;
 			}
-			/* is it non-modifier key? */
-			code = SDL_GetScancodeFromName(token);
+			/* is it non-modifier, symbolic key name? */
+			code = SDL_GetScancodeFromKey(SDL_GetKeyFromName(token));
 			if (code)
 			{
 				if (scancode)
@@ -700,7 +700,8 @@ static bool GuestSpecToKeymap(const char *spec, KeyMapping* mapping)
 	     token = strtok_r(NULL, "|", &saveptr))
 	{
 		token = Str_Trim(token);
-		if (isalpha(token[0]))
+		/* not a number? */
+		if (!isdigit(token[0]))
 		{
 			mods = AddSTModifier(mods, token);
 			if (!mods)
-- 
2.30.2


--------------6125158E9D8E923B9ED57408
Content-Type: text/x-patch; charset=UTF-8;
 name="0009-Keymap-accept-also-0x-prefixed-hex-values-for-scanco.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0009-Keymap-accept-also-0x-prefixed-hex-values-for-scanco.pa";
 filename*1="tch"



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/