From 0ef2df21f2943c3985fcc86f5f6c3289036be491 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 5 Jan 2018 07:00:50 -0500 Subject: [PATCH] compositor modifier hook --- include/wlr/types/wlr_keyboard.h | 14 ++++++++------ include/wlr/types/wlr_seat.h | 14 +++++++++++--- rootston/keyboard.c | 3 ++- types/wlr_keyboard.c | 20 +++++++++++--------- types/wlr_seat.c | 29 ++++++++++++++++------------- types/wlr_xdg_shell_v6.c | 5 +++-- 6 files changed, 51 insertions(+), 34 deletions(-) diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index d32d6e96..b37797c8 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -32,6 +32,13 @@ enum wlr_keyboard_modifier { struct wlr_keyboard_impl; +struct wlr_keyboard_modifiers { + xkb_mod_mask_t depressed; + xkb_mod_mask_t latched; + xkb_mod_mask_t locked; + xkb_mod_mask_t group; +}; + struct wlr_keyboard { struct wlr_keyboard_impl *impl; // TODO: Should this store key repeat info too? @@ -45,12 +52,7 @@ struct wlr_keyboard { uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP]; size_t num_keycodes; - struct { - xkb_mod_mask_t depressed; - xkb_mod_mask_t latched; - xkb_mod_mask_t locked; - xkb_mod_mask_t group; - } modifiers; + struct wlr_keyboard_modifiers *modifiers; struct { int32_t rate; diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 432e5dc3..f5b4afde 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -71,7 +71,8 @@ struct wlr_keyboard_grab_interface { struct wlr_surface *surface); void (*key)(struct wlr_seat_keyboard_grab *grab, uint32_t time, uint32_t key, uint32_t state); - void (*modifiers)(struct wlr_seat_keyboard_grab *grab); + void (*modifiers)(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers); void (*cancel)(struct wlr_seat_keyboard_grab *grab); }; @@ -344,6 +345,11 @@ bool wlr_seat_pointer_has_grab(struct wlr_seat *seat); */ void wlr_seat_set_keyboard(struct wlr_seat *seat, struct wlr_input_device *dev); +/** + * Get the active keyboard for the seat. + */ +struct wlr_keyboard *wlr_seat_get_keyboard(struct wlr_seat *seat); + /** * Start a grab of the keyboard of this seat. The grabber is responsible for * handling all keyboard events until the grab ends. @@ -375,13 +381,15 @@ void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, * Send the modifier state to focused keyboard resources. Compositors should use * `wlr_seat_keyboard_notify_modifiers()` to respect any keyboard grabs. */ -void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat); +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers); /** * Notify the seat that the modifiers for the keyboard have changed. Defers to * any keyboard grabs. */ -void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat); +void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers); /** * Notify the seat that the keyboard focus has changed and request it to be the diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 7b281308..29409dd7 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -279,7 +279,8 @@ void roots_keyboard_handle_key(struct roots_keyboard *keyboard, void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) { struct wlr_seat *seat = r_keyboard->seat->seat; wlr_seat_set_keyboard(seat, r_keyboard->device); - wlr_seat_keyboard_notify_modifiers(seat); + wlr_seat_keyboard_notify_modifiers(seat, + r_keyboard->device->keyboard->modifiers); } static void keyboard_config_merge(struct roots_keyboard_config *config, diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 6caf27f5..53ea3a59 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -30,17 +30,17 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { 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) { + if (depressed == keyboard->modifiers->depressed && + latched == keyboard->modifiers->latched && + locked == keyboard->modifiers->locked && + group == keyboard->modifiers->group) { return; } - keyboard->modifiers.depressed = depressed; - keyboard->modifiers.latched = latched; - keyboard->modifiers.locked = locked; - keyboard->modifiers.group = group; + keyboard->modifiers->depressed = depressed; + keyboard->modifiers->latched = latched; + keyboard->modifiers->locked = locked; + keyboard->modifiers->group = group; wl_signal_emit(&keyboard->events.modifiers, keyboard); } @@ -117,6 +117,7 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, void wlr_keyboard_init(struct wlr_keyboard *kb, struct wlr_keyboard_impl *impl) { kb->impl = impl; + kb->modifiers = calloc(1, sizeof(struct wlr_keyboard_modifiers)); wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.keymap); @@ -139,6 +140,7 @@ void wlr_keyboard_destroy(struct wlr_keyboard *kb) { xkb_state_unref(kb->xkb_state); xkb_keymap_unref(kb->keymap); close(kb->keymap_fd); + free(kb->modifiers); free(kb); } @@ -222,7 +224,7 @@ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, } uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { - xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; + xkb_mod_mask_t mask = kb->modifiers->depressed | kb->modifiers->latched; uint32_t modifiers = 0; for (size_t i = 0; i < WLR_MODIFIER_COUNT; ++i) { if (kb->mod_indexes[i] != XKB_MOD_INVALID && diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 79638822..8c5519b6 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -291,8 +291,9 @@ static void default_keyboard_key(struct wlr_seat_keyboard_grab *grab, wlr_seat_keyboard_send_key(grab->seat, time, key, state); } -static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab) { - wlr_seat_keyboard_send_modifiers(grab->seat); +static void default_keyboard_modifiers(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_send_modifiers(grab->seat, modifiers); } static void default_keyboard_cancel(struct wlr_seat_keyboard_grab *grab) { @@ -796,6 +797,10 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat->keyboard_state.keyboard = keyboard; } +struct wlr_keyboard *wlr_seat_get_keyboard(struct wlr_seat *seat) { + return seat->keyboard_state.keyboard; +} + void wlr_seat_keyboard_start_grab(struct wlr_seat *wlr_seat, struct wlr_seat_keyboard_grab *grab) { grab->seat = wlr_seat; @@ -834,23 +839,19 @@ static void keyboard_resource_destroy_notify(struct wl_listener *listener, wlr_seat_keyboard_clear_focus(state->seat); } -void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat) { +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers) { struct wlr_seat_client *client = seat->keyboard_state.focused_client; if (client == NULL) { return; } - struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard; - if (keyboard == NULL) { - return; - } - uint32_t serial = wl_display_next_serial(seat->display); struct wl_resource *resource; wl_resource_for_each(resource, &client->keyboards) { wl_keyboard_send_modifiers(resource, serial, - keyboard->modifiers.depressed, keyboard->modifiers.latched, - keyboard->modifiers.locked, keyboard->modifiers.group); + modifiers->depressed, modifiers->latched, + modifiers->locked, modifiers->group); } } @@ -930,7 +931,8 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, if (client != NULL && seat->keyboard_state.keyboard != NULL) { // tell new client about any modifier change last, // as it targets seat->keyboard_state.focused_client - wlr_seat_keyboard_send_modifiers(seat); + wlr_seat_keyboard_send_modifiers(seat, + seat->keyboard_state.keyboard->modifiers); } } @@ -950,10 +952,11 @@ bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) { return seat->keyboard_state.grab->interface != &default_keyboard_grab_impl; } -void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat) { +void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, + struct wlr_keyboard_modifiers *modifiers) { clock_gettime(CLOCK_MONOTONIC, &seat->last_event); struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; - grab->interface->modifiers(grab); + grab->interface->modifiers(grab, modifiers); } void wlr_seat_keyboard_notify_key(struct wlr_seat *seat, uint32_t time, diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 1c46197e..fd09b467 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -112,8 +112,9 @@ static void xdg_keyboard_grab_key(struct wlr_seat_keyboard_grab *grab, uint32_t wlr_seat_keyboard_send_key(grab->seat, time, key, state); } -static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab) { - wlr_seat_keyboard_send_modifiers(grab->seat); +static void xdg_keyboard_grab_modifiers(struct wlr_seat_keyboard_grab *grab, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_send_modifiers(grab->seat, modifiers); } static void xdg_keyboard_grab_cancel(struct wlr_seat_keyboard_grab *grab) {