From 521e893528eb68691fad4944257fd073619d6338 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 3 Oct 2017 14:03:26 +0200 Subject: Add modifiers signal, remove wlr_keyboard_update_modifiers --- backend/wayland/wl_seat.c | 4 --- include/wlr/interfaces/wlr_keyboard.h | 3 -- include/wlr/types/wlr_keyboard.h | 1 + include/wlr/types/wlr_seat.h | 1 + types/wlr_keyboard.c | 40 +++++++++++----------- types/wlr_seat.c | 64 ++++++++++++++++++++++++----------- 6 files changed, 67 insertions(+), 46 deletions(-) diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 44ce6028..ba3feb8d 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -155,11 +155,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { - struct wlr_input_device *dev = data; - assert(dev && dev->keyboard); - wlr_keyboard_update_modifiers(dev->keyboard, mods_depressed, mods_latched, - mods_locked, group); } static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, diff --git a/include/wlr/interfaces/wlr_keyboard.h b/include/wlr/interfaces/wlr_keyboard.h index 9755267a..78c1f753 100644 --- a/include/wlr/interfaces/wlr_keyboard.h +++ b/include/wlr/interfaces/wlr_keyboard.h @@ -13,8 +13,5 @@ void wlr_keyboard_init(struct wlr_keyboard *keyboard, struct wlr_keyboard_impl * void wlr_keyboard_destroy(struct wlr_keyboard *keyboard); void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event); -void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, - uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, - uint32_t group); #endif diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index 2d9f1490..9ec8ddd4 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -49,6 +49,7 @@ struct wlr_keyboard { struct { struct wl_signal key; + struct wl_signal modifiers; struct wl_signal keymap; } events; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6927cd16..489bd529 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -37,6 +37,7 @@ struct wlr_seat_keyboard { struct wlr_seat *seat; struct wlr_keyboard *keyboard; struct wl_listener key; + struct wl_listener modifiers; struct wl_listener keymap; struct wl_listener destroy; struct wl_list link; diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 168475bd..f51ea8c4 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -21,19 +21,28 @@ static void keyboard_led_update(struct wlr_keyboard *keyboard) { wlr_keyboard_led_update(keyboard, leds); } -void wlr_keyboard_update_modifiers(struct wlr_keyboard *keyboard, - uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, - uint32_t group) { - if (mods_depressed == keyboard->modifiers.depressed && - mods_latched == keyboard->modifiers.latched && - mods_locked == keyboard->modifiers.locked && +static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { + xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_DEPRESSED); + xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LATCHED); + xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LOCKED); + xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, + XKB_STATE_LAYOUT_EFFECTIVE); + if (depressed == keyboard->modifiers.depressed && + latched == keyboard->modifiers.latched && + locked == keyboard->modifiers.locked && group == keyboard->modifiers.group) { return; } - keyboard->modifiers.depressed = mods_depressed; - keyboard->modifiers.latched = mods_latched; - keyboard->modifiers.locked = mods_locked; + + keyboard->modifiers.depressed = depressed; + keyboard->modifiers.latched = latched; + keyboard->modifiers.locked = locked; keyboard->modifiers.group = group; + + wl_signal_emit(&keyboard->events.modifiers, keyboard); } void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, @@ -42,17 +51,7 @@ void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, xkb_state_update_key(keyboard->xkb_state, keycode, event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); keyboard_led_update(keyboard); - - xkb_mod_mask_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_DEPRESSED); - xkb_mod_mask_t latched = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_LATCHED); - xkb_mod_mask_t locked = xkb_state_serialize_mods(keyboard->xkb_state, - XKB_STATE_MODS_LOCKED); - xkb_mod_mask_t group = xkb_state_serialize_layout(keyboard->xkb_state, - XKB_STATE_LAYOUT_EFFECTIVE); - wlr_keyboard_update_modifiers(keyboard, depressed, latched, locked, group); - + keyboard_modifier_update(keyboard); wl_signal_emit(&keyboard->events.key, event); } @@ -60,6 +59,7 @@ void wlr_keyboard_init(struct wlr_keyboard *kb, struct wlr_keyboard_impl *impl) { kb->impl = impl; wl_signal_init(&kb->events.key); + wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 66b2f18e..2702f1b5 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -376,39 +376,61 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, wl_pointer_send_frame(pointer); } +static void keyboard_switch_seat_keyboard(struct wlr_seat_handle *handle, + struct wlr_seat_keyboard *seat_kb) { + if (handle->seat_keyboard == seat_kb) { + return; + } + + // TODO: We should probably lift all of the keys set by the other + // keyboard + wl_keyboard_send_keymap(handle->keyboard, + WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, seat_kb->keyboard->keymap_fd, + seat_kb->keyboard->keymap_size); + + if (wl_resource_get_version(handle->keyboard) >= 2) { + // TODO: Make this better + wl_keyboard_send_repeat_info(handle->keyboard, 25, 600); + } + handle->seat_keyboard = seat_kb; +} + static void keyboard_key_notify(struct wl_listener *listener, void *data) { - struct wlr_seat_keyboard *seat_kb = wl_container_of( - listener, seat_kb, key); + struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, key); struct wlr_seat *seat = seat_kb->seat; struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle; if (!handle || !handle->keyboard) { return; } - struct wlr_keyboard *keyboard = seat_kb->keyboard; + + keyboard_switch_seat_keyboard(handle, seat_kb); + struct wlr_event_keyboard_key *event = data; enum wlr_key_state key_state = event->state; - if (handle->seat_keyboard != seat_kb) { - // TODO: We should probably lift all of the keys set by the other - // keyboard - wl_keyboard_send_keymap(handle->keyboard, - WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, - seat_kb->keyboard->keymap_fd, - seat_kb->keyboard->keymap_size); - - if (wl_resource_get_version(handle->keyboard) >= 2) { - // TODO: Make this better - wl_keyboard_send_repeat_info(handle->keyboard, 25, 600); - } - handle->seat_keyboard = seat_kb; + + uint32_t key_serial = wl_display_next_serial(seat->display); + wl_keyboard_send_key(handle->keyboard, key_serial, + (uint32_t)event->time_usec, event->keycode, key_state); +} + +static void keyboard_modifiers_notify(struct wl_listener *listener, + void *data) { + struct wlr_seat_keyboard *seat_kb = wl_container_of(listener, seat_kb, + modifiers); + struct wlr_seat *seat = seat_kb->seat; + struct wlr_seat_handle *handle = seat->keyboard_state.focused_handle; + if (!handle || !handle->keyboard) { + return; } + keyboard_switch_seat_keyboard(handle, seat_kb); + + struct wlr_keyboard *keyboard = seat_kb->keyboard; + uint32_t modifiers_serial = wl_display_next_serial(seat->display); wl_keyboard_send_modifiers(handle->keyboard, modifiers_serial, keyboard->modifiers.depressed, keyboard->modifiers.latched, keyboard->modifiers.locked, keyboard->modifiers.group); - uint32_t key_serial = wl_display_next_serial(seat->display); - wl_keyboard_send_key(handle->keyboard, key_serial, - (uint32_t)event->time_usec, event->keycode, key_state); } static void keyboard_keymap_notify(struct wl_listener *listener, void *data) { @@ -434,6 +456,9 @@ void wlr_seat_attach_keyboard(struct wlr_seat *seat, wl_list_init(&seat_kb->key.link); seat_kb->key.notify = keyboard_key_notify; wl_signal_add(&kb->events.key, &seat_kb->key); + wl_list_init(&seat_kb->modifiers.link); + seat_kb->modifiers.notify = keyboard_modifiers_notify; + wl_signal_add(&kb->events.modifiers, &seat_kb->modifiers); wl_list_init(&seat_kb->keymap.link); seat_kb->keymap.notify = keyboard_keymap_notify; wl_signal_add(&kb->events.keymap, &seat_kb->keymap); @@ -450,6 +475,7 @@ void wlr_seat_detach_keyboard(struct wlr_seat *seat, struct wlr_keyboard *kb) { if (seat_kb->keyboard == kb) { wl_list_remove(&seat_kb->link); wl_list_remove(&seat_kb->key.link); + wl_list_remove(&seat_kb->modifiers.link); wl_list_remove(&seat_kb->keymap.link); wl_list_remove(&seat_kb->destroy.link); free(seat_kb); -- cgit v1.2.3