summaryrefslogtreecommitdiff
path: root/sway/input/keyboard.c
diff options
context:
space:
mode:
authorBrian Ashworth <[email protected]>2019-07-17 17:12:20 -0400
committerSimon Ser <[email protected]>2019-07-23 20:45:46 +0300
commit6effca7b61e87c7d17885d007d94e556a0137651 (patch)
tree686cc1e219d8236f8c9864c9992b3cb6b44c9583 /sway/input/keyboard.c
parent36aa67e549609ce6c786c382f14ab866536cac47 (diff)
ipc: add an input event
This adds an ipc event related to input devices. Currently the following changes are supported: - added: when an input device becomes available - removed: when an input device is no longer available - xkb_keymap_changed: (keyboards only) the keymap changed - xkb_layout_changed: (keyboards only) the effective layout changed
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r--sway/input/keyboard.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c
index 1f7ed849..328458fa 100644
--- a/sway/input/keyboard.c
+++ b/sway/input/keyboard.c
@@ -473,6 +473,11 @@ static void handle_keyboard_modifiers(struct wl_listener *listener,
uint32_t modifiers = wlr_keyboard_get_modifiers(wlr_device->keyboard);
determine_bar_visibility(modifiers);
+
+ if (wlr_device->keyboard->modifiers.group != keyboard->effective_layout) {
+ keyboard->effective_layout = wlr_device->keyboard->modifiers.group;
+ ipc_event_input("xkb_layout", keyboard->seat_device->input_device);
+ }
}
struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat,
@@ -603,8 +608,23 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
}
}
+ bool keymap_changed = false;
+ bool effective_layout_changed = keyboard->effective_layout != 0;
+ if (keyboard->keymap) {
+ char *old_keymap_string = xkb_keymap_get_as_string(keyboard->keymap,
+ XKB_KEYMAP_FORMAT_TEXT_V1);
+ char *new_keymap_string = xkb_keymap_get_as_string(keymap,
+ XKB_KEYMAP_FORMAT_TEXT_V1);
+ keymap_changed = strcmp(old_keymap_string, new_keymap_string);
+ free(old_keymap_string);
+ free(new_keymap_string);
+ } else {
+ keymap_changed = true;
+ }
+
xkb_keymap_unref(keyboard->keymap);
keyboard->keymap = keymap;
+ keyboard->effective_layout = 0;
wlr_keyboard_set_keymap(wlr_device->keyboard, keyboard->keymap);
xkb_mod_mask_t locked_mods = 0;
@@ -654,6 +674,14 @@ void sway_keyboard_configure(struct sway_keyboard *keyboard) {
wl_signal_add(&wlr_device->keyboard->events.modifiers,
&keyboard->keyboard_modifiers);
keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers;
+
+ if (keymap_changed) {
+ ipc_event_input("xkb_keymap",
+ keyboard->seat_device->input_device);
+ } else if (effective_layout_changed) {
+ ipc_event_input("xkb_layout",
+ keyboard->seat_device->input_device);
+ }
}
void sway_keyboard_destroy(struct sway_keyboard *keyboard) {