aboutsummaryrefslogtreecommitdiff
path: root/search.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-27 19:42:31 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-03-04 08:43:43 +0000
commit5e64e06a550c2499a23f03749986791136cbbcb9 (patch)
tree0922e869989e2f55ba2b3aa5d14ff0b78a954a50 /search.c
parentinput: ask XKB for consumed modifiers, but don’t actually use them just yet (diff)
input: rewrite of how we match foot’s own key bindings
Bindings are matched in one out of three ways: * By translated (by XKB) symbols * By untranslated symbols * By raw key codes A translated symbol is affected by pressed modifiers, some of which can be “consumed”. Consumed modifiers to not partake in the comparison with the binding’s modifiers. In this mode, ctrl+shift+2 maps to ctrl+@ on a US layout. Untranslated symbols, or un-shifted symbols refer to the “base” symbol of the pressed key, i.e. it’s unaffected by modifiers. In this mode, consumed modifiers *do* partake in the comparison with the binding’s modifiers, and ctrl+shift+2 maps to ctrl+shift+2 on a US layout. More examples: ctrl+shift+u maps to ctrl+U in the translated lookup, while ctrl+shift+u maps to ctrl+shift+u in the untranslated lookup. Finally, we also match raw key codes. This allows our bindings to work using the same physical keys when the user switches between latin and non-latin layouts. This means key bindings in foot.ini *must* not include both +shift+ and a *shifted* key. I.e. ctrl+shift+U is not a valid combo as it cannot be triggered. Unfortunately, this was how you were supposed to write bindings up until now... so, we try to detect such bindings, log a deprecation warning and then “fix” the binding for the user. When specifying bindings in foot.ini, both ctrl+U and ctrl+shift+u are valid, and will work. The latter is preferred though, since we cannot detect the raw key code for the former variant. Personally, I also prefer the latter one because it is more explicit; it’s more obvious which keys are involved. However, in some cases it makes more sense to use the other variant. Typically for non-letter combos.
Diffstat (limited to 'search.c')
-rw-r--r--search.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/search.c b/search.c
index 5dfa7b58..30a50ae5 100644
--- a/search.c
+++ b/search.c
@@ -783,7 +783,9 @@ execute_binding(struct seat *seat, struct terminal *term,
void
search_input(struct seat *seat, struct terminal *term, uint32_t key,
- xkb_keysym_t sym, xkb_mod_mask_t mods, uint32_t serial)
+ xkb_keysym_t sym, xkb_mod_mask_t mods, xkb_mod_mask_t consumed,
+ const xkb_keysym_t *raw_syms, size_t raw_count,
+ uint32_t serial)
{
LOG_DBG("search: input: sym=%d/0x%x, mods=0x%08x", sym, sym, mods);
@@ -795,12 +797,13 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
/* Key bindings */
tll_foreach(seat->kbd.bindings.search, it) {
- if (it->item.mods != mods)
- continue;
+ const struct key_binding *bind = &it->item;
+
+ /* Match translated symbol */
+ if (bind->sym == sym &&
+ bind->mods == (mods & ~consumed)) {
- /* Match symbol */
- if (it->item.sym == sym) {
- if (execute_binding(seat, term, it->item.action, serial,
+ if (execute_binding(seat, term, bind->action, serial,
&update_search_result, &redraw))
{
goto update_search;
@@ -808,10 +811,25 @@ search_input(struct seat *seat, struct terminal *term, uint32_t key,
return;
}
+ if (bind->mods != mods)
+ continue;
+
+ /* Match untranslated symbols */
+ for (size_t i = 0; i < raw_count; i++) {
+ if (bind->sym == raw_syms[i]) {
+ if (execute_binding(seat, term, bind->action, serial,
+ &update_search_result, &redraw))
+ {
+ goto update_search;
+ }
+ return;
+ }
+ }
+
/* Match raw key code */
- tll_foreach(it->item.key_codes, code) {
+ tll_foreach(bind->key_codes, code) {
if (code->item == key) {
- if (execute_binding(seat, term, it->item.action, serial,
+ if (execute_binding(seat, term, bind->action, serial,
&update_search_result, &redraw))
{
goto update_search;