2009-08-12 06:49:53 +04:00
|
|
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
|
|
|
|
/*
|
2009-08-12 07:00:52 +04:00
|
|
|
* genkeymap.c
|
2009-08-12 06:49:53 +04:00
|
|
|
* Copyright (C) Ádám Wallner 2008 <wallner@bitbaro.hu>
|
2009-08-12 10:18:05 +04:00
|
|
|
*
|
2009-08-12 06:49:53 +04:00
|
|
|
* 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.
|
2009-08-12 10:18:05 +04:00
|
|
|
*
|
2009-08-12 06:49:53 +04:00
|
|
|
* 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.
|
2009-08-12 10:18:05 +04:00
|
|
|
*
|
2009-08-12 06:49:53 +04:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with main.cc. If not, write to:
|
2009-08-12 10:18:05 +04:00
|
|
|
* The Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor
|
|
|
|
* Boston, MA 02110-1301, USA
|
|
|
|
|
|
|
|
Updated Jay Sorg 2009
|
2009-08-12 06:49:53 +04:00
|
|
|
|
2016-05-05 10:05:23 +03:00
|
|
|
cs Czech 0x405
|
|
|
|
de German 0x407
|
|
|
|
en-us US English 0x409
|
|
|
|
fr French 0x40c
|
|
|
|
it Italian 0x410
|
2009-08-12 06:49:53 +04:00
|
|
|
br Portuguese (Brazil) 0x416
|
2016-05-05 10:05:23 +03:00
|
|
|
ru Russian 0x419
|
|
|
|
se Swedish 0x41d
|
|
|
|
en-uk UK English 0x809
|
2009-08-12 06:49:53 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-08-12 10:18:05 +04:00
|
|
|
#include <string.h>
|
2009-08-12 06:49:53 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
2014-10-27 14:39:05 +03:00
|
|
|
#include <X11/XKBlib.h>
|
2009-08-12 06:49:53 +04:00
|
|
|
#include <locale.h>
|
|
|
|
|
2014-10-27 14:39:05 +03:00
|
|
|
extern int xfree86_to_evdev[137-8];
|
|
|
|
|
2009-08-12 10:18:05 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
const char *programname;
|
|
|
|
char text[256];
|
|
|
|
char *displayname = NULL;
|
|
|
|
char *outfname;
|
2016-06-22 02:30:17 +03:00
|
|
|
const char *sections[8] = {
|
|
|
|
"noshift", "shift", "altgr", "shiftaltgr",
|
|
|
|
"capslock", "capslockaltgr", "shiftcapslock", "shiftcapslockaltgr"
|
|
|
|
};
|
2014-10-24 14:02:00 +04:00
|
|
|
int states[8] = {0, 1, 0x80, 0x81, 2, 0x82, 3, 0x83};
|
2012-09-20 07:51:34 +04:00
|
|
|
int i;
|
|
|
|
int idx;
|
|
|
|
int char_count;
|
|
|
|
int nbytes = 0;
|
|
|
|
int unicode;
|
|
|
|
Display *dpy;
|
|
|
|
KeySym ks;
|
|
|
|
FILE *outf;
|
|
|
|
XKeyPressedEvent e;
|
|
|
|
wchar_t wtext[256];
|
2014-10-27 14:39:05 +03:00
|
|
|
XkbDescPtr kbdesc;
|
|
|
|
char *symatom;
|
|
|
|
int is_evdev;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
programname = argv[0];
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s out_filename\n", programname);
|
2016-10-11 04:59:54 +03:00
|
|
|
fprintf(stderr, "Example: %s /etc/xrdp/km-00000409.ini\n", programname);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
outfname = argv[1];
|
|
|
|
dpy = XOpenDisplay(displayname);
|
|
|
|
|
|
|
|
if (!dpy)
|
2009-08-12 10:18:05 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
fprintf(stderr, "%s: unable to open display '%s'\n",
|
|
|
|
programname, XDisplayName(displayname));
|
|
|
|
return 1;
|
2009-08-12 10:18:05 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2014-10-27 14:39:05 +03:00
|
|
|
/* 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);
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
outf = fopen(outfname, "w");
|
|
|
|
|
|
|
|
if (outf == NULL)
|
2009-08-12 10:18:05 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
fprintf(stderr, "%s: unable to create file '%s'\n", programname, outfname);
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
return 1;
|
2009-08-12 10:18:05 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
memset(&e, 0, sizeof(e));
|
|
|
|
e.type = KeyPress;
|
|
|
|
e.serial = 16;
|
|
|
|
e.send_event = True;
|
|
|
|
e.display = dpy;
|
|
|
|
e.same_screen = True;
|
|
|
|
|
2014-10-24 14:02:00 +04:00
|
|
|
for (idx = 0; idx < 8; idx++) /* Sections and states */
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
fprintf(outf, "[%s]\n", sections[idx]);
|
|
|
|
e.state = states[idx];
|
|
|
|
|
|
|
|
for (i = 8; i <= 137; i++) /* Keycodes */
|
|
|
|
{
|
2014-10-27 14:39:05 +03:00
|
|
|
if (is_evdev)
|
|
|
|
e.keycode = xfree86_to_evdev[i-8];
|
|
|
|
else
|
|
|
|
e.keycode = i;
|
2012-09-20 07:51:34 +04:00
|
|
|
nbytes = XLookupString(&e, text, 255, &ks, NULL);
|
|
|
|
text[nbytes] = 0;
|
|
|
|
char_count = mbstowcs(wtext, text, 255);
|
|
|
|
unicode = 0;
|
|
|
|
|
|
|
|
if (char_count == 1)
|
|
|
|
{
|
|
|
|
unicode = wtext[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(outf, "Key%d=%d:%d\n", i, (int) ks, unicode);
|
|
|
|
}
|
|
|
|
|
2014-10-24 14:02:00 +04:00
|
|
|
if (idx != 7)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
fprintf(outf, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
fclose(outf);
|
|
|
|
return 0;
|
2009-08-12 06:49:53 +04:00
|
|
|
}
|