Generate correct xfree86 keymaps when evdev is used
Use a mapping table to map xfree86 keycodes to evdev keycodes and obtain consistent keysyms for keymaps. This way, it is now possible to generate correct keymaps when evdev driver is used on host.
This commit is contained in:
parent
2f919932cb
commit
0409da6af9
@ -2,7 +2,7 @@
|
||||
bin_PROGRAMS = \
|
||||
xrdp-genkeymap
|
||||
|
||||
xrdp_genkeymap_SOURCES = genkeymap.c
|
||||
xrdp_genkeymap_SOURCES = genkeymap.c evdev-map.c
|
||||
|
||||
xrdp_genkeymap_LDADD = \
|
||||
-L/usr/X11R6/lib \
|
||||
|
156
genkeymap/evdev-map.c
Normal file
156
genkeymap/evdev-map.c
Normal file
@ -0,0 +1,156 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
|
||||
/*
|
||||
* evdev-map.c
|
||||
* Copyright (C) Michał Górny 2014 <mgorny@gentoo.org>
|
||||
*
|
||||
* You may 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.
|
||||
*
|
||||
* main.cc 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 main.cc. If not, write to:
|
||||
* The Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301, USA
|
||||
*
|
||||
* xfree86(base)->evdev keycode mapping
|
||||
*/
|
||||
|
||||
int xfree86_to_evdev[137-8+1] = {
|
||||
/* MDSW */ 203,
|
||||
/* ESC */ 9,
|
||||
/* AE01 */ 10,
|
||||
/* AE02 */ 11,
|
||||
/* AE03 */ 12,
|
||||
/* AE04 */ 13,
|
||||
/* AE05 */ 14,
|
||||
/* AE06 */ 15,
|
||||
/* AE07 */ 16,
|
||||
/* AE08 */ 17,
|
||||
/* AE09 */ 18,
|
||||
/* AE10 */ 19,
|
||||
/* AE11 */ 20,
|
||||
/* AE12 */ 21,
|
||||
/* BKSP */ 22,
|
||||
/* TAB */ 23,
|
||||
/* AD01 */ 24,
|
||||
/* AD02 */ 25,
|
||||
/* AD03 */ 26,
|
||||
/* AD04 */ 27,
|
||||
/* AD05 */ 28,
|
||||
/* AD06 */ 29,
|
||||
/* AD07 */ 30,
|
||||
/* AD08 */ 31,
|
||||
/* AD09 */ 32,
|
||||
/* AD10 */ 33,
|
||||
/* AD11 */ 34,
|
||||
/* AD12 */ 35,
|
||||
/* RTRN */ 36,
|
||||
/* LCTL */ 37,
|
||||
/* AC01 */ 38,
|
||||
/* AC02 */ 39,
|
||||
/* AC03 */ 40,
|
||||
/* AC04 */ 41,
|
||||
/* AC05 */ 42,
|
||||
/* AC06 */ 43,
|
||||
/* AC07 */ 44,
|
||||
/* AC08 */ 45,
|
||||
/* AC09 */ 46,
|
||||
/* AC10 */ 47,
|
||||
/* AC11 */ 48,
|
||||
/* TLDE */ 49,
|
||||
/* LFSH */ 50,
|
||||
/* BKSL */ 51,
|
||||
/* AB01 */ 52,
|
||||
/* AB02 */ 53,
|
||||
/* AB03 */ 54,
|
||||
/* AB04 */ 55,
|
||||
/* AB05 */ 56,
|
||||
/* AB06 */ 57,
|
||||
/* AB07 */ 58,
|
||||
/* AB08 */ 59,
|
||||
/* AB09 */ 60,
|
||||
/* AB10 */ 61,
|
||||
/* RTSH */ 62,
|
||||
/* KPMU */ 63,
|
||||
/* LALT */ 64,
|
||||
/* SPCE */ 65,
|
||||
/* CAPS */ 66,
|
||||
/* FK01 */ 67,
|
||||
/* FK02 */ 68,
|
||||
/* FK03 */ 69,
|
||||
/* FK04 */ 70,
|
||||
/* FK05 */ 71,
|
||||
/* FK06 */ 72,
|
||||
/* FK07 */ 73,
|
||||
/* FK08 */ 74,
|
||||
/* FK09 */ 75,
|
||||
/* FK10 */ 76,
|
||||
/* NMLK */ 77,
|
||||
/* SCLK */ 78,
|
||||
/* KP7 */ 79,
|
||||
/* KP8 */ 80,
|
||||
/* KP9 */ 81,
|
||||
/* KPSU */ 82,
|
||||
/* KP4 */ 83,
|
||||
/* KP5 */ 84,
|
||||
/* KP6 */ 85,
|
||||
/* KPAD */ 86,
|
||||
/* KP1 */ 87,
|
||||
/* KP2 */ 88,
|
||||
/* KP3 */ 89,
|
||||
/* KP0 */ 90,
|
||||
/* KPDL */ 91,
|
||||
/* SYRQ */ 107,
|
||||
/* II5D */ 0,
|
||||
/* LSGT */ 94,
|
||||
/* FK11 */ 95,
|
||||
/* FK12 */ 96,
|
||||
/* HOME */ 110,
|
||||
/* UP */ 111,
|
||||
/* PGUP */ 112,
|
||||
/* LEFT */ 113,
|
||||
/* II65 */ 0,
|
||||
/* RGHT */ 114,
|
||||
/* END */ 115,
|
||||
/* DOWN */ 116,
|
||||
/* PGDN */ 117,
|
||||
/* INS */ 118,
|
||||
/* DELE */ 119,
|
||||
/* KPEN */ 104,
|
||||
/* RCTL */ 105,
|
||||
/* PAUS */ 127,
|
||||
/* PRSC */ 107,
|
||||
/* KPDV */ 106,
|
||||
/* RALT */ 108,
|
||||
/* BRK */ 419,
|
||||
/* LWIN */ 133,
|
||||
/* RWIN */ 134,
|
||||
/* MENU */ 0,
|
||||
/* FK13 */ 191,
|
||||
/* FK14 */ 192,
|
||||
/* FK15 */ 193,
|
||||
/* FK16 */ 194,
|
||||
/* FK17 */ 195,
|
||||
/* KPDC */ 0,
|
||||
/* LVL3 */ 92,
|
||||
/* ALT */ 204,
|
||||
/* KPEQ */ 125,
|
||||
/* SUPR */ 206,
|
||||
/* HYPR */ 207,
|
||||
/* XFER */ 0,
|
||||
/* I02 */ 0,
|
||||
/* NFER */ 0,
|
||||
/* I04 */ 0,
|
||||
/* AE13 */ 132,
|
||||
/* I06 */ 0,
|
||||
/* I07 */ 0,
|
||||
0,
|
||||
0
|
||||
};
|
@ -37,8 +37,11 @@
|
||||
#include <string.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/XKBlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
extern int xfree86_to_evdev[137-8];
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *programname;
|
||||
@ -57,6 +60,9 @@ int main(int argc, char **argv)
|
||||
FILE *outf;
|
||||
XKeyPressedEvent e;
|
||||
wchar_t wtext[256];
|
||||
XkbDescPtr kbdesc;
|
||||
char *symatom;
|
||||
int is_evdev;
|
||||
|
||||
setlocale(LC_CTYPE, "");
|
||||
programname = argv[0];
|
||||
@ -78,6 +84,30 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* check whether evdev is used */
|
||||
kbdesc = XkbAllocKeyboard();
|
||||
if (!kbdesc)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to allocate keyboard desc\n",
|
||||
programname);
|
||||
XCloseDisplay(dpy);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (XkbGetNames(dpy, XkbKeycodesNameMask, kbdesc) != Success)
|
||||
{
|
||||
fprintf(stderr, "%s: unable to obtain keycode name for keyboard\n",
|
||||
programname);
|
||||
XkbFreeKeyboard(kbdesc, 0, True);
|
||||
XCloseDisplay(dpy);
|
||||
return 1;
|
||||
}
|
||||
|
||||
symatom = XGetAtomName(dpy, kbdesc->names->keycodes);
|
||||
is_evdev = !strncmp(symatom, "evdev", 5);
|
||||
XFree(symatom);
|
||||
XkbFreeKeyboard(kbdesc, 0, True);
|
||||
|
||||
outf = fopen(outfname, "w");
|
||||
|
||||
if (outf == NULL)
|
||||
@ -101,7 +131,10 @@ int main(int argc, char **argv)
|
||||
|
||||
for (i = 8; i <= 137; i++) /* Keycodes */
|
||||
{
|
||||
e.keycode = i;
|
||||
if (is_evdev)
|
||||
e.keycode = xfree86_to_evdev[i-8];
|
||||
else
|
||||
e.keycode = i;
|
||||
nbytes = XLookupString(&e, text, 255, &ks, NULL);
|
||||
text[nbytes] = 0;
|
||||
char_count = mbstowcs(wtext, text, 255);
|
||||
|
Loading…
Reference in New Issue
Block a user