[clutter] x11: Ignore num lock / scroll lock for event state



commit 4691878a766d4a92a7b28917b580e734d183944b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sat Dec 22 22:21:16 2012 -0500

    x11: Ignore num lock / scroll lock for event state
    
    As x11 considers num lock and scroll lock to be modifiers, code that
    checks for an exact modifier combination will fail if naively done when
    num lock or scroll lock are turned on. Applications that want to ignore
    these modifiers will need to use XKB to manually mask out the modifier
    state.
    
    As it is very unlikely that applications will want to care about the
    state of num lock or scroll lock for key press/key release events, mask
    out the num lock and scroll lock keys automatically.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690664

 README.in                                     |    6 ++++++
 clutter/x11/clutter-device-manager-core-x11.c |    2 +-
 clutter/x11/clutter-device-manager-xi2.c      |    2 +-
 clutter/x11/clutter-keymap-x11.c              |   12 +++++++++++-
 clutter/x11/clutter-keymap-x11.h              |    2 +-
 5 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/README.in b/README.in
index c8019f1..22f5ef0 100644
--- a/README.in
+++ b/README.in
@@ -298,6 +298,12 @@ Relevant information for developers with existing Clutter applications
 wanting to port to newer releases (see NEWS for general information on new
 features).
 
+Release Notes for Clutter 1.14
+-------------------------------------------------------------------------------
+
+â The X11 backend (both core X events and XInput 2 backends) now mask out
+  scroll lock and num lock modifiers from the event state.
+
 Release Notes for Clutter 1.12
 -------------------------------------------------------------------------------
 
diff --git a/clutter/x11/clutter-device-manager-core-x11.c b/clutter/x11/clutter-device-manager-core-x11.c
index 3b18aa3..f470189 100644
--- a/clutter/x11/clutter-device-manager-core-x11.c
+++ b/clutter/x11/clutter-device-manager-core-x11.c
@@ -236,7 +236,7 @@ translate_key_event (ClutterBackendX11       *backend_x11,
   event->key.keyval =
     _clutter_keymap_x11_translate_key_state (backend_x11->keymap,
                                              event->key.hardware_keycode,
-                                             event->key.modifier_state,
+                                             &event->key.modifier_state,
                                              NULL);
 
   event_x11->key_group =
diff --git a/clutter/x11/clutter-device-manager-xi2.c b/clutter/x11/clutter-device-manager-xi2.c
index 8ecc8ad..616dee7 100644
--- a/clutter/x11/clutter-device-manager-xi2.c
+++ b/clutter/x11/clutter-device-manager-xi2.c
@@ -772,7 +772,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
         event->key.keyval =
           _clutter_keymap_x11_translate_key_state (backend_x11->keymap,
                                                    event->key.hardware_keycode,
-                                                   event->key.modifier_state,
+                                                   &event->key.modifier_state,
                                                    NULL);
 
         /* KeyEvents have platform specific data associated to them */
diff --git a/clutter/x11/clutter-keymap-x11.c b/clutter/x11/clutter-keymap-x11.c
index d4bbf2c..4a1d578 100644
--- a/clutter/x11/clutter-keymap-x11.c
+++ b/clutter/x11/clutter-keymap-x11.c
@@ -50,6 +50,7 @@ struct _ClutterKeymapX11
   ClutterModifierType modmap[8];
 
   ClutterModifierType num_lock_mask;
+  ClutterModifierType scroll_lock_mask;
 
 #ifdef HAVE_XKB
   XkbDescPtr xkb_desc;
@@ -180,6 +181,10 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
     keymap_x11->num_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy,
                                                       XK_Num_Lock);
 
+  if (keymap_x11->scroll_lock_mask == 0)
+    keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy,
+                                                         XK_Scroll_Lock);
+
   return keymap_x11->xkb_desc;
 }
 #endif /* HAVE_XKB */
@@ -435,11 +440,12 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 gint
 _clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
                                          guint                hardware_keycode,
-                                         ClutterModifierType  modifier_state,
+                                         ClutterModifierType *modifier_state_p,
                                          ClutterModifierType *mods_p)
 {
   ClutterBackendX11 *backend_x11;
   ClutterModifierType unconsumed_modifiers = 0;
+  ClutterModifierType modifier_state = *modifier_state_p;
   gint retval;
 
   g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), 0);
@@ -468,6 +474,10 @@ _clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
   if (mods_p)
     *mods_p = unconsumed_modifiers;
 
+  *modifier_state_p = modifier_state & ~(keymap->num_lock_mask |
+                                         keymap->scroll_lock_mask |
+                                         LockMask);
+
   return retval;
 }
 
diff --git a/clutter/x11/clutter-keymap-x11.h b/clutter/x11/clutter-keymap-x11.h
index 7c5ea2f..3032785 100644
--- a/clutter/x11/clutter-keymap-x11.h
+++ b/clutter/x11/clutter-keymap-x11.h
@@ -43,7 +43,7 @@ gboolean _clutter_keymap_x11_get_num_lock_state  (ClutterKeymapX11    *keymap);
 gboolean _clutter_keymap_x11_get_caps_lock_state (ClutterKeymapX11    *keymap);
 gint     _clutter_keymap_x11_translate_key_state (ClutterKeymapX11    *keymap,
                                                   guint                hardware_keycode,
-                                                  ClutterModifierType  modifier_state,
+                                                  ClutterModifierType *modifier_state_p,
                                                   ClutterModifierType *mods_p);
 gboolean _clutter_keymap_x11_get_is_modifier     (ClutterKeymapX11    *keymap,
                                                   gint                 keycode);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]