keyboard/altgr/unigraph: export script mkxkbsymbols
[sheet.git] / tools / mkxkbsymbols
1 #!/usr/bin/env perl
2 use 5.014;
3 use warnings;
4 use utf8;
5
6 use JSON ();
7
8 our $VERSION = '1.00';
9
10 my $info = eval {
11         local $/;
12         return JSON->new->utf8->decode(readline);
13 } or die "Could not read keyboard layout data: $@\n";
14
15 my $geochar = do './keyspos.inc.pl'
16         or die "Could not read keyboard position names: $@\n";
17
18 if (($info->{moderows} // '') =~ /4/) {
19         push @{$_}, map {"+$_"} @{$_} for values %{$geochar};
20 }
21
22 my ($name) = $ARGV =~ m{.*/([^.]+)};
23 say "// setxkbmap -print $name | xkbcomp -w0 -I.. - \$DISPLAY";
24 say '';
25
26 say sprintf 'xkb_symbols "%s" {', $info->{title};
27 for my $k (sort keys %{$geochar}) {
28         printf "\tkey <%s> {[%s]};\n", $k, join(', ',
29                 map { !$_ ? 'NoSymbol' : sprintf 'U%04X', ord }
30                 map { $info->{key}->{$_} } @{ $geochar->{$k} }
31         );
32 }
33 say '};';
34
35 =head1 NAME
36
37 mkxkbsymbols - Export keyboard layout metadata as Xorg symbols
38
39 =head1 SYNOPSIS
40
41     tools/mkxkbsymbols data/keyboard/altgr/$NAME.eng.json >$NAME
42     setxkbmap -print $NAME | xkbcomp -w0 -I.. - $DISPLAY
43
44 =head1 DESCRIPTION
45
46 Converts site includes (back) to I<xkb_symbols> configurations
47 compatible with C<xkbcomp> so it can be used in Xorg.
48
49 =head1 AUTHOR
50
51 Mischa POSLAWSKY <perl@shiar.org>
52
53 =head1 LICENSE
54
55 Licensed under the GNU Affero General Public License version 3.
56