aboutsummaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2025-03-29 09:34:40 +0000
committerDaniel Eklöf <daniel@ekloef.se>2025-03-31 06:08:43 +0000
commit58910856c8a86095883625009a089cef464edc44 (patch)
treece2859bf841de26b40d99015665ccc3a82f1baa4 /input.c
parentgrid: reflow: fix empty line coalescing (diff)
input: xkb: ignore virtual modifiers
Some compositors (mutter/GNOME is one) adds _virtual_ modifiers to the set of active modifiers when e.g. Alt, Meta, Super or Hyper is pressed. For example, pressing Alt+b would result in *both* the Alt *and* the Mod1 modifier being set. Since foot makes close to zero assumptions on how the modifiers should be interpreted, this causes various breakages. For example, a foot shortcut defined as Mod1+b will not match, since the Alt modifiers is also set. This has forced users to redefine/override some of the default key bindings to include the additional modifiers. It also causes issues with the kitty keyboard protocol, for some key combinations. Mainly whether or not to use unshifted key or not, resulting in incorrect escape sequences. Since all the "real" modifiers are always set as well, we can safely ignore the virtual modifiers. Closes #2009
Diffstat (limited to 'input.c')
-rw-r--r--input.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/input.c b/input.c
index cbe8e1c7..abaac8eb 100644
--- a/input.c
+++ b/input.c
@@ -620,6 +620,54 @@ keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
if (seat->kbd.mod_num != XKB_MOD_INVALID)
seat->kbd.kitty_significant |= 1 << seat->kbd.mod_num;
+
+ /*
+ * Create a mask of all "virtual" modifiers. Some compositors
+ * add these *in addition* to the "real" modifiers (Mod1,
+ * Mod2, etc).
+ *
+ * Since our modifier logic (both for internal shortcut
+ * processing, and e.g. the kitty keyboard protocol) makes
+ * very few assumptions on available modifiers, which keys map
+ * to which modifier etc, the presence of virtual modifiers
+ * causes various things to break.
+ *
+ * For example, if a foot shortcut is Mod1+b (i.e. Alt+b), it
+ * won't match if the compositor _also_ sets the Alt modifier
+ * (the corresponding shortcut in foot would be Alt+Mod1+b).
+ *
+ * See https://codeberg.org/dnkl/foot/issues/2009
+ *
+ * Mutter (GNOME) is known to set the virtual modifiers in
+ * addtiion to the real modifiers.
+ *
+ * As far as I know, there's no compositor that _only_ sets
+ * virtual modifiers (don't think that's even legal...?)
+ */
+ {
+ xkb_mod_index_t alt = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_ALT);
+ xkb_mod_index_t meta = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_META);
+ xkb_mod_index_t super = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_SUPER);
+ xkb_mod_index_t hyper = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_HYPER);
+ xkb_mod_index_t num_lock = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_NUM);
+ xkb_mod_index_t scroll_lock = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_SCROLL);
+ xkb_mod_index_t level_three = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_LEVEL3);
+ xkb_mod_index_t level_five = xkb_keymap_mod_get_index(seat->kbd.xkb_keymap, XKB_VMOD_NAME_LEVEL5);
+
+ xkb_mod_index_t ignore = 0;
+
+ if (alt != XKB_MOD_INVALID) ignore |= 1 << alt;
+ if (meta != XKB_MOD_INVALID) ignore |= 1 << meta;
+ if (super != XKB_MOD_INVALID) ignore |= 1 << super;
+ if (hyper != XKB_MOD_INVALID) ignore |= 1 << hyper;
+ if (num_lock != XKB_MOD_INVALID) ignore |= 1 << num_lock;
+ if (scroll_lock != XKB_MOD_INVALID) ignore |= 1 << scroll_lock;
+ if (level_three != XKB_MOD_INVALID) ignore |= 1 << level_three;
+ if (level_five != XKB_MOD_INVALID) ignore |= 1 << level_five;
+
+ seat->kbd.virtual_modifiers = ignore;
+ }
+
seat->kbd.key_arrow_up = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "UP");
seat->kbd.key_arrow_down = xkb_keymap_key_by_name(seat->kbd.xkb_keymap, "DOWN");
}
@@ -1759,6 +1807,10 @@ keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial,
{
struct seat *seat = data;
+ mods_depressed &= ~seat->kbd.virtual_modifiers;
+ mods_latched &= ~seat->kbd.virtual_modifiers;
+ mods_locked &= ~seat->kbd.virtual_modifiers;
+
#if defined(_DEBUG)
char depressed[256];
char latched[256];