aboutsummaryrefslogtreecommitdiff
path: root/ht/gen-keysyms.sh
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-09-12 13:38:33 +0200
committerPřemysl Janouch <p@janouch.name>2018-10-07 18:09:09 +0200
commitcd6c9e4d8c6a49eb91091c00b55e0f879c9220bf (patch)
tree17dbca0adbac6ce78ae65be17be70c59f9b60755 /ht/gen-keysyms.sh
parentbf14fd5e04ab96e755cec4fd46349339e1eb3e2b (diff)
downloadhaven-cd6c9e4d8c6a49eb91091c00b55e0f879c9220bf.tar.gz
haven-cd6c9e4d8c6a49eb91091c00b55e0f879c9220bf.tar.xz
haven-cd6c9e4d8c6a49eb91091c00b55e0f879c9220bf.zip
ht: add generated X11 keysym maps
Now we can make sense of keysyms and translate them to text.
Diffstat (limited to 'ht/gen-keysyms.sh')
-rwxr-xr-xht/gen-keysyms.sh49
1 files changed, 49 insertions, 0 deletions
diff --git a/ht/gen-keysyms.sh b/ht/gen-keysyms.sh
new file mode 100755
index 0000000..064dec4
--- /dev/null
+++ b/ht/gen-keysyms.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+gofmt <<EOF | sed 's, *//$,,'
+// Code generated by running "go generate" in janouch.name/haven. DO NOT EDIT.
+
+package $GOPACKAGE
+
+import "janouch.name/haven/nexgb/xproto"
+
+$(curl --silent --show-error \
+ https://cgit.freedesktop.org/xorg/proto/x11proto/plain/keysymdef.h \
+ https://cgit.freedesktop.org/xorg/proto/x11proto/plain/XF86keysym.h \
+| perl -lne '
+ next unless /^\#define\s+
+ (XF86)?(XK_)([a-zA-Z_0-9]+)\s+
+ 0x([0-9a-fA-F]+)\s*
+ (?:\/\*\s*(.*?)\s*\*\/)?\s*
+ $/x;
+
+ my ($name, $ident, $hex, $comment) =
+ (($1 // "") . $3, ($1 // "") . $2 . $3, lc $4, ($5 // ""));
+
+ # They are already somewhat sorted in the source file.
+ push @a, { hex => $hex, ident => $ident, comment => $comment };
+
+ $nametokeysym{$name} = $ident;
+
+ # All but the first name listed should be considered deprecated.
+ $keysymtoname{$ident} = $name unless exists $seen{$hex};
+ $seen{$hex}++;
+
+ END {
+ print "const (";
+ print "$_->{ident} = 0x$_->{hex} // $_->{comment}" for @a;
+ print ")";
+
+ # Very large tables, should be an on-demand package :(
+
+ print "// KeysymToName maps X11 keysym constants to their names";
+ print "var KeysymToName = map[xproto.Keysym]string{";
+ print "$_: \"$keysymtoname{$_}\"," for sort keys %keysymtoname;
+ print "}";
+
+ print "// NameToKeysym maps X11 keysym names to their constants";
+ print "var NameToKeysym = map[string]xproto.Keysym{";
+ print "\"$_\": $nametokeysym{$_}," for sort keys %nametokeysym;
+ print "}";
+ }
+')
+EOF