diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-05-07 22:15:26 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2020-05-07 23:10:03 -0400 |
commit | 064f64dbf7a5e71116cb03d8d45aaaf0ee69312e (patch) | |
tree | e59deee649104b02845a296384286aa964dbfb5b | |
parent | 6357e166f9a31f0c828ea5bb0000627c15442505 (diff) |
input/keyboard: expose keymap matching helper
sway needs this logic too, and currently ships a version that has fallen
behind in terms of bugfixes (b1a63bc).
-rw-r--r-- | include/wlr/types/wlr_keyboard.h | 3 | ||||
-rw-r--r-- | types/wlr_keyboard.c | 16 | ||||
-rw-r--r-- | types/wlr_keyboard_group.c | 23 |
3 files changed, 24 insertions, 18 deletions
diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index 616e2218..c3e36054 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -105,6 +105,9 @@ struct wlr_event_keyboard_key { bool wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); + +bool wlr_keyboard_keymaps_match(struct xkb_keymap *km1, struct xkb_keymap *km2); + /** * Sets the keyboard repeat info. `rate` is in key repeats/second and delay is * in milliseconds. diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 8b4bcf8f..72b8eab5 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -232,3 +232,19 @@ uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { } return modifiers; } + +bool wlr_keyboard_keymaps_match(struct xkb_keymap *km1, + struct xkb_keymap *km2) { + if (!km1 && !km2) { + return true; + } + if (!km1 || !km2) { + return false; + } + char *km1_str = xkb_keymap_get_as_string(km1, XKB_KEYMAP_FORMAT_TEXT_V1); + char *km2_str = xkb_keymap_get_as_string(km2, XKB_KEYMAP_FORMAT_TEXT_V1); + bool result = strcmp(km1_str, km2_str) == 0; + free(km1_str); + free(km2_str); + return result; +} diff --git a/types/wlr_keyboard_group.c b/types/wlr_keyboard_group.c index 71e95646..059a4767 100644 --- a/types/wlr_keyboard_group.c +++ b/types/wlr_keyboard_group.c @@ -81,21 +81,6 @@ struct wlr_keyboard_group *wlr_keyboard_group_from_wlr_keyboard( return (struct wlr_keyboard_group *)keyboard; } -static bool keymaps_match(struct xkb_keymap *km1, struct xkb_keymap *km2) { - if (!km1 && !km2) { - return true; - } - if (!km1 || !km2) { - return false; - } - char *km1_str = xkb_keymap_get_as_string(km1, XKB_KEYMAP_FORMAT_TEXT_V1); - char *km2_str = xkb_keymap_get_as_string(km2, XKB_KEYMAP_FORMAT_TEXT_V1); - bool result = strcmp(km1_str, km2_str) == 0; - free(km1_str); - free(km2_str); - return result; -} - static void handle_keyboard_key(struct wl_listener *listener, void *data) { struct keyboard_group_device *group_device = wl_container_of(listener, group_device, key); @@ -166,10 +151,12 @@ static void handle_keyboard_keymap(struct wl_listener *listener, void *data) { wl_container_of(listener, group_device, keymap); struct wlr_keyboard *keyboard = group_device->keyboard; - if (!keymaps_match(keyboard->group->keyboard.keymap, keyboard->keymap)) { + if (!wlr_keyboard_keymaps_match(keyboard->group->keyboard.keymap, + keyboard->keymap)) { struct keyboard_group_device *device; wl_list_for_each(device, &keyboard->group->devices, link) { - if (!keymaps_match(keyboard->keymap, device->keyboard->keymap)) { + if (!wlr_keyboard_keymaps_match(keyboard->keymap, + device->keyboard->keymap)) { wlr_keyboard_set_keymap(device->keyboard, keyboard->keymap); return; } @@ -245,7 +232,7 @@ bool wlr_keyboard_group_add_keyboard(struct wlr_keyboard_group *group, return false; } - if (!keymaps_match(group->keyboard.keymap, keyboard->keymap)) { + if (!wlr_keyboard_keymaps_match(group->keyboard.keymap, keyboard->keymap)) { wlr_log(WLR_ERROR, "Device keymap does not match keyboard group's"); return false; } |