Commit 3d11d0eb authored by bellard's avatar bellard

keymaps support (initial patch by Johannes Schindelin)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1173 c046a42c-6fe2-441c-8c8c-71466251a162
parent 7b91a172
......@@ -6,6 +6,7 @@ version 0.6.2:
- Cirrus VGA: support for 1280x1024x[8,15,16] modes
- 'pidfile' option
- .dmg disk image format support (Johannes Schindelin)
- keymaps support (initial patch by Johannes Schindelin)
version 0.6.1:
......
......@@ -56,6 +56,8 @@ install: all
ifndef CONFIG_WIN32
mkdir -p "$(mandir)/man1"
install qemu.1 qemu-img.1 "$(mandir)/man1"
mkdir -p "$(datadir)/keymaps"
install -m 644 keymaps/* "$(datadir)"
endif
for d in $(TARGET_DIRS); do \
$(MAKE) -C $$d $@ || exit 1 ; \
......
......@@ -333,7 +333,7 @@ endif
$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VL_LIBS)
sdl.o: sdl.c
sdl.o: sdl.c keymaps.c sdl_keysym.h
$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
sdlaudio.o: sdlaudio.c
......
/*
* QEMU keysym to keycode conversion using rdesktop keymaps
*
* Copyright (c) 2004 Johannes Schindelin
*
* 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.
*/
static int get_keysym(const char *name)
{
name2keysym_t *p;
for(p = name2keysym; p->name != NULL; p++) {
if (!strcmp(p->name, name))
return p->keysym;
}
return 0;
}
#define MAX_NORMAL_KEYCODE 512
#define MAX_EXTRA_COUNT 256
typedef struct {
uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
struct {
int keysym;
uint16_t keycode;
} keysym2keycode_extra[MAX_EXTRA_COUNT];
int extra_count;
} kbd_layout_t;
static kbd_layout_t *parse_keyboard_layout(const char *language,
kbd_layout_t * k)
{
FILE *f;
char file_name[1024];
char line[1024];
int len;
snprintf(file_name, sizeof(file_name),
"%s/keymaps/%s", bios_dir, language);
if (!k)
k = qemu_mallocz(sizeof(kbd_layout_t));
if (!k)
return 0;
if (!(f = fopen(file_name, "r"))) {
fprintf(stderr,
"Could not read keymap file: '%s'\n", file_name);
return 0;
}
for(;;) {
if (fgets(line, 1024, f) == NULL)
break;
len = strlen(line);
if (len > 0 && line[len - 1] == '\n')
line[len - 1] = '\0';
if (line[0] == '#')
continue;
if (!strncmp(line, "map ", 4))
continue;
if (!strncmp(line, "include ", 8)) {
parse_keyboard_layout(line + 8, k);
} else {
char *end_of_keysym = line;
while (*end_of_keysym != 0 && *end_of_keysym != ' ')
end_of_keysym++;
if (*end_of_keysym) {
int keysym;
*end_of_keysym = 0;
keysym = get_keysym(line);
if (keysym == 0) {
// fprintf(stderr, "Warning: unknown keysym %s\n", line);
} else {
const char *rest = end_of_keysym + 1;
int keycode = strtol(rest, NULL, 0);
/* if(keycode&0x80)
keycode=(keycode<<8)^0x80e0; */
if (keysym < MAX_NORMAL_KEYCODE) {
//fprintf(stderr,"Setting keysym %s (%d) to %d\n",line,keysym,keycode);
k->keysym2keycode[keysym] = keycode;
} else {
if (k->extra_count >= MAX_EXTRA_COUNT) {
fprintf(stderr,
"Warning: Could not assign keysym %s (0x%x) because of memory constraints.\n",
line, keysym);
} else {
fprintf(stderr, "Setting %d: %d,%d\n",
k->extra_count, keysym, keycode);
k->keysym2keycode_extra[k->extra_count].
keysym = keysym;
k->keysym2keycode_extra[k->extra_count].
keycode = keycode;
k->extra_count++;
}
}
}
}
}
}
fclose(f);
return k;
}
static void *init_keyboard_layout(const char *language)
{
return parse_keyboard_layout(language, 0);
}
static int keysym2scancode(void *kbd_layout, int keysym)
{
kbd_layout_t *k = kbd_layout;
if (keysym < MAX_NORMAL_KEYCODE) {
if (k->keysym2keycode[keysym] == 0)
fprintf(stderr, "Warning: no scancode found for keysym %d\n",
keysym);
return k->keysym2keycode[keysym];
} else {
int i;
#ifdef XK_ISO_Left_Tab
if (keysym == XK_ISO_Left_Tab)
keysym = XK_Tab;
#endif
for (i = 0; i < k->extra_count; i++)
if (k->keysym2keycode_extra[i].keysym == keysym)
return k->keysym2keycode_extra[i].keycode;
}
return 0;
}
# generated from XKB map ar
include common
map 0x401
exclam 0x02 shift
at 0x03 shift
numbersign 0x04 shift
dollar 0x05 shift
percent 0x06 shift
asciicircum 0x07 shift
ampersand 0x08 shift
asterisk 0x09 shift
parenleft 0x0a shift
parenright 0x0b shift
minus 0x0c
underscore 0x0c shift
equal 0x0d
plus 0x0d shift
Arabic_dad 0x10 altgr
Arabic_fatha 0x10 shift altgr
Arabic_sad 0x11 altgr
Arabic_fathatan 0x11 shift altgr
Arabic_theh 0x12 altgr
Arabic_damma 0x12 shift altgr
Arabic_qaf 0x13 altgr
Arabic_dammatan 0x13 shift altgr
Arabic_feh 0x14 altgr
UFEF9 0x14 shift altgr
Arabic_ghain 0x15 altgr
Arabic_hamzaunderalef 0x15 shift altgr
Arabic_ain 0x16 altgr
grave 0x16 shift altgr
Arabic_ha 0x17 altgr
division 0x17 shift altgr
Arabic_khah 0x18 altgr
multiply 0x18 shift altgr
Arabic_hah 0x19 altgr
Arabic_semicolon 0x19 shift altgr
bracketleft 0x1a
braceleft 0x1a shift
Arabic_jeem 0x1a altgr
bracketright 0x1b
braceright 0x1b shift
Arabic_dal 0x1b altgr
Arabic_sheen 0x1e altgr
backslash 0x1e shift altgr
Arabic_seen 0x1f altgr
Arabic_yeh 0x20 altgr
bracketleft 0x20 shift altgr
Arabic_beh 0x21 altgr
bracketright 0x21 shift altgr
Arabic_lam 0x22 altgr
UFEF7 0x22 shift altgr
Arabic_alef 0x23 altgr
Arabic_hamzaonalef 0x23 shift altgr
Arabic_teh 0x24 altgr
Arabic_tatweel 0x24 shift altgr
Arabic_noon 0x25 altgr
Arabic_comma 0x25 shift altgr
Arabic_meem 0x26 altgr
slash 0x26 shift altgr
semicolon 0x27
colon 0x27 shift
Arabic_kaf 0x27 altgr
apostrophe 0x28
quotedbl 0x28 shift
Arabic_tah 0x28 altgr
grave 0x29
asciitilde 0x29 shift
Arabic_thal 0x29 altgr
Arabic_shadda 0x29 shift altgr
backslash 0x2b
bar 0x2b shift
less 0x2b altgr
greater 0x2b shift altgr
Arabic_hamzaonyeh 0x2c altgr
asciitilde 0x2c shift altgr
Arabic_hamza 0x2d altgr
Arabic_sukun 0x2d shift altgr
Arabic_hamzaonwaw 0x2e altgr
Arabic_kasra 0x2e shift altgr
Arabic_ra 0x2f altgr
Arabic_kasratan 0x2f shift altgr
UFEFB 0x30 altgr
UFEF5 0x30 shift altgr
Arabic_alefmaksura 0x31 altgr
Arabic_maddaonalef 0x31 shift altgr
Arabic_tehmarbuta 0x32 altgr
apostrophe 0x32 shift altgr
comma 0x33
less 0x33 shift
Arabic_waw 0x33 altgr
period 0x34
greater 0x34 shift
Arabic_zain 0x34 altgr
slash 0x35
question 0x35 shift
Arabic_zah 0x35 altgr
Arabic_question_mark 0x35 shift altgr
include modifiers
#
# Top row
#
1 0x2
2 0x3
3 0x4
4 0x5
5 0x6
6 0x7
7 0x8
8 0x9
9 0xa
0 0xb
BackSpace 0xe
#
# QWERTY first row
#
Tab 0xf localstate
ISO_Left_Tab 0xf shift
q 0x10 addupper
w 0x11 addupper
e 0x12 addupper
r 0x13 addupper
t 0x14 addupper
y 0x15 addupper
u 0x16 addupper
i 0x17 addupper
o 0x18 addupper
p 0x19 addupper
#
# QWERTY second row
#
a 0x1e addupper
s 0x1f addupper
d 0x20 addupper
f 0x21 addupper
g 0x22 addupper
h 0x23 addupper
j 0x24 addupper
k 0x25 addupper
l 0x26 addupper
Return 0x1c localstate
#
# QWERTY third row
#
z 0x2c addupper
x 0x2d addupper
c 0x2e addupper
v 0x2f addupper
b 0x30 addupper
n 0x31 addupper
m 0x32 addupper
space 0x39 localstate
less 0x56
greater 0x56 shift
bar 0x56 altgr
brokenbar 0x56 shift altgr
#
# Esc and Function keys
#
Escape 0x1 localstate
F1 0x3b localstate
F2 0x3c localstate
F3 0x3d localstate
F4 0x3e localstate
F5 0x3f localstate
F6 0x40 localstate
F7 0x41 localstate
F8 0x42 localstate
F9 0x43 localstate
F10 0x44 localstate
F11 0x57 localstate
F12 0x58 localstate
# Printscreen, Scrollock and Pause
# Printscreen really requires four scancodes (0xe0, 0x2a, 0xe0, 0x37),
# but (0xe0, 0x37) seems to work.
Print 0xb7 localstate
Sys_Req 0xb7 localstate
Execute 0xb7 localstate
Scroll_Lock 0x46
#
# Insert - PgDown
#
Insert 0xd2 localstate
Delete 0xd3 localstate
Home 0xc7 localstate
End 0xcf localstate
Page_Up 0xc9 localstate
Page_Down 0xd1 localstate
#
# Arrow keys
#
Left 0xcb localstate
Up 0xc8 localstate
Down 0xd0 localstate
Right 0xcd localstate
#
# Numpad
#
Num_Lock 0x45
KP_Divide 0xb5
KP_Multiply 0x37
KP_Subtract 0x4a
KP_Add 0x4e
KP_Enter 0x9c
KP_Decimal 0x53 numlock
KP_Separator 0x53 numlock
KP_Delete 0x53
KP_0 0x52 numlock
KP_Insert 0x52
KP_1 0x4f numlock
KP_End 0x4f
KP_2 0x50 numlock
KP_Down 0x50
KP_3 0x51 numlock
KP_Next 0x51
KP_4 0x4b numlock
KP_Left 0x4b
KP_5 0x4c numlock
KP_Begin 0x4c
KP_6 0x4d numlock
KP_Right 0x4d
KP_7 0x47 numlock
KP_Home 0x47
KP_8 0x48 numlock
KP_Up 0x48
KP_9 0x49 numlock
KP_Prior 0x49
Caps_Lock 0x3a
#
# Inhibited keys
#
Multi_key 0x0 inhibit
# generated from XKB map dk
include common
map 0x406
exclam 0x02 shift
exclamdown 0x02 altgr
onesuperior 0x02 shift altgr
quotedbl 0x03 shift
at 0x03 altgr
twosuperior 0x03 shift altgr
numbersign 0x04 shift
sterling 0x04 altgr
threesuperior 0x04 shift altgr
currency 0x05 shift
dollar 0x05 altgr
onequarter 0x05 shift altgr
percent 0x06 shift
onehalf 0x06 altgr
cent 0x06 shift altgr
ampersand 0x07 shift
yen 0x07 altgr
fiveeighths 0x07 shift altgr
slash 0x08 shift
braceleft 0x08 altgr
division 0x08 shift altgr
parenleft 0x09 shift
bracketleft 0x09 altgr
guillemotleft 0x09 shift altgr
parenright 0x0a shift
bracketright 0x0a altgr
guillemotright 0x0a shift altgr
equal 0x0b shift
braceright 0x0b altgr
degree 0x0b shift altgr
plus 0x0c
question 0x0c shift
plusminus 0x0c altgr
questiondown 0x0c shift altgr
dead_acute 0x0d
dead_grave 0x0d shift
bar 0x0d altgr
brokenbar 0x0d shift altgr
Greek_OMEGA 0x10 shift altgr
lstroke 0x11 altgr
Lstroke 0x11 shift altgr
EuroSign 0x12 altgr
cent 0x12 shift altgr
registered 0x13 altgr
thorn 0x14 altgr
THORN 0x14 shift altgr
leftarrow 0x15 altgr
yen 0x15 shift altgr
downarrow 0x16 altgr
uparrow 0x16 shift altgr
rightarrow 0x17 altgr
idotless 0x17 shift altgr
oe 0x18 altgr
OE 0x18 shift altgr
thorn 0x19 altgr
THORN 0x19 shift altgr
aring 0x1a
Aring 0x1a shift
dead_diaeresis 0x1a altgr
dead_abovering 0x1a shift altgr
dead_diaeresis 0x1b
dead_circumflex 0x1b shift
dead_tilde 0x1b altgr
dead_caron 0x1b shift altgr
ordfeminine 0x1e altgr
masculine 0x1e shift altgr
ssharp 0x1f altgr
section 0x1f shift altgr
eth 0x20 altgr
ETH 0x20 shift altgr
dstroke 0x21 altgr
ordfeminine 0x21 shift altgr
eng 0x22 altgr
ENG 0x22 shift altgr
hstroke 0x23 altgr
Hstroke 0x23 shift altgr
kra 0x25 altgr
lstroke 0x26 altgr
Lstroke 0x26 shift altgr
ae 0x27
AE 0x27 shift
oslash 0x28
Ooblique 0x28 shift
dead_caron 0x28 shift altgr
onehalf 0x29
section 0x29 shift
threequarters 0x29 altgr
paragraph 0x29 shift altgr
apostrophe 0x2b
asterisk 0x2b shift
dead_doubleacute 0x2b altgr
multiply 0x2b shift altgr
guillemotleft 0x2c altgr
guillemotright 0x2d altgr
copyright 0x2e altgr
leftdoublequotemark 0x2f altgr
grave 0x2f shift altgr
rightdoublequotemark 0x30 altgr
mu 0x32 altgr
masculine 0x32 shift altgr
comma 0x33
semicolon 0x33 shift
dead_cedilla 0x33 altgr
dead_ogonek 0x33 shift altgr
period 0x34
colon 0x34 shift
periodcentered 0x34 altgr
dead_abovedot 0x34 shift altgr
minus 0x35
underscore 0x35 shift
hyphen 0x35 altgr
macron 0x35 shift altgr
nobreakspace 0x39 altgr
less 0x56
greater 0x56 shift
backslash 0x56 altgr
notsign 0x56 shift altgr
# generated from XKB map de
include common
map 0x407
exclam 0x02 shift
onesuperior 0x02 altgr
exclamdown 0x02 shift altgr
quotedbl 0x03 shift
twosuperior 0x03 altgr
oneeighth 0x03 shift altgr
section 0x04 shift
threesuperior 0x04 altgr
sterling 0x04 shift altgr
dollar 0x05 shift
onequarter 0x05 altgr
currency 0x05 shift altgr
percent 0x06 shift
onehalf 0x06 altgr
threeeighths 0x06 shift altgr
ampersand 0x07 shift
threequarters 0x07 altgr
fiveeighths 0x07 shift altgr
slash 0x08 shift
braceleft 0x08 altgr
seveneighths 0x08 shift altgr
parenleft 0x09 shift
bracketleft 0x09 altgr
trademark 0x09 shift altgr
parenright 0x0a shift
bracketright 0x0a altgr
plusminus 0x0a shift altgr
equal 0x0b shift
braceright 0x0b altgr
ssharp 0x0c
question 0x0c shift
backslash 0x0c altgr
questiondown 0x0c shift altgr
acute 0x0d
dead_acute 0x0d
grave 0x0d shift
dead_grave 0x0d shift
dead_cedilla 0x0d altgr
dead_ogonek 0x0d shift altgr
at 0x10 altgr
Greek_OMEGA 0x10 shift altgr
EuroSign 0x12 altgr
paragraph 0x13 altgr
registered 0x13 shift altgr
tslash 0x14 altgr
Tslash 0x14 shift altgr
z 0x15 addupper
leftarrow 0x15 altgr
yen 0x15 shift altgr
downarrow 0x16 altgr
uparrow 0x16 shift altgr
rightarrow 0x17 altgr
idotless 0x17 shift altgr
oslash 0x18 altgr
Ooblique 0x18 shift altgr
thorn 0x19 altgr
THORN 0x19 shift altgr
udiaeresis 0x1a
Udiaeresis 0x1a shift
dead_diaeresis 0x1a altgr
dead_abovering 0x1a shift altgr
plus 0x1b
asterisk 0x1b shift
asciitilde 0x1b altgr
dead_tilde 0x1b altgr
dead_macron 0x1b shift altgr
ae 0x1e altgr
AE 0x1e shift altgr
eth 0x20 altgr
ETH 0x20 shift altgr
dstroke 0x21 altgr
ordfeminine 0x21 shift altgr
eng 0x22 altgr
ENG 0x22 shift altgr
hstroke 0x23 altgr
Hstroke 0x23 shift altgr
kra 0x25 altgr
odiaeresis 0x27
Odiaeresis 0x27 shift
dead_doubleacute 0x27 altgr
adiaeresis 0x28
Adiaeresis 0x28 shift
dead_caron 0x28 shift altgr
asciicircum 0x29
dead_circumflex 0x29
degree 0x29 shift
notsign 0x29 altgr
numbersign 0x2b
apostrophe 0x2b shift
dead_breve 0x2b shift altgr
y 0x2c addupper
guillemotleft 0x2c altgr
guillemotright 0x2d altgr
cent 0x2e altgr