keybind: refactor update_keycodes_iter() to reduce nesting

update_keycodes_iter() currently has 4(!) levels of nested loops, which
makes the logic (especially the break/continue statements) difficult to
understand. The logic also appears to continue looping uselessly after
a given keycode has already been added to a keybind.

Refactor by adding some small utility functions:

- keybind_contains_keycode()
- keybind_contains_keysym()
- keybind_contains_any_keysym()

No functional change intended.
This commit is contained in:
John Lindgren 2025-08-16 13:17:36 -04:00 committed by Johan Malm
parent 28513cbdbe
commit 6574c82aed
3 changed files with 56 additions and 33 deletions

View file

@ -219,17 +219,14 @@ match_keybinding_for_sym(struct server *server, uint32_t modifiers,
}
if (sym == XKB_KEY_NoSymbol) {
/* Use keycodes */
for (size_t i = 0; i < keybind->keycodes_len; i++) {
if (keybind->keycodes[i] == xkb_keycode) {
return keybind;
}
if (keybind_contains_keycode(keybind, xkb_keycode)) {
return keybind;
}
} else {
/* Use syms */
for (size_t i = 0; i < keybind->keysyms_len; i++) {
if (xkb_keysym_to_lower(sym) == keybind->keysyms[i]) {
return keybind;
}
if (keybind_contains_keysym(keybind,
xkb_keysym_to_lower(sym))) {
return keybind;
}
}
}