[Spice-commits] 2 commits - client/inputs_channel.cpp client/x11

Christophe Fergau teuf at kemper.freedesktop.org
Wed Aug 17 01:44:02 PDT 2011


 client/inputs_channel.cpp |    2 +-
 client/x11/platform.cpp   |   25 ++-----------------------
 2 files changed, 3 insertions(+), 24 deletions(-)

New commits:
commit 3d31e36bf2db0c42b21e8e27b5b6f3aea9ea4181
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Aug 16 11:26:54 2011 +0200

    use Xkb to get keyboard modifier mask
    
    To be able to enable/disable keyboard leds on X11, we need to query
    the X server for which mask correspond to which led (NumLock,
    CapsLock). So far this was done using XKeysymToKeycode and iterating
    over X modifier mapping.
    Xkb provides XkbKeysymToModifiers for this purpose, and since
    we're using Xkb anyway, it makes more sense to use it.
    
    At some point, on my Fedora 15 box, XKeysymToKeycode was returning
    NoSymbol for CapsLock and NumLock leading to spicec not being able
    to change the keyboard leds when qemu tells it to. However, I couldn't
    reproduce this when I tried again :-/

diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index 09ca61d..f3fb444 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -2953,27 +2953,6 @@ static void init_xfixes()
         XFixesQueryVersion(x_display, &major, &minor) && major >= 1;
 }
 
-static unsigned int get_modifier_mask(KeySym modifier)
-{
-    int mask = 0;
-    int i;
-
-    XModifierKeymap* map = XGetModifierMapping(x_display);
-    KeyCode keycode = XKeysymToKeycode(x_display, modifier);
-    if (keycode == NoSymbol) {
-        XFreeModifiermap(map);
-        return 0;
-    }
-
-    for (i = 0; i < 8; i++) {
-        if (map->modifiermap[map->max_keypermod * i] == keycode) {
-            mask = 1 << i;
-        }
-    }
-    XFreeModifiermap(map);
-    return mask;
-}
-
 static void init_kbd()
 {
     int xkb_major = XkbMajorVersion;
@@ -2986,8 +2965,8 @@ static void init_kbd()
         !XkbQueryExtension(x_display, &opcode, &event, &error, &xkb_major, &xkb_minor)) {
         return;
     }
-    caps_lock_mask = get_modifier_mask(XK_Caps_Lock);
-    num_lock_mask = get_modifier_mask(XK_Num_Lock);
+    caps_lock_mask = XkbKeysymToModifiers(x_display, XK_Caps_Lock);
+    num_lock_mask = XkbKeysymToModifiers(x_display, XK_Num_Lock);
 }
 
 static void init_XIM()
commit f2b4c3d21aed0018dc7014542f76b64e6aa57ce6
Author: Christophe Fergeau <cfergeau at redhat.com>
Date:   Tue Aug 16 11:14:44 2011 +0200

    fix harmless typo in InputsChannel::handle_modifiers
    
    InputsChannel::handle_modifiers converts _modifiers which is a
    bitflag of SPICE_KEYBOARD_MODIFIER_FLAGS_* to a Platform::*_MODIFIER
    bitflag, which is what Platform::set_keyboard_lock_modifiers expects.
    However, it's called with _modifiers, and the bitflag that this
    function computes is never used. Pass the computed bitflag to
    ::set_keyboard_lock_modifiers since _modifiers format is meaningless
    for ::set_keyboard_lock_modifiers.
    This bug was harmless because the two different set of modifier
    flags actually use the same values, so _modifiers and modifiers could
    be used interchangeably. However it's more future-proof to use the
    right format here.

diff --git a/client/inputs_channel.cpp b/client/inputs_channel.cpp
index 4d1232a..9e940d9 100644
--- a/client/inputs_channel.cpp
+++ b/client/inputs_channel.cpp
@@ -402,7 +402,7 @@ void InputsChannel::set_local_modifiers()
         modifiers |= Platform::CAPS_LOCK_MODIFIER;
     }
 
-    Platform::set_keyboard_lock_modifiers(_modifiers);
+    Platform::set_keyboard_lock_modifiers(modifiers);
 }
 
 void InputsChannel::on_focus_in()


More information about the Spice-commits mailing list