Skip to contentSkip to conversation

selectable keyboard mapping function

PATCH In review Elrond 2 participants 4 messages Dec 19, 2004

lore
Share & tools
lore

Elrond

author
#0 lore raw

PATCH 1/1 selectable keyboard mapping function

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:

	<http://bugs.debian.org/282658>
	<http://bugs.debian.org/284510>

Patch attached.

Elrond

p.s.: I'm not on the list, so please include me in replies.

#DPATCHLEVEL=1

sdl.c +26 -8
diff -ur qemu-0.6.1/sdl.c qemu/sdl.c
@@ -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;
vl.c +11 -0
diff -ur qemu-0.6.1/vl.c qemu/vl.c
@@ -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;
vl.h +1 -0
diff -ur qemu-0.6.1/vl.h qemu/vl.h
@@ -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-doc.texi renamed from qemu-doc.texi~ +15 -0
@@ -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
#1 lore raw

Hi,

Fabrice committed a new keyboard mapping scheme which you can activate by using "-k <lang>" where <lang> is something like de, fr, en, etc. Could you please try that and tell us if it solves your problems?

Ciao,
Dscho

author
#2 lore raw
Quoted 5 lines · Johannes Schindelin

Hi,

Fabrice committed a new keyboard mapping scheme which you can activate by using "-k <lang>" where <lang> is something like de, fr, en, etc. Could you please try that and tell us if it solves your problems?

I can't try it myself, as I don't have those problems. You could ask the submitters of those bugs.

I haven't looked at cvs yet, but doing "de"-schemes sounds a bit weird, unless it's used to decode back from cooked keys to scancodes..

Elrond

#3 lore raw

Hi,

Quoted 3 lines · Elrond

I haven't looked at cvs yet, but doing "de"-schemes sounds a bit weird, unless it's used to decode back from cooked keys to scancodes..

Well, it's not that weird, once you realize that X11 is standardized on keysyms, but PC hardware on scancodes.

Hth,
Dscho