Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Cg4Rf-0000wj-Nj for qemu-devel@nongnu.org; Sun, 19 Dec 2004 12:02:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Cg4Rc-0000ve-BX for qemu-devel@nongnu.org; Sun, 19 Dec 2004 12:02:09 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Cg4Ra-0000vL-Tp for qemu-devel@nongnu.org; Sun, 19 Dec 2004 12:02:07 -0500 Received: from [130.83.48.97] (helo=baerbel.mug.maschinenbau.tu-darmstadt.de) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1Cg3rk-0000an-Nv for qemu-devel@nongnu.org; Sun, 19 Dec 2004 11:25:05 -0500 Received: from baerbel.mug.maschinenbau.tu-darmstadt.de (localhost [127.0.0.1]) by baerbel.mug.maschinenbau.tu-darmstadt.de (8.13.1/8.13.1) with ESMTP id iBJGOkX6018896 for ; Sun, 19 Dec 2004 17:24:46 +0100 Received: (from tacke@localhost) by baerbel.mug.maschinenbau.tu-darmstadt.de (8.13.1/8.13.1/Submit) id iBJGOjgl018894 for qemu-devel@nongnu.org; Sun, 19 Dec 2004 17:24:45 +0100 Date: Sun, 19 Dec 2004 17:24:45 +0100 From: Elrond Message-ID: <20041219162445.GA18823@memak.tu-darmstadt.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OXfL5xGRrasGEqWY" Content-Disposition: inline Subject: [Qemu-devel] [Patch] selectable keyboard mapping function Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, After having some bug reports about scrambled keyboards in Debian, we decided to make the keyboard mapping function choosable. It helps most people at least somewhat. Here are two bugreports for example problems: Patch attached. Elrond p.s.: I'm not on the list, so please include me in replies. --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="02_selectable_sdl_keyboard.patch" #DPATCHLEVEL=1 diff -ur qemu-0.6.1/sdl.c qemu/sdl.c --- qemu-0.6.1/sdl.c 2004-11-14 21:51:33.000000000 +0100 +++ qemu/sdl.c 2004-11-27 20:37:14.000000000 +0100 @@ -72,7 +72,6 @@ ds->height = h; } -#ifdef CONFIG_SDL_GENERIC_KBD /* XXX: use keymap tables defined in the VNC patch because the following code suppose you have a US keyboard. */ @@ -131,6 +130,7 @@ [SDLK_COMMA] = 0x33, [SDLK_PERIOD] = 0x34, [SDLK_SLASH] = 0x35, + [SDLK_RSHIFT] = 0x36, [SDLK_KP_MULTIPLY] = 0x37, [SDLK_LALT] = 0x38, [SDLK_SPACE] = 0x39, @@ -178,20 +178,16 @@ [SDLK_DELETE] = 0xd3, }; -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) +static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev) { return scancodes[ev->keysym.sym]; } -#elif defined(_WIN32) - -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) +static uint8_t sdl_keyevent_to_keycode_direct(const SDL_KeyboardEvent *ev) { return ev->keysym.scancode; } -#else - static const uint8_t x_keycode_to_pc_keycode[61] = { 0xc7, /* 97 Home */ 0xc8, /* 98 Up */ @@ -256,7 +252,7 @@ 0x53, /* 157 KP_Del */ }; -static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev) +static uint8_t sdl_keyevent_to_keycode_xf86(const SDL_KeyboardEvent *ev) { int keycode; @@ -275,8 +271,30 @@ return keycode; } +#ifdef CONFIG_SDL_GENERIC_KBD +#define DEFAULT_KEYEVENT_TO_KEYCODE sdl_keyevent_to_keycode_generic +#elif defined(_WIN32) +#define DEFAULT_KEYEVENT_TO_KEYCODE sdl_keyevent_to_keycode_direct +#else +#define DEFAULT_KEYEVENT_TO_KEYCODE sdl_keyevent_to_keycode_xf86 #endif +static uint8_t (* sdl_keyevent_to_keycode) (const SDL_KeyboardEvent *ev) = DEFAULT_KEYEVENT_TO_KEYCODE; + +void qemu_keyboard_set_sdl_method(const char *method) +{ + if (strcmp(method, "generic")==0) + sdl_keyevent_to_keycode = sdl_keyevent_to_keycode_generic; + else if (strcmp(method, "direct")==0) + sdl_keyevent_to_keycode = sdl_keyevent_to_keycode_direct; + else if (strcmp(method, "xf86")==0) + sdl_keyevent_to_keycode = sdl_keyevent_to_keycode_xf86; + else + fprintf(stderr, "Unknown keyboard method `%s', ignoring\n", + method); +} + + static void reset_keys(void) { int i; diff -ur qemu-0.6.1/vl.c qemu/vl.c --- qemu-0.6.1/vl.c 2004-11-14 21:51:33.000000000 +0100 +++ qemu/vl.c 2004-11-27 20:41:14.000000000 +0100 @@ -2502,6 +2502,8 @@ "-m megs set virtual RAM size to megs MB [default=%d]\n" "-nographic disable graphical output and redirect serial I/Os to console\n" "-enable-audio enable audio support\n" + "-keyboard {generic|direct|xf86}\n" + " Select keyboard mapping method [default=xf86]\n" "-localtime set the real time clock to local time [default=utc]\n" "-full-screen start in full screen\n" #ifdef TARGET_PPC @@ -2591,6 +2593,7 @@ QEMU_OPTION_m, QEMU_OPTION_nographic, QEMU_OPTION_enable_audio, + QEMU_OPTION_keyboard, QEMU_OPTION_nics, QEMU_OPTION_macaddr, @@ -2647,6 +2650,9 @@ { "m", HAS_ARG, QEMU_OPTION_m }, { "nographic", 0, QEMU_OPTION_nographic }, { "enable-audio", 0, QEMU_OPTION_enable_audio }, +#ifdef CONFIG_SDL + { "keyboard", HAS_ARG, QEMU_OPTION_keyboard }, +#endif { "nics", HAS_ARG, QEMU_OPTION_nics}, { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, @@ -2975,6 +2981,11 @@ case QEMU_OPTION_enable_audio: audio_enabled = 1; break; +#ifdef CONFIG_SDL + case QEMU_OPTION_keyboard: + qemu_keyboard_set_sdl_method(optarg); + break; +#endif case QEMU_OPTION_h: help(); break; diff -ur qemu-0.6.1/vl.h qemu/vl.h --- qemu-0.6.1/vl.h 2004-11-14 21:51:33.000000000 +0100 +++ qemu/vl.h 2004-11-27 15:55:53.000000000 +0100 @@ -545,6 +545,7 @@ /* sdl.c */ void sdl_display_init(DisplayState *ds, int full_screen); +void qemu_keyboard_set_sdl_method(const char *method); /* ide.c */ #define MAX_DISKS 4 --- qemu-0.6.1/qemu-doc.texi~ 2004-12-18 21:19:02.000000000 +0100 +++ qemu-0.6.1/qemu-doc.texi 2004-12-18 21:19:02.000000000 +0100 @@ -194,6 +194,21 @@ The SB16 emulation is disabled by default as it may give problems with Windows. You can enable it manually with this option. +@item -keyboard {generic|direct|xf86} +Choose a mapping function for the keyboard: +@table @code +@item xf86 +An i386 XFree86 based one +(default on most Unix builds) +@item generic +an SDL based mapping function, fixes some "scrambled keyboards" +problems, but has its own issues +(default for alpha) +@item direct +Uses the scancodes as acquired from the underlying OS. +(default on Win32) +@end table + @item -localtime Set the real time clock to local time (the default is to UTC time). This option is needed to have correct date in MS-DOS or --OXfL5xGRrasGEqWY--