From 0c85905972fdc739fb140e32c3389c08e769bfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 21 Mar 2021 11:55:03 +0100 Subject: [PATCH] input: must have all required modifiers to un-shift a symbol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When detecting, and repairing, “broken” key bindings (where the key binding itself explicitly lists a modifier that is consumed by the final symbol - e.g “Shift+W”), don’t just look for an intersection between the set of modifiers needed to produce the final symbol, and the modifiers listed in the key combo. Instead, check if the key combo has *all* the required modifiers. Example: Shift+AltGr+w produces Page_Down. I.e. Page_Down is the _shifted_ symbol, ‘w’ is the un-shifted symbol, and Shift+AltGr are the modifiers required to shift ‘w’ to Page_Down. If we have the key combo Shift+Page_Down, foot would, correctly, determine that Page_Down is a shifted symbol. It would find the Shift+AltGr modifier set, and since the intersection of “Shift+AltGr” and “Shift” (from our key combo) is non-empty, foot would (incorrectly) determine that we can, and should, replace Page_Down with its un-shifted symbol ‘w’. This is completely wrong, since Shift+w does _not_ produce Page_Down. Closes #407 --- CHANGELOG.md | 5 +++++ input.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46e3a5b8..266d9b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,11 @@ ### Deprecated ### Removed ### Fixed + +* Logic that repairs invalid key bindings ended up breaking valid key + bindings instead (https://codeberg.org/dnkl/foot/issues/407). + + ### Security ### Contributors diff --git a/input.c b/input.c index bc28bbf2..9a26e778 100644 --- a/input.c +++ b/input.c @@ -450,7 +450,7 @@ maybe_repair_key_combo(const struct seat *seat, /* Check if key combo’s modifier set intersects */ for (size_t j = 0; j < mod_mask_count; j++) { - if (!(mod_masks[j] & mods)) + if ((mod_masks[j] & mods) != mod_masks[j]) continue; char combo[64] = {0};