[PATCH xmodmap] Accept a single character as keysym, interpreted from the user locale.

Ángel González ingenit at zoho.com
Sun Sep 15 10:16:32 PDT 2013


This allows providing directly the desired character in the xmodmap file,
instead of looking up the equivalence (when available) or introducing
in hexadecimal the codepoint. Thus allowing more readable and nicer
xmodmap files.

Signed-off-by: Ángel González <ingenit at zoho.com>
---

The alternative way to perform this would be to modify XStringToKeysym()
in libX11, but it seemed more risky than just touching xmodmap.

 handle.c  | 8 ++++++++
 xmodmap.c | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/handle.c b/handle.c
index 3f05a46..0e69152 100644
--- a/handle.c
+++ b/handle.c
@@ -307,6 +307,14 @@ parse_keysym(const char *line, int n, char **name, KeySym *keysym)
     *keysym = XStringToKeysym (*name);
     if (*keysym == NoSymbol && '0' <= **name && **name <= '9')
 	return parse_number(*name, keysym);
+
+    if (*keysym == NoSymbol && (mbstowcs (NULL, *name, 0) == 1)) {
+	    wchar_t character;
+	    char codepoint[8];
+	    mbstowcs (&character, *name, 1);
+	    snprintf (codepoint, sizeof(codepoint), "U%X", (unsigned)character);
+	    *keysym = XStringToKeysym (codepoint);
+    }
     return (*keysym != NoSymbol);
 }
 
diff --git a/xmodmap.c b/xmodmap.c
index 2a10976..3eff703 100644
--- a/xmodmap.c
+++ b/xmodmap.c
@@ -36,6 +36,7 @@ from The Open Group.
 #include <stdlib.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <locale.h>
 #include "xmodmap.h"
 
 const char *ProgramName;
@@ -175,6 +176,7 @@ main(int argc, char *argv[])
     Bool didAnything = False;
 
     ProgramName = argv[0];
+    setlocale (LC_CTYPE, "");
 
     /*
      * scan the arg list once to find out which display to use
-- 
1.8.4




More information about the xorg-devel mailing list