-
Notifications
You must be signed in to change notification settings - Fork 3
/
keysyms.pl
executable file
·424 lines (329 loc) · 11.6 KB
/
keysyms.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#!/usr/bin/perl -w
# keysyms.pl: generate keysyms.c from keysyms.dat
# Copyright (c) 2000-2013 Philip Kendall, Matan Ziv-Av, Russell Marks,
# Fredrick Meunier, Catalin Mihaila, Stuart Brady
# Copyright (c) 2015 Sergio Baldoví
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Author contact information:
# E-mail: philip-fuse@shadowmagic.org.uk
use strict;
use lib '../../perl';
use Fuse;
my $ui = shift;
$ui = 'gtk' unless defined $ui;
die "$0: unrecognised user interface: $ui\n"
unless 0 < grep { $ui eq $_ } ( 'gtk', 'x', 'fb', 'sdl', 'win32', 'wii' );
sub fb_keysym ($) {
my $keysym = shift;
$keysym =~ tr/a-z/A-Z/;
substr( $keysym, 0, 4 ) = 'WIN' if substr( $keysym, 0, 5 ) eq 'META_';
return $keysym;
}
sub wii_keysym ($) {
my $keysym = shift;
$keysym =~ tr/a-z/A-Z/;
return "WII_KEY_$keysym";
}
sub sdl_keysym ($) {
my $keysym = shift;
if ( $keysym =~ /[a-zA-Z][a-z]+/ ) {
$keysym =~ tr/a-z/A-Z/;
}
$keysym =~ s/(.*)_L$/L$1/;
$keysym =~ s/(.*)_R$/R$1/;
# All the magic #defines start with `SDLK_'
$keysym = "SDLK_$keysym";
return $keysym;
}
sub sdl_unicode_keysym ($) {
my $keysym = shift;
if ( $keysym eq "'" ) {
$keysym = "\\'";
}
$keysym = "'$keysym'";
return $keysym;
}
sub win32_keysym ($) {
my $keysym = shift;
# http://msdn.microsoft.com/en-us/library/dd375731(VS.85).aspx
$keysym =~ tr/a-z/A-Z/;
if ( $keysym =~ /^[A-Z0-9]$/ ) {
$keysym = "'$keysym'";
} else {
$keysym =~ s/(.*)_L$/$1/;
$keysym =~ s/META$/LWIN/;
$keysym =~ s/ALT$/MENU/; # Not a typo: the 'menu' key is VK_APPS
# All the magic #defines start with `VK_'
$keysym = "VK_$keysym";
}
return $keysym;
}
# Parameters for each UI
my %ui_data = (
fb => { headers => [ ],
# max_length not used
skips => { },
translations => {
Mode_switch => 'MENU',
},
function => \&fb_keysym
},
wii => { headers => [ 'ui/wii/wiikeysyms.h' ],
max_length => 24,
skips => { map { $_ => 1 } ( 'numbersign',
'Shift_L', 'Shift_R',
'Control_L', 'Control_R',
'Alt_L', 'Alt_R',
'Meta_L', 'Meta_R',
'Hyper_L','Hyper_R',
'Super_L','Super_R',
'KP_Enter',
'Mode_switch' ) },
function => \&wii_keysym
},
gtk => { headers => [ 'gdk/gdkkeysyms.h', 'ui/gtk/gtkcompat.h' ],
max_length => 16,
skips => { },
translations => { },
function => sub ($) { "GDK_KEY_$_[0]" },
},
sdl => { headers => [ 'SDL.h' ],
max_length => 18,
skips => { map { $_ => 1 } ( 'Hyper_L','Hyper_R','Caps_Lock',
'A' .. 'Z', 'asciitilde', 'bar', 'dead_circumflex',
'braceleft', 'braceright', 'percent' ) },
unicode_skips => { map { $_ => 1 } qw( Hyper_L Hyper_R Caps_Lock
Escape F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
BackSpace Tab Caps_Lock Return Shift_L Shift_R
Control_L Control_R Alt_L Alt_R Meta_L Meta_R
Super_L Super_R Mode_switch Up Down Left Right
Insert Delete Home End Page_Up Page_Down KP_Enter
dead_circumflex KP_Divide KP_Period ) },
translations => {
apostrophe => 'QUOTE',
asciicircum => 'CARET',
bracketleft => 'LEFTBRACKET',
bracketright => 'RIGHTBRACKET',
exclam => 'EXCLAIM',
Control_L => 'LCTRL',
Control_R => 'RCTRL',
equal => 'EQUALS',
numbersign => 'HASH',
Mode_switch => 'MENU',
Page_Up => 'PAGEUP',
Page_Down => 'PAGEDOWN',
parenleft => 'LEFTPAREN',
parenright => 'RIGHTPAREN',
},
unicode_translations => {
space => ' ',
exclam => '!',
dollar => '$',
numbersign => '#',
ampersand => "&",
apostrophe => "'",
asciitilde => "~",
at => "@",
backslash => "\\\\",
braceleft => "{",
braceright => "}",
bracketleft => "[",
bracketright => "]",
parenleft => "(",
parenright => ")",
percent => "%",
question => "?",
quotedbl => '\\"',
asterisk => "*",
plus => "+",
comma => ',',
minus => '-',
period => '.',
slash => '/',
colon => ':',
semicolon => ';',
less => '<',
equal => '=',
greater => '>',
asciicircum => '^',
bar => '|',
underscore => '_',
},
function => \&sdl_keysym,
unicode_function => \&sdl_unicode_keysym,
},
x => { headers => [ 'X11/keysym.h' ],
max_length => 15,
skips => { },
translations => { },
function => sub ($) { "XK_$_[0]" },
},
win32 => { headers => [ 'windows.h' ],
max_length => 16,
skips => { map { $_ => 1 } ( 'Shift_R','Control_R',
'Alt_R','Meta_R',
'Hyper_L','Hyper_R',
'Super_L','Super_R',
'KP_Enter',
'dollar','less','greater','exclam',
'ampersand','parenleft','parenright',
'asterisk','plus','colon','bar',
'braceleft','braceright','bracketleft','bracketright',
'apostrophe','asciicircum','dead_circumflex','asciitilde',
'at','backslash','comma','equal','minus','numbersign',
'percent','period','question','quotedbl',
'semicolon','slash','underscore',
'A' .. 'Z' ) },
translations => {
BackSpace => 'BACK',
Page_Up => 'PRIOR',
Page_Down => 'NEXT',
Caps_Lock => 'CAPITAL',
Mode_switch => 'APPS',
},
function => \&win32_keysym
},
);
# Translation table for any UI which uses keyboard mode K_MEDIUMRAW
my @cooked_keysyms = (
# 0x00
undef, 'ESCAPE', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '0', 'MINUS', 'EQUAL', 'BACKSPACE', 'TAB',
# 0x10
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', 'BRACKETLEFT', 'BRACKETRIGHT', 'RETURN', 'CONTROL_L', 'A', 'S',
# 0x20
'D', 'F', 'G', 'H', 'J', 'K', 'L', 'SEMICOLON',
'APOSTROPHE', 'GRAVE', 'SHIFT_L', 'NUMBERSIGN', 'Z', 'X', 'C', 'V',
# 0x30
'B', 'N', 'M', 'COMMA', 'PERIOD', 'SLASH', 'SHIFT_R', 'KB_MULTIPLY',
'ALT_L', 'SPACE', 'CAPS_LOCK', 'F1', 'F2', 'F3', 'F4', 'F5',
# 0x40
'F6', 'F7', 'F8', 'F9', 'F10', 'NUM_LOCK', 'SCROLL_LOCK', 'KP_7',
'KP_8', 'KP_9', 'KP_MINUS', 'KP_4', 'KP_5', 'KP_6', 'KP_PLUS', 'KP_1',
# 0x50
'KP_2', 'KP_3', 'KP_0', 'KP_DECIMAL', undef, undef, 'BACKSLASH', 'F11',
'F12', undef, undef, undef, undef, undef, undef, undef,
# 0x60
'KP_ENTER', 'CONTROL_R', 'KP_DIVIDE', 'PRINT', 'ALT_R', undef, 'HOME','UP',
'PAGE_UP', 'LEFT', 'RIGHT', 'END', 'DOWN', 'PAGE_DOWN', 'INSERT', 'DELETE',
# 0x70
undef, undef, undef, undef, undef, undef, undef, 'BREAK',
undef, undef, undef, undef, undef, 'WIN_L', 'WIN_R', 'MENU'
);
my @keys;
while(<>) {
next if /^\s*$/;
next if /^\s*\#/;
chomp;
my( $keysym, $key1, $key2 ) = split /\s*,\s*/;
push @keys, [ $keysym, $key1, $key2 ]
}
my $define = uc $ui;
print Fuse::GPL(
'keysyms.c: UI keysym to Fuse input layer keysym mappings',
"2000-2007 Philip Kendall, Matan Ziv-Av, Russell Marks\n" .
" Fredrick Meunier, Catalin Mihaila, Stuart Brady" ),
<< "CODE";
/* This file is autogenerated from keysyms.dat by keysyms.pl.
Do not edit unless you know what you're doing! */
#include "config.h"
CODE
# Comment to unbreak Emacs' perl mode
print << "CODE";
#include "input.h"
#include "keyboard.h"
CODE
# Comment to unbreak Emacs' perl mode
foreach my $header ( @{ $ui_data{$ui}{headers} } ) {
print "#include <$header>\n";
}
print "\nkeysyms_map_t keysyms_map[] = {\n\n";
KEY:
foreach( @keys ) {
my( $keysym ) = @$_;
next if $ui_data{$ui}{skips}{$keysym};
my $ui_keysym = $keysym;
$ui_keysym = $ui_data{$ui}{translations}{$keysym} if
$ui_data{$ui}{translations}{$keysym};
$ui_keysym = $ui_data{$ui}{function}->( $ui_keysym );
if( $ui eq 'fb' ) {
for( my $i = 0; $i <= $#cooked_keysyms; $i++ ) {
next unless defined $cooked_keysyms[$i] and
$cooked_keysyms[$i] eq $ui_keysym;
printf " { %3i, INPUT_KEY_%-12s },\n", $i, $keysym;
last;
}
} else {
printf " { %-$ui_data{$ui}{max_length}s INPUT_KEY_%-12s },\n",
"$ui_keysym,", $keysym;
}
}
print << "CODE";
{ 0, 0 } /* End marker: DO NOT MOVE! */
};
CODE
if( $ui eq 'sdl' ) {
print "\nkeysyms_map_t unicode_keysyms_map[] = {\n\n";
foreach( @keys ) {
my( $keysym ) = @$_;
next if $ui_data{$ui}{unicode_skips}{$keysym};
my $ui_keysym = $keysym;
$ui_keysym = $ui_data{$ui}{unicode_translations}{$keysym} if
$ui_data{$ui}{unicode_translations}{$keysym};
$ui_keysym = $ui_data{$ui}{unicode_function}->( $ui_keysym );
printf " { %-$ui_data{$ui}{max_length}s INPUT_KEY_%-12s },\n",
"$ui_keysym,", $keysym;
}
print << "CODE";
{ 0, 0 } /* End marker: DO NOT MOVE! */
};
CODE
}
if( $ui eq 'win32' ) {
print << "CODE";
keysyms_map_t oem_keysyms_map[] = {
{ '&', INPUT_KEY_ampersand },
{ '\\'', INPUT_KEY_apostrophe },
{ '~', INPUT_KEY_asciitilde },
{ '*', INPUT_KEY_asterisk },
{ '\@', INPUT_KEY_at },
{ '\\\\', INPUT_KEY_backslash },
{ '|', INPUT_KEY_bar },
{ '{', INPUT_KEY_braceleft },
{ '}', INPUT_KEY_braceright },
{ '[', INPUT_KEY_bracketleft },
{ ']', INPUT_KEY_bracketright },
{ ':', INPUT_KEY_colon },
{ ',', INPUT_KEY_comma },
{ '\$', INPUT_KEY_dollar },
{ '=', INPUT_KEY_equal },
{ '!', INPUT_KEY_exclam },
{ '>', INPUT_KEY_greater },
{ '<', INPUT_KEY_less },
{ '-', INPUT_KEY_minus },
{ '#', INPUT_KEY_numbersign },
{ '(', INPUT_KEY_parenleft },
{ ')', INPUT_KEY_parenright },
{ '%', INPUT_KEY_percent },
{ '.', INPUT_KEY_period },
{ '+', INPUT_KEY_plus },
{ '?', INPUT_KEY_question },
{ '"', INPUT_KEY_quotedbl },
{ ';', INPUT_KEY_semicolon },
{ '/', INPUT_KEY_slash },
{ '_', INPUT_KEY_underscore },
{ 0, 0 } /* End marker: DO NOT MOVE! */
};
CODE
}