Add keymap parsing script and corresponding keymap for en-us.

This commit is contained in:
Michael Jumper 2014-01-02 16:58:59 -08:00
parent 54b16f2db4
commit a0531ca152
4 changed files with 369 additions and 0 deletions

2
src/protocols/rdp/keymaps/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Autogenerated .c
*.c

View File

@ -0,0 +1,86 @@
#
# Copyright (C) 2013 Glyptodon LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
name "base"
# Typeable characters
map 0x39 ~ " " # Space
map 0x0F ~ 0xff09 # Tab
# Control characters
map 0x0E ~ 0xff08 # BackSpace
map 0x1C ~ 0xff0d # Return
map 0x01 ~ 0xff1b # Escape
map +ext 0x52 ~ 0xff63 # Insert
map +ext 0x53 ~ 0xffff # Delete
map +ext 0x47 ~ 0xff50 # Home
map +ext 0x4F ~ 0xff57 # End
map +ext 0x4B ~ 0xff51 # Left
map +ext 0x48 ~ 0xff52 # Up
map +ext 0x4D ~ 0xff53 # Right
map +ext 0x50 ~ 0xff54 # Down
map +ext 0x49 ~ 0xff55 # Page_Up
map +ext 0x51 ~ 0xff56 # Page_Down
# Locks
map 0x45 ~ 0xff7f # Num_Lock
map 0x46 ~ 0xff14 # Scroll_Lock
map +ext 0x3A ~ 0xffe5 # Caps_Lock
# Keypad numerals
map 0x52 ~ 0xffb0 # KP_0
map 0x4F ~ 0xffb1 # KP_1
map 0x50 ~ 0xffb2 # KP_2
map 0x51 ~ 0xffb3 # KP_3
map 0x4B ~ 0xffb4 # KP_4
map 0x4C ~ 0xffb5 # KP_5
map 0x4D ~ 0xffb6 # KP_6
map 0x47 ~ 0xffb7 # KP_7
map 0x48 ~ 0xffb8 # KP_8
map 0x49 ~ 0xffb9 # KP_9
# F keys
map 0x3B ~ 0xffbe # F1
map 0x3C ~ 0xffbf # F2
map 0x3D ~ 0xffc0 # F3
map 0x3E ~ 0xffc1 # F4
map 0x3F ~ 0xffc2 # F5
map 0x40 ~ 0xffc3 # F6
map 0x41 ~ 0xffc4 # F7
map 0x42 ~ 0xffc5 # F8
map 0x43 ~ 0xffc6 # F9
map 0x44 ~ 0xffc7 # F10
map 0x57 ~ 0xffc8 # F11
map 0x58 ~ 0xffc9 # F12
# Modifiers
map 0x2A ~ 0xffe1 # Shift_L
map 0x36 ~ 0xffe2 # Shift_R
map 0x1D ~ 0xffe3 # Control_L
map 0x9D ~ 0xffe4 # Control_R
map 0x38 ~ 0xffe9 # Alt_L
map +ext 0x38 ~ 0xffea # Alt_R
map +ext 0x38 ~ 0xfe03 # ISO_Level3_Shift
map +ext 0x5B ~ 0xffeb # Super_L
map +ext 0x5C ~ 0xffec # Super_R
map +ext 0x5D ~ 0xff67 # Menu

View File

@ -0,0 +1,36 @@
#
# Copyright (C) 2013 Glyptodon LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
parent "base"
name "en-us-qwerty"
freerdp "KBD_US"
map -shift 0x29 0x02..0x0D ~ "`1234567890-="
map -shift 0x10..0x1B 0x2B ~ "qwertyuiop[]\"
map -shift 0x1E..0x28 ~ "asdfghjkl;'"
map -shift 0x2C..0x35 ~ "zxcvbnm,./"
map +shift 0x29 0x02..0x0D ~ "~!@#$%^&*()_+"
map +shift 0x10..0x1B 0x2B ~ "QWERTYUIOP{}|"
map +shift 0x1E..0x28 ~ "ASDFGHJKL:""
map +shift 0x2C..0x35 ~ "ZXCVBNM<>?"

View File

@ -0,0 +1,245 @@
#!/usr/bin/perl
#
# Copyright (C) 2013 Glyptodon LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#
# generate.pl
#
# Parse .keymap files, producing corresponding .c files that can be included
# into the RDP plugin source.
#
sub keymap_symbol {
my $_ = shift;
s/-/_/g;
return 'guac_rdp_keymap_' . $_;
}
for $filename (@ARGV) {
# Header
$src = '/* Autogenerated from ' . $filename . ' */' . "\n"
. "\n"
. '#include "config.h"' . "\n"
. '#include "rdp_keymap.h"' . "\n"
. '#include <freerdp/input.h>' . "\n"
. "\n"
. '#ifdef HAVE_FREERDP_LOCALE_KEYBOARD_H' . "\n"
. '#include <freerdp/locale/keyboard.h>' . "\n"
. '#else' . "\n"
. '#include <freerdp/kbd/layouts.h>' . "\n"
. '#endif' . "\n"
. "\n"
. 'static guac_rdp_keysym_desc __keymap[] = {' . "\n";
$parent = "";
$layout_name = "";
$freerdp = "";
# Parse file
open INPUT, '<', "$filename";
while (<INPUT>) {
chomp;
# Comments
if (m/^\s*#/) {}
# Name
elsif (($name) = m/^\s*name\s+"(.*)"\s*(?:#.*)?$/) {
$layout_name = $name;
}
# Parent map
elsif (($name) = m/^\s*parent\s+"(.*)"\s*(?:#.*)?$/) {
$parent = keymap_symbol($name);
}
# FreeRDP equiv
elsif (($name) = m/^\s*freerdp\s+"(.*)"\s*(?:#.*)?$/) {
$freerdp = $name;
}
# Map
elsif (($range, $onto) =
m/^\s*map\s+([^~]*)\s+~\s+(".*"|0x[0-9A-Fa-f]+)\s*(?:#.*)?$/) {
@keysyms = ();
@scancodes = ();
$ext_flags = 0;
$set_shift = 0;
$set_altgr = 0;
$clear_shift = 0;
$clear_altgr = 0;
# Parse ranges and options
foreach $_ (split(/\s+/, $range)) {
# Set option/modifier
if (($opt) = m/^\+([a-z]+)$/) {
if ($opt eq "shift") { $set_shift = 1; }
elsif ($opt eq "altgr") { $set_altgr = 1; }
elsif ($opt eq "ext") { $ext_flags = 1; }
else {
die "$filename: $.: ERROR: "
. "Invalid set option\n";
}
}
# Clear option/modifier
elsif (($opt) = m/^-([a-z]+)$/) {
if ($opt eq "shift") { $clear_shift = 1; }
elsif ($opt eq "altgr") { $clear_altgr = 1; }
else {
die "$filename: $.: ERROR: "
. "Invalid clear option\n";
}
}
# Single scancode
elsif (($scancode) = m/^(0x[0-9A-Fa-f]+)$/) {
$scancodes[++$#scancodes] = hex($scancode);
}
# Range of scancodes
elsif (($start, $end) =
m/^(0x[0-9A-Fa-f]+)\.\.(0x[0-9A-Fa-f]+)$/) {
for ($i=hex($start); $i<=hex($end); $i++) {
$scancodes[++$#scancodes] = $i;
}
}
# Invalid token
else {
die "$filename: $.: ERROR: "
. "Invalid token\n";
}
}
# Parse onto
if ($onto =~ m/^0x/) {
$keysyms[0] = hex($onto);
}
else {
foreach $char (split("", substr($onto, 1, length($onto)-2))) {
$codepoint = unpack('U0U*', $char);
if ($codepoint >= 0x0100) {
$keysyms[++$#keysyms] = 0x01000000 | $codepoint;
}
else {
$keysyms[++$#keysyms] = $codepoint;
}
}
}
# Check mapping
if ($#keysyms != $#scancodes) {
die "$filename: $.: ERROR: "
. "Keysym and scancode range lengths differ\n";
}
# Write keysym/scancode pairs
for ($i=0; $i<=$#keysyms; $i++) {
$src .= " {"
. " .keysym = " . $keysyms[$i] . ","
. " .scancode = " . $scancodes[$i];
# Set requirements
if ($set_shift && !$set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT";
}
elsif (!$set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_ALTGR";
}
elsif ($set_shift && $set_altgr) {
$src .= ", .set_keysyms = GUAC_KEYSYMS_SHIFT_ALTGR";
}
# Clear requirements
if ($clear_shift && !$clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT";
}
elsif (!$clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALTGR";
}
elsif ($clear_shift && $clear_altgr) {
$src .= ", .clear_keysyms = GUAC_KEYSYMS_ALL_SHIFT_ALTGR";
}
# Flags
if ($ext_flags) {
$src .= ", .flags = KBD_FLAGS_EXTENDED";
}
$src .= " },\n";
}
}
# Invalid token
elsif (m/\S/) {
die "$filename: $.: ERROR: "
. "Invalid token\n";
}
}
close INPUT;
# Map footer
$src .= ' {0}' . "\n"
. '};' . "\n";
# Desc header
$keymap_sym = keymap_symbol($layout_name);
$src .= "\n"
. 'const guac_rdp_keymap ' . $keymap_sym . '[] = { ' . "\n";
# Layout name
$src .= " .name = \"$layout_name\",\n";
# Parent layout (if any)
if ($parent) {
$src .= " .parent = $parent,\n";
}
# FreeRDP layout (if any)
if ($freerdp) {
$src .= " .freerdp_keyboard_layout = $freerdp,\n";
}
# Desc footer
$src .= ' .mapping = __keymap' . "\n"
. '};' . "\n";
# Write output
open OUTPUT, ">", "$keymap_sym.c";
print OUTPUT "$src";
close OUTPUT;
print STDERR "Generated \"$keymap_sym.c\".\n";
}