From 0ef2df21f2943c3985fcc86f5f6c3289036be491 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 5 Jan 2018 07:00:50 -0500 Subject: compositor modifier hook --- include/wlr/types/wlr_keyboard.h | 14 ++++++++------ include/wlr/types/wlr_seat.h | 14 +++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'include') 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 -- cgit v1.2.3 From b40a5f084abeb5530b3a0097c946ba720c897262 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 6 Jan 2018 11:06:09 -0500 Subject: keyboard grab enter with modifiers --- include/wlr/types/wlr_seat.h | 13 ++++++++----- rootston/seat.c | 11 ++++++++++- types/wlr_data_device.c | 3 ++- types/wlr_seat.c | 45 +++++++++++++++++++++++--------------------- types/wlr_xdg_shell_v6.c | 4 +++- 5 files changed, 47 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index f5b4afde..c2a89f33 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -68,7 +68,8 @@ struct wlr_seat_keyboard_grab; struct wlr_keyboard_grab_interface { void (*enter)(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface); + struct wlr_surface *surface, uint32_t keycodes[], + size_t num_keycodes, struct wlr_keyboard_modifiers *modifiers); 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, @@ -396,8 +397,9 @@ void wlr_seat_keyboard_notify_modifiers(struct wlr_seat *seat, * focused surface for this keyboard. Defers to any current grab of the seat's * keyboard. */ -void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface); +void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers); /** * Send a keyboard enter event to the given surface and consider it to be the @@ -406,8 +408,9 @@ void wlr_seat_keyboard_notify_enter(struct wlr_seat *wlr_seat, * `wlr_seat_keyboard_notify_enter()` to change keyboard focus to respect * keyboard grabs. */ -void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface); +void wlr_seat_keyboard_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers); /** * Clear the focused surface for the keyboard and leave all entered surfaces. diff --git a/rootston/seat.c b/rootston/seat.c index 2728ca96..0972fce2 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -616,7 +616,16 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { seat->has_focus = true; wl_list_remove(&seat_view->link); wl_list_insert(&seat->views, &seat_view->link); - wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface); + + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); + if (keyboard != NULL) { + wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, + keyboard->keycodes, keyboard->num_keycodes, + keyboard->modifiers); + } else { + wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, + NULL, 0, NULL); + } } void roots_seat_cycle_focus(struct roots_seat *seat) { diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index 3c48119a..5a6bc198 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -585,7 +585,8 @@ const struct wlr_touch_grab_interface wlr_data_device_touch_drag_interface = { }; static void keyboard_drag_enter(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface) { + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { // nothing has keyboard focus during drags } diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 6ed92493..4378675c 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -282,8 +282,9 @@ static const struct wlr_pointer_grab_interface default_pointer_grab_impl = { }; static void default_keyboard_enter(struct wlr_seat_keyboard_grab *grab, - struct wlr_surface *surface) { - wlr_seat_keyboard_enter(grab->seat, surface); + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { + wlr_seat_keyboard_enter(grab->seat, surface, keycodes, num_keycodes, modifiers); } static void default_keyboard_key(struct wlr_seat_keyboard_grab *grab, @@ -851,14 +852,19 @@ void wlr_seat_keyboard_send_modifiers(struct wlr_seat *seat, 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, - modifiers->depressed, modifiers->latched, - modifiers->locked, modifiers->group); + if (modifiers == NULL) { + wl_keyboard_send_modifiers(resource, serial, 0, 0, 0, 0); + } else { + wl_keyboard_send_modifiers(resource, serial, + modifiers->depressed, modifiers->latched, + modifiers->locked, modifiers->group); + } } } void wlr_seat_keyboard_enter(struct wlr_seat *seat, - struct wlr_surface *surface) { + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { if (seat->keyboard_state.focused_surface == surface) { // this surface already got an enter notify return; @@ -886,19 +892,17 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, } // enter the current surface - if (client != NULL && seat->keyboard_state.keyboard != NULL) { - struct wlr_keyboard *keyboard = seat->keyboard_state.keyboard; - + if (client != NULL) { struct wl_array keys; wl_array_init(&keys); - for (size_t i = 0; i < keyboard->num_keycodes; ++i) { + for (size_t i = 0; i < num_keycodes; ++i) { uint32_t *p = wl_array_add(&keys, sizeof(uint32_t)); if (!p) { wlr_log(L_ERROR, "Cannot allocate memory, skipping keycode: %d\n", - keyboard->keycodes[i]); + keycodes[i]); continue; } - *p = keyboard->keycodes[i]; + *p = keycodes[i]; } uint32_t serial = wl_display_next_serial(seat->display); struct wl_resource *resource; @@ -930,24 +934,23 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, seat->keyboard_state.focused_client = client; seat->keyboard_state.focused_surface = surface; - if (client != NULL && seat->keyboard_state.keyboard != NULL) { + if (client != NULL) { // tell new client about any modifier change last, // as it targets seat->keyboard_state.focused_client - wlr_seat_keyboard_send_modifiers(seat, - seat->keyboard_state.keyboard->modifiers); + wlr_seat_keyboard_send_modifiers(seat, modifiers); } } -void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, struct - wlr_surface *surface) { +void wlr_seat_keyboard_notify_enter(struct wlr_seat *seat, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { struct wlr_seat_keyboard_grab *grab = seat->keyboard_state.grab; - grab->interface->enter(grab, surface); + grab->interface->enter(grab, surface, keycodes, num_keycodes, modifiers); } void wlr_seat_keyboard_clear_focus(struct wlr_seat *seat) { - struct wl_array keys; - wl_array_init(&keys); - wlr_seat_keyboard_enter(seat, NULL); + // TODO respect grabs here? + wlr_seat_keyboard_enter(seat, NULL, NULL, 0, NULL); } bool wlr_seat_keyboard_has_grab(struct wlr_seat *seat) { diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index fd09b467..59b152bd 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -103,7 +103,9 @@ static const struct wlr_pointer_grab_interface xdg_pointer_grab_impl = { .axis = xdg_pointer_grab_axis, }; -static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, struct wlr_surface *surface) { +static void xdg_keyboard_grab_enter(struct wlr_seat_keyboard_grab *grab, + struct wlr_surface *surface, uint32_t keycodes[], size_t num_keycodes, + struct wlr_keyboard_modifiers *modifiers) { // keyboard focus should remain on the popup } -- cgit v1.2.3 From b6f29e87e85b599170a0ffd1f4c94c46c216d51a Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 17 Jan 2018 08:31:15 -0500 Subject: dont use pointer for modifiers --- include/wlr/types/wlr_keyboard.h | 2 +- rootston/keyboard.c | 2 +- rootston/seat.c | 2 +- types/wlr_keyboard.c | 20 +++++++++----------- types/wlr_seat.c | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index b37797c8..c67cc4c2 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -52,7 +52,7 @@ struct wlr_keyboard { uint32_t keycodes[WLR_KEYBOARD_KEYS_CAP]; size_t num_keycodes; - struct wlr_keyboard_modifiers *modifiers; + struct wlr_keyboard_modifiers modifiers; struct { int32_t rate; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 09adea5a..f1123599 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -289,7 +289,7 @@ 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, - r_keyboard->device->keyboard->modifiers); + &r_keyboard->device->keyboard->modifiers); } static void keyboard_config_merge(struct roots_keyboard_config *config, diff --git a/rootston/seat.c b/rootston/seat.c index ed58e294..1a0e6253 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -667,7 +667,7 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { if (keyboard != NULL) { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, keyboard->keycodes, keyboard->num_keycodes, - keyboard->modifiers); + &keyboard->modifiers); } else { wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface, NULL, 0, NULL); diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 5a90e6b2..b0dc97aa 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -42,17 +42,17 @@ static bool 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 false; } - 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; return true; } @@ -138,7 +138,6 @@ 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); @@ -161,7 +160,6 @@ 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); } @@ -259,7 +257,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 4378675c..019cb567 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -794,7 +794,7 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat, seat_client_send_repeat_info(client, keyboard); } - wlr_seat_keyboard_send_modifiers(seat, keyboard->modifiers); + wlr_seat_keyboard_send_modifiers(seat, &keyboard->modifiers); } else { seat->keyboard_state.keyboard = NULL; } -- cgit v1.2.3