keyboard/altgr/unigraph: export script mkxkbsymbols
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 7 Mar 2024 18:20:06 +0000 (19:20 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 8 Apr 2024 15:39:26 +0000 (17:39 +0200)
Makefile
keyboard/altgr/unigraph.eng.inc.pl
tools/mkxkbsymbols [new file with mode: 0755]

index df6cbe5bab35d15e5837a61ca3d67c2f711a6e59..7db808b04a03d1577d276026f9d05773b42a08b6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ word/put.js: $(download)
 word/%.min.js: word/%.js
        uglifyjs -m '' $< -o $@
 
-data: data/digraphs.json data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.json data/unicode-sampler word
+data: data/digraphs.json data/unicode-cover.inc.pl data/countries.inc.pl data/browser data/termcol-xcolor.inc.pl data/digraphs-xorg.json data/unicode-sampler word keyboard/symbols/unigraph
 
 data/DerivedAge.txt: $(download)
        tools/wget-ifmodified http://www.unicode.org/Public/UNIDATA/$(@F) $@
@@ -56,6 +56,9 @@ data/keysymdef.json: tools/mkxkeysymdef data/keysymdef.h
 data/digraphs-xorg.json: tools/mkdigraphs-xorg data/xorg-compose data/keysymdef.json
        $(call cmdsave,$^)
 
+keyboard/symbols/%: tools/mkxkbsymbols data/keyboard/altgr/%.eng.json
+       $(call cmdsave,$^)
+
 data/digraphs-vim.inc.pl: tools/mkdigraphs-vim
        $(call cmdsave,$<)
 
index e54badf90cc7405897cf51418d2e6e9d4f26f50d..89498ff5100c578dbc87b5b31ba2ed21aec4d407 100644 (file)
@@ -83,6 +83,7 @@ while (my ($k, $c) = each %rows) {
                ),
                'Inspired by <a href="/keyboard/altgr/msx-graph">MSX graph</a> mode,',
                'but reimagined for modern Unicode coverage.',
+               'Freely available as <a href="/keyboard/symbols/unigraph">xorg symbols</a> export.',
        ),
        moderows => '5421',
        flag => {
diff --git a/tools/mkxkbsymbols b/tools/mkxkbsymbols
new file mode 100755 (executable)
index 0000000..0a24a7f
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+use 5.014;
+use warnings;
+use utf8;
+
+use JSON ();
+
+our $VERSION = '1.00';
+
+my $info = eval {
+       local $/;
+       return JSON->new->utf8->decode(readline);
+} or die "Could not read keyboard layout data: $@\n";
+
+my $geochar = do './keyspos.inc.pl'
+       or die "Could not read keyboard position names: $@\n";
+
+if (($info->{moderows} // '') =~ /4/) {
+       push @{$_}, map {"+$_"} @{$_} for values %{$geochar};
+}
+
+my ($name) = $ARGV =~ m{.*/([^.]+)};
+say "// setxkbmap -print $name | xkbcomp -w0 -I.. - \$DISPLAY";
+say '';
+
+say sprintf 'xkb_symbols "%s" {', $info->{title};
+for my $k (sort keys %{$geochar}) {
+       printf "\tkey <%s> {[%s]};\n", $k, join(', ',
+               map { !$_ ? 'NoSymbol' : sprintf 'U%04X', ord }
+               map { $info->{key}->{$_} } @{ $geochar->{$k} }
+       );
+}
+say '};';
+
+=head1 NAME
+
+mkxkbsymbols - Export keyboard layout metadata as Xorg symbols
+
+=head1 SYNOPSIS
+
+    tools/mkxkbsymbols data/keyboard/altgr/$NAME.eng.json >$NAME
+    setxkbmap -print $NAME | xkbcomp -w0 -I.. - $DISPLAY
+
+=head1 DESCRIPTION
+
+Converts site includes (back) to I<xkb_symbols> configurations
+compatible with C<xkbcomp> so it can be used in Xorg.
+
+=head1 AUTHOR
+
+Mischa POSLAWSKY <perl@shiar.org>
+
+=head1 LICENSE
+
+Licensed under the GNU Affero General Public License version 3.
+