-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxf86keys.pl
112 lines (97 loc) · 2.44 KB
/
xf86keys.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env perl
use warnings;
use strict;
use 5.018;
my $xmlHeader =
'<?xml version="1.0" encoding="UTF-8"?>
<schemalist>
<schema id="com.deepin.dde.keybinding.mediakey" path="/com/deepin/dde/keybinding/mediakey/" >
';
my $xmlFooter =
' </schema>
</schemalist>
';
sub decamelize {
my $s = shift;
$s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{
my $fc = pos($s)==0;
my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4);
my $t = $p0 || $fc ? $p0 : '-';
$t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2";
$t;
}ge;
$s;
}
sub trimSpace {
my $s = shift;
$s =~ s/\A\s+//;
$s =~ s/\s+\z//;
return $s;
}
sub printKeyDefine {
my ($fh, $name, $comment) = @_;
my $id = decamelize($name);
my $key = 'XF86'.$name;
printKey($fh, $id, $key, $comment);
}
sub printKey {
my ($fh, $id, $key, $comment) = @_;
my $format =
' <key type="as" name="%s">
<default>[\'%s\']</default>
<summary>%s</summary>
<description></description>
</key>
';
printf $fh $format, $id, $key, trimSpace($comment);
}
sub printIgnoreKeyDefine {
my ($fh, $name) = @_;
print $fh " <!-- ignore XF86$name-->\n";
}
my $XF86keysymHFile = $ARGV[0];
my $outputXMLFile = $ARGV[1];
warn "input $XF86keysymHFile,output $outputXMLFile";
#my $file = "/usr/include/X11/XF86keysym.h";
open OUT, '>', $outputXMLFile
or die $!;
print OUT $xmlHeader;
open FH, '<', $XF86keysymHFile
or die $!;
my @ignoreKeys = qw(
ClearGrab Ungrab LogWindowTree LogGrabInfo
iTouch Q RotationPB RotationKB BackForward Travel UserPB User1KB User2KB Market
);
while (my $line = <FH>) {
chomp $line;
if ($line =~ /^#define/ ) {
print ">>> ", $line , "\n";
if ($line =~ /^#define\s+XF86XK_(\w+)\s+0x[0-9A-F]+(\s*\/\*(.*)\*\/)?/ ) {
my $name = $1;
my $comment = $3;
if ( !defined $comment ) {
$comment = ""
}
# ignore some keys
if ($name =~ /^Switch_VT_/ ||
$name =~ /_VMode$/ ||
$name =~ /^Launch[0-9A-F]$/ ||
grep { $_ eq $name } @ignoreKeys
) {
printIgnoreKeyDefine(\*OUT, $name);
next;
}
say "name: $name, comment: {$comment}";
printKeyDefine(\*OUT, $name, $comment);
} else {
die "line don't match regex: $line";
}
}
}
close FH;
# Exceptions
printKey(\*OUT,'switch-monitors', 'mod4-p', '');
printKey(\*OUT,'capslock', 'Caps_Lock', '');
printKey(\*OUT,'numlock', 'Num_Lock', '');
print OUT $xmlFooter;
close OUT;