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
This commit is contained in:
Jasper St. Pierre 2012-12-22 22:21:16 -05:00
parent 551c01e7ce
commit 4691878a76
5 changed files with 20 additions and 4 deletions

View File

@ -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 wanting to port to newer releases (see NEWS for general information on new
features). 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 Release Notes for Clutter 1.12
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -236,7 +236,7 @@ translate_key_event (ClutterBackendX11 *backend_x11,
event->key.keyval = event->key.keyval =
_clutter_keymap_x11_translate_key_state (backend_x11->keymap, _clutter_keymap_x11_translate_key_state (backend_x11->keymap,
event->key.hardware_keycode, event->key.hardware_keycode,
event->key.modifier_state, &event->key.modifier_state,
NULL); NULL);
event_x11->key_group = event_x11->key_group =

View File

@ -772,7 +772,7 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
event->key.keyval = event->key.keyval =
_clutter_keymap_x11_translate_key_state (backend_x11->keymap, _clutter_keymap_x11_translate_key_state (backend_x11->keymap,
event->key.hardware_keycode, event->key.hardware_keycode,
event->key.modifier_state, &event->key.modifier_state,
NULL); NULL);
/* KeyEvents have platform specific data associated to them */ /* KeyEvents have platform specific data associated to them */

View File

@ -50,6 +50,7 @@ struct _ClutterKeymapX11
ClutterModifierType modmap[8]; ClutterModifierType modmap[8];
ClutterModifierType num_lock_mask; ClutterModifierType num_lock_mask;
ClutterModifierType scroll_lock_mask;
#ifdef HAVE_XKB #ifdef HAVE_XKB
XkbDescPtr xkb_desc; XkbDescPtr xkb_desc;
@ -180,6 +181,10 @@ get_xkb (ClutterKeymapX11 *keymap_x11)
keymap_x11->num_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy, keymap_x11->num_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy,
XK_Num_Lock); 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; return keymap_x11->xkb_desc;
} }
#endif /* HAVE_XKB */ #endif /* HAVE_XKB */
@ -435,11 +440,12 @@ G_GNUC_END_IGNORE_DEPRECATIONS
gint gint
_clutter_keymap_x11_translate_key_state (ClutterKeymapX11 *keymap, _clutter_keymap_x11_translate_key_state (ClutterKeymapX11 *keymap,
guint hardware_keycode, guint hardware_keycode,
ClutterModifierType modifier_state, ClutterModifierType *modifier_state_p,
ClutterModifierType *mods_p) ClutterModifierType *mods_p)
{ {
ClutterBackendX11 *backend_x11; ClutterBackendX11 *backend_x11;
ClutterModifierType unconsumed_modifiers = 0; ClutterModifierType unconsumed_modifiers = 0;
ClutterModifierType modifier_state = *modifier_state_p;
gint retval; gint retval;
g_return_val_if_fail (CLUTTER_IS_KEYMAP_X11 (keymap), 0); 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) if (mods_p)
*mods_p = unconsumed_modifiers; *mods_p = unconsumed_modifiers;
*modifier_state_p = modifier_state & ~(keymap->num_lock_mask |
keymap->scroll_lock_mask |
LockMask);
return retval; return retval;
} }

View File

@ -43,7 +43,7 @@ gboolean _clutter_keymap_x11_get_num_lock_state (ClutterKeymapX11 *keymap);
gboolean _clutter_keymap_x11_get_caps_lock_state (ClutterKeymapX11 *keymap); gboolean _clutter_keymap_x11_get_caps_lock_state (ClutterKeymapX11 *keymap);
gint _clutter_keymap_x11_translate_key_state (ClutterKeymapX11 *keymap, gint _clutter_keymap_x11_translate_key_state (ClutterKeymapX11 *keymap,
guint hardware_keycode, guint hardware_keycode,
ClutterModifierType modifier_state, ClutterModifierType *modifier_state_p,
ClutterModifierType *mods_p); ClutterModifierType *mods_p);
gboolean _clutter_keymap_x11_get_is_modifier (ClutterKeymapX11 *keymap, gboolean _clutter_keymap_x11_get_is_modifier (ClutterKeymapX11 *keymap,
gint keycode); gint keycode);