Bugfix: set group mask 1 by default, correctly compare modifiers

fixes #2002
This commit is contained in:
Michael Stapelberg 2015-10-29 08:47:36 +01:00
parent 0e5180cae9
commit 9692c1498b
2 changed files with 19 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;
}