Commit e58d12ed5b22ca78b46cc4e36392f4e763008eb9
1 parent
d549f7d9
Darwin patch
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@982 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
146 additions
and
16 deletions
sdl.c
| ... | ... | @@ -29,6 +29,10 @@ |
| 29 | 29 | #include <signal.h> |
| 30 | 30 | #endif |
| 31 | 31 | |
| 32 | +#if defined(__APPLE__) | |
| 33 | +#define CONFIG_SDL_GENERIC_KBD | |
| 34 | +#endif | |
| 35 | + | |
| 32 | 36 | static SDL_Surface *screen; |
| 33 | 37 | static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ |
| 34 | 38 | static int last_vm_running; |
| ... | ... | @@ -63,6 +67,126 @@ static void sdl_resize(DisplayState *ds, int w, int h) |
| 63 | 67 | ds->depth = screen->format->BitsPerPixel; |
| 64 | 68 | } |
| 65 | 69 | |
| 70 | +#ifdef CONFIG_SDL_GENERIC_KBD | |
| 71 | + | |
| 72 | +/* XXX: use keymap tables defined in the VNC patch because the | |
| 73 | + following code suppose you have a US keyboard. */ | |
| 74 | + | |
| 75 | +static const uint8_t scancodes[SDLK_LAST] = { | |
| 76 | + [SDLK_ESCAPE] = 0x01, | |
| 77 | + [SDLK_1] = 0x02, | |
| 78 | + [SDLK_2] = 0x03, | |
| 79 | + [SDLK_3] = 0x04, | |
| 80 | + [SDLK_4] = 0x05, | |
| 81 | + [SDLK_5] = 0x06, | |
| 82 | + [SDLK_6] = 0x07, | |
| 83 | + [SDLK_7] = 0x08, | |
| 84 | + [SDLK_8] = 0x09, | |
| 85 | + [SDLK_9] = 0x0a, | |
| 86 | + [SDLK_0] = 0x0b, | |
| 87 | + [SDLK_MINUS] = 0x0c, | |
| 88 | + [SDLK_EQUALS] = 0x0d, | |
| 89 | + [SDLK_BACKSPACE] = 0x0e, | |
| 90 | + [SDLK_TAB] = 0x0f, | |
| 91 | + [SDLK_q] = 0x10, | |
| 92 | + [SDLK_w] = 0x11, | |
| 93 | + [SDLK_e] = 0x12, | |
| 94 | + [SDLK_r] = 0x13, | |
| 95 | + [SDLK_t] = 0x14, | |
| 96 | + [SDLK_y] = 0x15, | |
| 97 | + [SDLK_u] = 0x16, | |
| 98 | + [SDLK_i] = 0x17, | |
| 99 | + [SDLK_o] = 0x18, | |
| 100 | + [SDLK_p] = 0x19, | |
| 101 | + [SDLK_LEFTBRACKET] = 0x1a, | |
| 102 | + [SDLK_RIGHTBRACKET] = 0x1b, | |
| 103 | + [SDLK_RETURN] = 0x1c, | |
| 104 | + [SDLK_LCTRL] = 0x1d, | |
| 105 | + [SDLK_a] = 0x1e, | |
| 106 | + [SDLK_s] = 0x1f, | |
| 107 | + [SDLK_d] = 0x20, | |
| 108 | + [SDLK_f] = 0x21, | |
| 109 | + [SDLK_g] = 0x22, | |
| 110 | + [SDLK_h] = 0x23, | |
| 111 | + [SDLK_j] = 0x24, | |
| 112 | + [SDLK_k] = 0x25, | |
| 113 | + [SDLK_l] = 0x26, | |
| 114 | + [SDLK_SEMICOLON] = 0x27, | |
| 115 | + [SDLK_QUOTE] = 0x28, | |
| 116 | + [SDLK_BACKQUOTE] = 0x29, | |
| 117 | + [SDLK_LSHIFT] = 0x2a, | |
| 118 | + [SDLK_BACKSLASH] = 0x2b, | |
| 119 | + [SDLK_z] = 0x2c, | |
| 120 | + [SDLK_x] = 0x2d, | |
| 121 | + [SDLK_c] = 0x2e, | |
| 122 | + [SDLK_v] = 0x2f, | |
| 123 | + [SDLK_b] = 0x30, | |
| 124 | + [SDLK_n] = 0x31, | |
| 125 | + [SDLK_m] = 0x32, | |
| 126 | + [SDLK_COMMA] = 0x33, | |
| 127 | + [SDLK_PERIOD] = 0x34, | |
| 128 | + [SDLK_SLASH] = 0x35, | |
| 129 | + [SDLK_KP_MULTIPLY] = 0x37, | |
| 130 | + [SDLK_LALT] = 0x38, | |
| 131 | + [SDLK_SPACE] = 0x39, | |
| 132 | + [SDLK_CAPSLOCK] = 0x3a, | |
| 133 | + [SDLK_F1] = 0x3b, | |
| 134 | + [SDLK_F2] = 0x3c, | |
| 135 | + [SDLK_F3] = 0x3d, | |
| 136 | + [SDLK_F4] = 0x3e, | |
| 137 | + [SDLK_F5] = 0x3f, | |
| 138 | + [SDLK_F6] = 0x40, | |
| 139 | + [SDLK_F7] = 0x41, | |
| 140 | + [SDLK_F8] = 0x42, | |
| 141 | + [SDLK_F9] = 0x43, | |
| 142 | + [SDLK_F10] = 0x44, | |
| 143 | + [SDLK_NUMLOCK] = 0x45, | |
| 144 | + [SDLK_SCROLLOCK] = 0x46, | |
| 145 | + [SDLK_KP7] = 0x47, | |
| 146 | + [SDLK_KP8] = 0x48, | |
| 147 | + [SDLK_KP9] = 0x49, | |
| 148 | + [SDLK_KP_MINUS] = 0x4a, | |
| 149 | + [SDLK_KP4] = 0x4b, | |
| 150 | + [SDLK_KP5] = 0x4c, | |
| 151 | + [SDLK_KP6] = 0x4d, | |
| 152 | + [SDLK_KP_PLUS] = 0x4e, | |
| 153 | + [SDLK_KP1] = 0x4f, | |
| 154 | + [SDLK_KP2] = 0x50, | |
| 155 | + [SDLK_KP3] = 0x51, | |
| 156 | + [SDLK_KP0] = 0x52, | |
| 157 | + [SDLK_KP_PERIOD] = 0x53, | |
| 158 | + [SDLK_PRINT] = 0x54, | |
| 159 | + [SDLK_LMETA] = 0x56, | |
| 160 | + | |
| 161 | + [SDLK_KP_ENTER] = 0x9c, | |
| 162 | + [SDLK_KP_DIVIDE] = 0xb5, | |
| 163 | + | |
| 164 | + [SDLK_UP] = 0xc8, | |
| 165 | + [SDLK_DOWN] = 0xd0, | |
| 166 | + [SDLK_RIGHT] = 0xcd, | |
| 167 | + [SDLK_LEFT] = 0xcb, | |
| 168 | + [SDLK_INSERT] = 0xd2, | |
| 169 | + [SDLK_HOME] = 0xc7, | |
| 170 | + [SDLK_END] = 0xcf, | |
| 171 | + [SDLK_PAGEUP] = 0xc9, | |
| 172 | + [SDLK_PAGEDOWN] = 0xd1, | |
| 173 | + [SDLK_DELETE] = 0xd3, | |
| 174 | +}; | |
| 175 | + | |
| 176 | +static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) | |
| 177 | +{ | |
| 178 | + return scancodes[ev->keysym.sym]; | |
| 179 | +} | |
| 180 | + | |
| 181 | +#elif defined(_WIN32) | |
| 182 | + | |
| 183 | +static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) | |
| 184 | +{ | |
| 185 | + return ev->keysym.scancode; | |
| 186 | +} | |
| 187 | + | |
| 188 | +#else | |
| 189 | + | |
| 66 | 190 | static const uint8_t x_keycode_to_pc_keycode[61] = { |
| 67 | 191 | 0xc7, /* 97 Home */ |
| 68 | 192 | 0xc8, /* 98 Up */ |
| ... | ... | @@ -127,6 +251,27 @@ static const uint8_t x_keycode_to_pc_keycode[61] = { |
| 127 | 251 | 0x53, /* 157 KP_Del */ |
| 128 | 252 | }; |
| 129 | 253 | |
| 254 | +static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) | |
| 255 | +{ | |
| 256 | + int keycode; | |
| 257 | + | |
| 258 | + keycode = ev->keysym.scancode; | |
| 259 | + | |
| 260 | + if (keycode < 9) { | |
| 261 | + keycode = 0; | |
| 262 | + } else if (keycode < 97) { | |
| 263 | + keycode -= 8; /* just an offset */ | |
| 264 | + } else if (keycode < 158) { | |
| 265 | + /* use conversion table */ | |
| 266 | + keycode = x_keycode_to_pc_keycode[keycode - 97]; | |
| 267 | + } else { | |
| 268 | + keycode = 0; | |
| 269 | + } | |
| 270 | + return keycode; | |
| 271 | +} | |
| 272 | + | |
| 273 | +#endif | |
| 274 | + | |
| 130 | 275 | static void sdl_process_key(SDL_KeyboardEvent *ev) |
| 131 | 276 | { |
| 132 | 277 | int keycode, v, i; |
| ... | ... | @@ -144,22 +289,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev) |
| 144 | 289 | } |
| 145 | 290 | |
| 146 | 291 | /* XXX: not portable, but avoids complicated mappings */ |
| 147 | - keycode = ev->keysym.scancode; | |
| 148 | - | |
| 149 | - /* XXX: windows version may not work: 0xe0/0xe1 should be trapped | |
| 150 | - ? */ | |
| 151 | -#ifndef _WIN32 | |
| 152 | - if (keycode < 9) { | |
| 153 | - keycode = 0; | |
| 154 | - } else if (keycode < 97) { | |
| 155 | - keycode -= 8; /* just an offset */ | |
| 156 | - } else if (keycode < 158) { | |
| 157 | - /* use conversion table */ | |
| 158 | - keycode = x_keycode_to_pc_keycode[keycode - 97]; | |
| 159 | - } else { | |
| 160 | - keycode = 0; | |
| 161 | - } | |
| 162 | -#endif | |
| 292 | + keycode = sdl_keyevent_to_keycode(ev); | |
| 163 | 293 | |
| 164 | 294 | switch(keycode) { |
| 165 | 295 | case 0x00: | ... | ... |