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
parent afaed4af63
commit a3971feca8
No known key found for this signature in database
GPG key ID: 6029FAD8ABFB076A
2 changed files with 70 additions and 1 deletions

View file

@ -23,6 +23,7 @@ struct menuitem {
char *text;
char *icon_name;
const char *arrow;
char accelerator;
struct menu *parent;
struct menu *submenu;
bool selectable;
@ -66,6 +67,19 @@ struct menu {
/* For keyboard support */
void menu_item_select_next(void);
void menu_item_select_previous(void);
/**
* menu_item_select_by_accelerator - selects the next menu item with
* a matching accelerator, starting after the current selection
*
* @accelerator a shortcut to quickly select/open an item, defined in menu.xml
* with an underscore in the item label before the target letter.
*
* Return: a boolean value that represents whether the newly selected item
* needs to be executed.
*/
bool menu_item_select_by_accelerator(char accelerator);
void menu_submenu_enter(void);
void menu_submenu_leave(void);
bool menu_call_selected_actions(void);
@ -100,7 +114,7 @@ void menu_open_root(struct menu *menu, int x, int y);
void menu_process_cursor_motion(struct wlr_scene_node *node);
/**
* menu_close_root- close root menu
* menu_close_root - close root menu
*
* This function will close server.menu_current and set it to NULL.
* Asserts that server.input_mode is set to LAB_INPUT_STATE_MENU.