From 9692c1498bcde3489f80b484dbd847a75dfd0405 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 29 Oct 2015 08:47:36 +0100 Subject: [PATCH] Bugfix: set group mask 1 by default, correctly compare modifiers fixes #2002 --- src/bindings.c | 4 ++-- src/config_directives.c | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/bindings.c b/src/bindings.c index ed8775a8..7ea087e6 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -167,10 +167,10 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas TAILQ_FOREACH(bind, bindings, bindings) { bool state_matches; - if (bind->event_state_mask == 0) { + if ((bind->event_state_mask & 0xFFFF) == 0) { /* Verify no modifiers are pressed. A bitwise AND would lead to * false positives, see issue #2002. */ - state_matches = (state_filtered == 0); + state_matches = (state_filtered == bind->event_state_mask); } else { state_matches = ((state_filtered & bind->event_state_mask) == bind->event_state_mask); } diff --git a/src/config_directives.c b/src/config_directives.c index 20b880ed..fb6ae94c 100644 --- a/src/config_directives.c +++ b/src/config_directives.c @@ -67,8 +67,9 @@ i3_event_state_mask_t event_state_from_str(const char *str) { /* It might be better to use strtok() here, but the simpler strstr() should * do for now. */ i3_event_state_mask_t result = 0; + int group_bits_set = 0; if (str == NULL) - return result; + return (I3_XKB_GROUP_MASK_1 << 16); if (strstr(str, "Mod1") != NULL) result |= XCB_KEY_BUT_MASK_MOD_1; if (strstr(str, "Mod2") != NULL) @@ -85,15 +86,26 @@ i3_event_state_mask_t event_state_from_str(const char *str) { if (strstr(str, "Shift") != NULL) result |= XCB_KEY_BUT_MASK_SHIFT; - if (strstr(str, "Group1") != NULL) + if (strstr(str, "Group1") != NULL) { result |= (I3_XKB_GROUP_MASK_1 << 16); + group_bits_set++; + } if (strstr(str, "Group2") != NULL || - strstr(str, "Mode_switch") != NULL) + strstr(str, "Mode_switch") != NULL) { result |= (I3_XKB_GROUP_MASK_2 << 16); - if (strstr(str, "Group3") != NULL) + group_bits_set++; + } + if (strstr(str, "Group3") != NULL) { result |= (I3_XKB_GROUP_MASK_3 << 16); - if (strstr(str, "Group4") != NULL) + group_bits_set++; + } + if (strstr(str, "Group4") != NULL) { result |= (I3_XKB_GROUP_MASK_4 << 16); + group_bits_set++; + } + if (group_bits_set == 0) { + result |= (I3_XKB_GROUP_MASK_1 << 16); + } return result; } -- 2.39.2