From 85152b9d71b51f7601e0cd3325f01d5f53cb77ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Tue, 7 Dec 2021 21:05:07 +0100 Subject: WIP: ht: commit whatever I was trying out --- ht/gen-keysyms-new.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100755 ht/gen-keysyms-new.sh (limited to 'ht/gen-keysyms-new.sh') diff --git a/ht/gen-keysyms-new.sh b/ht/gen-keysyms-new.sh new file mode 100755 index 0000000..388d946 --- /dev/null +++ b/ht/gen-keysyms-new.sh @@ -0,0 +1,94 @@ +#!/bin/sh +gofmt < $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}++; + + # TODO: Try stringer, see + # https://eli.thegreenplace.net/2021/a-comprehensive-guide-to-go-generate/ + END { + print "const ("; + print "$_->{ident} = 0x$_->{hex} // $_->{comment}" for @a; + print ")"; + + # Very large tables, should be an on-demand package :( + # + # KeysymToName/NameToKeysym can also be compress/lzw (small code), + # that may reduce string data to about 1/3. It's still rather small + # (27K -> 8K), I'm not sure where all those bytes come from. + # + # KeysymToName might be generated from NameToKeysym. + # KeysymToName may just be an index into the ntk constant. + # + # Actually we may just include a $name => $hex table and screw + # all else. But the text still begs for compression and the numbers + # for filtering and compression. + # + # Or actually []{$hex, $name}, stable sorted by $hex, and having + # the $name be an index into a constant. On construction we keep + # a map so that only the first $hex occurrence receives a name. + # + # My biggest gripe is probably source code size that won't go down + # because the constants are just so large (158K). + + my (@ktnK, @ktnV); + for (sort keys %keysymtoname) { + push @ktnK, $_; + push @ktnV, $keysymtoname{$_}; + } + print "var ktnKeys = []xproto.Keysym{${\join \", \", @ktnK}}"; + print "var ktnValues = \"${\join \" \", @ktnV}\""; + + my (@ntkK, @ntkV); + for (sort keys %nametokeysym) { + push @ntkK, $_; + push @ntkV, $nametokeysym{$_}; + } + print "var ntkKeys = \"${\join \" \", @ntkK}\""; + print "var ntkValues = []xproto.Keysym{${\join \", \", @ntkV}}"; + } +') + +// KeysymToName maps X11 keysym constants to their names. +var KeysymToName = map[xproto.Keysym]string{} + +// NameToKeysym maps X11 keysym names to their constants. +var NameToKeysym = map[string]xproto.Keysym{} + +func init() { + x := strings.Split(ktnValues, " ") + for i, keysym := range ktnKeys { + KeysymToName[keysym] = x[i] + } + for i, name := range strings.Split(ntkKeys, " ") { + NameToKeysym[name] = ntkValues[i] + } +} +EOF -- cgit v1.2.3