Hello, qemu-devel!

I use QEMU to run virtual machines on a Debian GNU/Linux machine with
AMD64 PC-class hardware.  My X keyboard configuration uses Meta
instead of Alt; even though I have a PC-style keyboard whose keys are
labeled Alt, they are assigned to the Meta keysyms.  I don't believe
this to be unusual.  Unfortunately, it makes it impossible to release
QEMU input grabs, which is likely related to the Debian bug report at
< http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=398351 >.

I've drafted a patch for QEMU's SDL interface to allow the use of
either Alt or Meta.  This appears to work when applied against either
Debianized QEMU 0.9.1 or raw QEMU SVN trunk (r4988) on my machine.
There may be bogosities that I have not noticed, since although it is
a localized change, I have not extensively read the QEMU source code.
This patch is attached in unified diff format, applyable with -p0.

(For those of you reading from the Debian bug, this is slightly
different than my previous posting there, because I noticed that I had
created a few redundant whitespace-changes-only hunks by mistake,
which I have now removed.)

Comments are appreciated from any related source.  Thanks for your
attention.  :-)

   ---> Drake Wilson
--- sdl.c.orig	2008-01-06 13:38:42.000000000 -0600
+++ sdl.c	2008-08-06 08:53:32.000000000 -0500
@@ -40,7 +40,9 @@
 static int gui_key_modifier_pressed;
 static int gui_keysym;
 static int gui_fullscreen_initial_grab;
-static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
+static int gui_grab_mods = KMOD_LALT | KMOD_LCTRL | KMOD_LMETA;
+static int gui_grab_req_all = KMOD_LCTRL; /* possibly modified on init */
+static int gui_grab_req_any = KMOD_LALT | KMOD_LMETA;
 static uint8_t modifiers_state[256];
 static int width, height;
 static SDL_Cursor *sdl_cursor_normal;
@@ -363,13 +365,10 @@
         case SDL_KEYDOWN:
         case SDL_KEYUP:
             if (ev->type == SDL_KEYDOWN) {
-                if (!alt_grab) {
-                    mod_state = (SDL_GetModState() & gui_grab_code) ==
-                                gui_grab_code;
-                } else {
-                    mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
-                                (gui_grab_code | KMOD_LSHIFT);
-                }
+                SDLMod sdl_mod_state = SDL_GetModState();
+                mod_state = (((sdl_mod_state & gui_grab_req_all) ==
+                              gui_grab_req_all) &&
+                             ((sdl_mod_state & gui_grab_req_any) != 0));
                 gui_key_modifier_pressed = mod_state;
                 if (gui_key_modifier_pressed) {
                     int keycode;
@@ -430,12 +429,7 @@
                     }
                 }
             } else if (ev->type == SDL_KEYUP) {
-                if (!alt_grab) {
-                    mod_state = (ev->key.keysym.mod & gui_grab_code);
-                } else {
-                    mod_state = (ev->key.keysym.mod &
-                                 (gui_grab_code | KMOD_LSHIFT));
-                }
+                mod_state = (ev->key.keysym.mod & gui_grab_mods);
                 if (!mod_state) {
                     if (gui_key_modifier_pressed) {
                         gui_key_modifier_pressed = 0;
@@ -630,6 +624,9 @@
     SDL_EnableUNICODE(1);
     gui_grab = 0;
 
+    if (alt_grab)
+        gui_grab_req_all |= KMOD_LSHIFT;
+
     sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
     sdl_cursor_normal = SDL_GetCursor();
 

Reply via email to