updated on Thu Jan 19 16:10:29 UTC 2012
[aur-mirror.git] / kvm-opensuse / kvm-fix-with-evdev.patch
blobd7c8e51d31ffbfc78eb2a8724f2cab4c63ca2887
1 f# This code was ported from gtk-vnc, to handle evdev keycode mapping by
2 # Dustin Kirkland <kirkland@canonical.com>, 24 September 2008.
3 # With improvements by Ryan Niebur <ryanryan52@gmail.com> to only
4 # check for evdev once instead of on every keypress.
6 diff -ur kvm-72+dfsg/qemu/configure kvm-72+dfsg/qemu/configure
7 --- kvm-72+dfsg/qemu/configure 2008-12-15 04:13:23.000000000 -0800
8 +++ kvm-72+dfsg/qemu/configure 2009-01-12 20:58:33.000000000 -0800
9 @@ -1463,9 +1463,9 @@
10 echo "#define CONFIG_SDL 1" >> $config_h
11 echo "CONFIG_SDL=yes" >> $config_mak
12 if test "$target_softmmu" = "no" -o "$static" = "yes"; then
13 - echo "SDL_LIBS=$sdl_static_libs" >> $config_mak
14 + echo "SDL_LIBS=-lX11 $sdl_static_libs" >> $config_mak
15 else
16 - echo "SDL_LIBS=`$sdl_config --libs`" >> $config_mak
17 + echo "SDL_LIBS=-lX11 `$sdl_config --libs`" >> $config_mak
19 if [ "${aa}" = "yes" ] ; then
20 echo "SDL_CFLAGS=`$sdl_config --cflags` `aalib-config --cflags`" >> $config_mak
21 diff -ur kvm-72+dfsg/qemu/console.h kvm-72+dfsg/qemu/console.h
22 --- kvm-72+dfsg/qemu/console.h 2008-12-14 05:16:27.000000000 -0800
23 +++ kvm-72+dfsg/qemu/console.h 2009-01-12 21:17:20.000000000 -0800
24 @@ -1,6 +1,8 @@
25 #ifndef CONSOLE_H
26 #define CONSOLE_H
28 +#include <stdbool.h>
30 #include "qemu-char.h"
32 /* keyboard/mouse support */
33 @@ -186,7 +188,8 @@
34 void curses_display_init(DisplayState *ds, int full_screen);
36 /* x_keymap.c */
37 -extern uint8_t _translate_keycode(const int key);
38 +extern uint8_t _translate_keycode(const int key, bool has_evdev);
39 +extern bool _check_for_evdev(void);
41 /* FIXME: term_printf et al should probably go elsewhere so everything
42 does not need to include console.h */
43 diff -ur kvm-72+dfsg/qemu/sdl.c kvm-72+dfsg/qemu/sdl.c
44 --- kvm-72+dfsg/qemu/sdl.c 2008-12-14 05:16:27.000000000 -0800
45 +++ kvm-72+dfsg/qemu/sdl.c 2009-01-12 21:12:00.000000000 -0800
46 @@ -50,6 +50,8 @@
47 static int guest_x, guest_y;
48 static SDL_Cursor *guest_sprite = 0;
50 +static bool has_evdev;
52 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
54 // printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
55 @@ -143,21 +145,7 @@
57 static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
59 - int keycode;
61 - keycode = ev->keysym.scancode;
63 - if (keycode < 9) {
64 - keycode = 0;
65 - } else if (keycode < 97) {
66 - keycode -= 8; /* just an offset */
67 - } else if (keycode < 212) {
68 - /* use conversion table */
69 - keycode = _translate_keycode(keycode - 97);
70 - } else {
71 - keycode = 0;
72 - }
73 - return keycode;
74 + return _translate_keycode(ev->keysym.scancode, has_evdev);
77 #endif
78 @@ -658,4 +646,6 @@
79 gui_fullscreen_initial_grab = 1;
80 sdl_grab_start();
83 + has_evdev = _check_for_evdev();
85 diff -ur kvm-72+dfsg/qemu/x_keymap.c kvm-72+dfsg/qemu/x_keymap.c
86 --- kvm-72+dfsg/qemu/x_keymap.c 2008-12-14 05:16:27.000000000 -0800
87 +++ kvm-72+dfsg/qemu/x_keymap.c 2009-01-12 21:18:37.000000000 -0800
88 @@ -24,7 +24,14 @@
89 #include "qemu-common.h"
90 #include "console.h"
92 -static const uint8_t x_keycode_to_pc_keycode[115] = {
93 +#include <SDL/SDL_syswm.h>
94 +#include <X11/XKBlib.h>
95 +#include <string.h>
97 +#define TRUE 1
98 +#define FALSE 0
100 +static const uint8_t x_keycode_to_pc_keycode[61] = {
101 0xc7, /* 97 Home */
102 0xc8, /* 98 Up */
103 0xc9, /* 99 PgUp */
104 @@ -86,27 +93,136 @@
105 0x51, /* 155 KP_PgDn */
106 0x52, /* 156 KP_Ins */
107 0x53, /* 157 KP_Del */
108 - 0x0, /* 158 */
109 - 0x0, /* 159 */
110 - 0x0, /* 160 */
111 - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 170 */
112 - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 180 */
113 - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 190 */
114 - 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* 200 */
115 - 0x0, /* 201 */
116 - 0x0, /* 202 */
117 - 0x0, /* 203 */
118 - 0x0, /* 204 */
119 - 0x0, /* 205 */
120 - 0x0, /* 206 */
121 - 0x0, /* 207 */
122 - 0x70, /* 208 Hiragana_Katakana */
123 - 0x0, /* 209 */
124 - 0x0, /* 210 */
125 - 0x73, /* 211 backslash */
128 -uint8_t _translate_keycode(const int key)
129 +/* This code was ported from gtk-vnc, to handle evdev keycode mapping by
130 + * Dustin Kirkland <kirkland@canonical.com>, 24 September 2008.
132 + * This table was put together by VirtualBox. It's based on the information in
133 + * /usr/share/X11/xkb/keycodes/evdev using the x_keycode_to_pc_keycode table
134 + * to get the pc keycodes.
135 + */
137 +static const uint8_t evdev_keycode_to_pc_keycode[61] = {
138 + 0x0, /* 97 EVDEV - RO ("Internet" Keyboards) */
139 + 0x0, /* 98 EVDEV - KATA (Katakana) */
140 + 0x0, /* 99 EVDEV - HIRA (Hiragana) */
141 + 0x79, /* 100 EVDEV - HENK (Henkan) */
142 + 0x70, /* 101 EVDEV - HKTG (Hiragana/Katakana toggle) */
143 + 0x7b, /* 102 EVDEV - MUHE (Muhenkan) */
144 + 0x0, /* 103 EVDEV - JPCM (KPJPComma) */
145 + 0x9c, /* 104 EVDEV - KPEN */
146 + 0x9d, /* 105 EVDEV - RCTL */
147 + 0xb5, /* 106 EVDEV - KPDV */
148 + 0xb7, /* 107 EVDEV - PRSC ***FIXME*** */
149 + 0xb8, /* 108 EVDEV - RALT */
150 + 0x0, /* 109 EVDEV - LNFD ("Internet" Keyboards) */
151 + 0xc7, /* 110 EVDEV - HOME ***FIXME*** */
152 + 0xc8, /* 111 EVDEV - UP */
153 + 0xc9, /* 112 EVDEV - PGUP */
154 + 0xcb, /* 113 EVDEV - LEFT */
155 + 0xcd, /* 114 EVDEV - RGHT */
156 + 0xcf, /* 115 EVDEV - END */
157 + 0xd0, /* 116 EVDEV - DOWN */
158 + 0xd1, /* 117 EVDEV - PGDN */
159 + 0xd2, /* 118 EVDEV - INS */
160 + 0xd3, /* 119 EVDEV - DELE */
161 + 0x0, /* 120 EVDEV - I120 ("Internet" Keyboards) */
162 + 0x0, /* 121 EVDEV - MUTE */
163 + 0x0, /* 122 EVDEV - VOL- */
164 + 0x0, /* 123 EVDEV - VOL+ */
165 + 0x0, /* 124 EVDEV - POWR */
166 + 0x0, /* 125 EVDEV - KPEQ */
167 + 0x0, /* 126 EVDEV - I126 ("Internet" Keyboards) */
168 + 0x0, /* 127 EVDEV - PAUS */
169 + 0x0, /* 128 EVDEV - ???? */
170 + 0x0, /* 129 EVDEV - I129 ("Internet" Keyboards) */
171 + 0xf1, /* 130 EVDEV - HNGL (Korean Hangul Latin toggle) */
172 + 0xf2, /* 131 EVDEV - HJCV (Korean Hangul Hanja toggle) */
173 + 0x7d, /* 132 EVDEV - AE13 (Yen) */
174 + 0xdb, /* 133 EVDEV - LWIN */
175 + 0xdc, /* 134 EVDEV - RWIN */
176 + 0xdd, /* 135 EVDEV - MENU */
177 + 0x0, /* 136 EVDEV - STOP */
178 + 0x0, /* 137 EVDEV - AGAI */
179 + 0x0, /* 138 EVDEV - PROP */
180 + 0x0, /* 139 EVDEV - UNDO */
181 + 0x0, /* 140 EVDEV - FRNT */
182 + 0x0, /* 141 EVDEV - COPY */
183 + 0x0, /* 142 EVDEV - OPEN */
184 + 0x0, /* 143 EVDEV - PAST */
185 + 0x0, /* 144 EVDEV - FIND */
186 + 0x0, /* 145 EVDEV - CUT */
187 + 0x0, /* 146 EVDEV - HELP */
188 + 0x0, /* 147 EVDEV - I147 */
189 + 0x0, /* 148 EVDEV - I148 */
190 + 0x0, /* 149 EVDEV - I149 */
191 + 0x0, /* 150 EVDEV - I150 */
192 + 0x0, /* 151 EVDEV - I151 */
193 + 0x0, /* 152 EVDEV - I152 */
194 + 0x0, /* 153 EVDEV - I153 */
195 + 0x0, /* 154 EVDEV - I154 */
196 + 0x0, /* 155 EVDEV - I156 */
197 + 0x0, /* 156 EVDEV - I157 */
198 + 0x0, /* 157 EVDEV - I158 */
201 +static bool strstarts(const char *lhs, const char *rhs)
203 + if (strlen(lhs) < strlen(rhs))
204 + return false;
205 + return memcmp(lhs, rhs, strlen(rhs)) == 0;
208 +bool _check_for_evdev(void)
210 + SDL_SysWMinfo info;
211 + XkbDescPtr desc = NULL;
212 + bool has_evdev = FALSE;
213 + const char *keycodes;
215 + SDL_VERSION(&info.version);
216 + if (!SDL_GetWMInfo(&info))
217 + goto out;
219 + desc = XkbGetKeyboard (info.info.x11.display,
220 + XkbAllComponentsMask,
221 + XkbUseCoreKbd);
222 + if (!desc)
223 + goto out;
225 + keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes);
226 + if (keycodes == NULL)
227 + fprintf(stderr, "qemu: warning: could not lookup keycode name\n");
228 + else if (strstarts(keycodes, "evdev_"))
229 + has_evdev = TRUE;
230 + else if (!strstarts(keycodes, "xfree86_"))
231 + fprintf(stderr, "qemu: warning: unknown keycodes `%s'\n", keycodes);
233 + XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
235 +out:
236 + return has_evdev;
240 +uint8_t _translate_keycode(int keycode, bool has_evdev)
242 - return x_keycode_to_pc_keycode[key];
243 + if (keycode < 9)
244 + keycode = 0;
245 + else if (keycode < 97)
246 + keycode -= 8; /* just an offset */
247 + else if (keycode < 158) {
248 + if (has_evdev)
249 + keycode = evdev_keycode_to_pc_keycode[keycode - 97];
250 + else
251 + keycode = x_keycode_to_pc_keycode[keycode - 97];
252 + } else if (keycode == 208) /* Hiragana_Katakana */
253 + keycode = 0x70;
254 + else if (keycode == 211) /* backslash */
255 + keycode = 0x73;
256 + else
257 + keycode = 0;
259 + return keycode;