labwc/include/config/keybind.h
John Lindgren 6574c82aed 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.
2025-08-18 19:54:18 +01:00

48 lines
1.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_KEYBIND_H
#define LABWC_KEYBIND_H
#include <wlr/types/wlr_keyboard.h>
#include <xkbcommon/xkbcommon.h>
#define MAX_KEYSYMS 32
#define MAX_KEYCODES 16
struct server;
struct keybind {
uint32_t modifiers;
xkb_keysym_t *keysyms;
size_t keysyms_len;
bool use_syms_only;
xkb_keycode_t keycodes[MAX_KEYCODES];
size_t keycodes_len;
int keycodes_layout;
bool allow_when_locked;
struct wl_list actions; /* struct action.link */
struct wl_list link; /* struct rcxml.keybinds */
bool on_release;
};
/**
* keybind_create - parse keybind and add to linked list
* @keybind: key combination
*/
struct keybind *keybind_create(const char *keybind);
void keybind_destroy(struct keybind *keybind);
/**
* parse_modifier - parse a string containing a single modifier name (e.g. "S")
* into the represented modifier value. returns 0 for invalid modifier names.
* @symname: modifier name
*/
uint32_t parse_modifier(const char *symname);
bool keybind_the_same(struct keybind *a, struct keybind *b);
bool keybind_contains_keycode(struct keybind *keybind, xkb_keycode_t keycode);
bool keybind_contains_keysym(struct keybind *keybind, xkb_keysym_t keysym);
void keybind_update_keycodes(struct server *server);
#endif /* LABWC_KEYBIND_H */