menu: implement menu accelerators

Menu accelerators are one-letter mnemonics to quickly select/exec
items from the current menu. For each menu item, the accelerator is
defined as the first character of the item label, converted to
lowercase. A different accelerator can be explicitly defined in
menu.xml with the special '_' character before the target letter.

- Add a field `accelerator` to the `menuitem` struct
- Implement `menu_item_select_by_accelerator()`

Example:
The accelerator for an item with the label "e_macs" is 'm'.
This commit is contained in:
Alex Chernika 2026-04-10 14:52:24 +02:00 committed by Johan Malm
parent 07a0a4e59b
commit 3632c6703a
4 changed files with 190 additions and 8 deletions

View file

@ -444,15 +444,24 @@ handle_menu_keys(struct keysyms *syms)
break;
case XKB_KEY_Return:
case XKB_KEY_KP_Enter:
menu_call_selected_actions();
if (!menu_call_selected_actions()) {
menu_submenu_enter();
};
break;
case XKB_KEY_Escape:
menu_close_root();
cursor_update_focus();
break;
default:
continue;
}
default: {
uint32_t accelerator = xkb_keysym_to_utf32(syms->syms[i]);
if (accelerator == 0) {
continue;
}
if (menu_item_select_by_accelerator(accelerator)) {
menu_call_selected_actions();
}
break;
}}
break;
}
}