summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2012-05-30 16:31:44 +0100
committerKristian Høgsberg <krh@bitplanet.net>2012-05-31 15:38:10 -0400
commite3f15edc2f7a760c898a3bcafc775f52f33e2d9b (patch)
tree2fd1fad81e56b565d590289ac3d823aecd82bf97
parent994679a20e64a017659296c5458a897d26226e35 (diff)
Do binding modifier lookup on XKB state, not physical keys
When we update the modifier_state used for Weston bindings, derive this from the XKB modifier state, rather than a hardcoded mapping of physical keys to modifier state. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
-rw-r--r--src/compositor.c46
-rw-r--r--src/compositor.h3
2 files changed, 23 insertions, 26 deletions
diff --git a/src/compositor.c b/src/compositor.c
index 0e39ebe..b76cd39 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1731,13 +1731,16 @@ notify_axis(struct wl_seat *seat, uint32_t time, uint32_t axis, int32_t value)
static int
update_modifier_state(struct weston_seat *seat, uint32_t key, uint32_t state)
{
- enum weston_keyboard_modifier modifier;
uint32_t mods_depressed, mods_latched, mods_locked, group;
+ uint32_t mods_lookup;
int ret = 0;
+ /* First update the XKB state object with the keypress. */
xkb_state_update_key(seat->xkb_state.state, key + 8,
state ? XKB_KEY_DOWN : XKB_KEY_UP);
+ /* Serialize and update our internal state, checking to see if it's
+ * different to the previous state. */
mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state,
XKB_STATE_DEPRESSED);
mods_latched = xkb_state_serialize_mods(seat->xkb_state.state,
@@ -1758,31 +1761,15 @@ update_modifier_state(struct weston_seat *seat, uint32_t key, uint32_t state)
seat->xkb_state.mods_locked = mods_locked;
seat->xkb_state.group = group;
- switch (key) {
- case KEY_LEFTCTRL:
- case KEY_RIGHTCTRL:
- modifier = MODIFIER_CTRL;
- break;
-
- case KEY_LEFTALT:
- case KEY_RIGHTALT:
- modifier = MODIFIER_ALT;
- break;
-
- case KEY_LEFTMETA:
- case KEY_RIGHTMETA:
- modifier = MODIFIER_SUPER;
- break;
-
- default:
- modifier = 0;
- break;
- }
-
- if (state)
- seat->modifier_state |= modifier;
- else
- seat->modifier_state &= ~modifier;
+ /* And update the modifier_state for bindings. */
+ mods_lookup = mods_depressed | mods_latched;
+ seat->modifier_state = 0;
+ if ((mods_lookup & seat->compositor->xkb_info.ctrl_mod))
+ seat->modifier_state |= MODIFIER_CTRL;
+ if ((mods_lookup & seat->compositor->xkb_info.alt_mod))
+ seat->modifier_state |= MODIFIER_ALT;
+ if ((mods_lookup & seat->compositor->xkb_info.super_mod))
+ seat->modifier_state |= MODIFIER_SUPER;
return ret;
}
@@ -2243,6 +2230,13 @@ static int weston_compositor_xkb_init(struct weston_compositor *ec,
return -1;
}
+ ec->xkb_info.ctrl_mod = xkb_map_mod_get_index(ec->xkb_info.keymap,
+ XKB_MOD_NAME_CTRL);
+ ec->xkb_info.alt_mod = xkb_map_mod_get_index(ec->xkb_info.keymap,
+ XKB_MOD_NAME_ALT);
+ ec->xkb_info.super_mod = xkb_map_mod_get_index(ec->xkb_info.keymap,
+ XKB_MOD_NAME_LOGO);
+
return 0;
}
diff --git a/src/compositor.h b/src/compositor.h
index 26857c2..4c037c9 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -305,6 +305,9 @@ struct weston_compositor {
struct xkb_rule_names names;
struct xkb_context *context;
struct xkb_keymap *keymap;
+ xkb_mod_index_t ctrl_mod;
+ xkb_mod_index_t alt_mod;
+ xkb_mod_index_t super_mod;
} xkb_info;
};