- DLOG("binding with event_state_mask 0x%x, state_filtered 0x%x, match: %s\n",
- bind->event_state_mask, state_filtered,
- ((state_filtered & bind->event_state_mask) == bind->event_state_mask) ? "yes" : "no");
+ const uint32_t xkb_group_mask = (bind->event_state_mask & 0xFFFF0000);
+ /* modifiers_mask is a special case: a value of 0 does not mean “match all”,
+ * but rather “match exactly when no modifiers are present”. */
+ const uint32_t modifiers_mask = (bind->event_state_mask & 0x0000FFFF);
+ const bool groups_match = ((xkb_group_state & xkb_group_mask) == xkb_group_mask);
+ bool mods_match;
+ if (modifiers_mask == 0) {
+ /* Verify no modifiers are pressed. A bitwise AND would lead to
+ * false positives, see issue #2002. */
+ mods_match = (modifiers_state == 0);
+ } else {
+ mods_match = ((modifiers_state & modifiers_mask) == modifiers_mask);
+ }
+ const bool state_matches = (groups_match && mods_match);
+
+ DLOG("binding groups_match = %s, mods_match = %s, state_matches = %s\n",
+ (groups_match ? "yes" : "no"),
+ (mods_match ? "yes" : "no"),
+ (state_matches ? "yes" : "no"));