From cef1f60522141f3e1a4fe5278d89bb77118735d4 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 22 Sep 2017 16:07:00 -0400 Subject: wlr-seat-keyboard: basic events --- include/wlr/types/wlr_seat.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include') diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index aa17d650..15aa6ad8 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -30,6 +30,15 @@ struct wlr_seat_pointer_state { struct wl_listener focus_resource_destroy_listener; }; +struct wlr_seat_keyboard_state { + struct wlr_seat *wlr_seat; + struct wlr_seat_handle *focused_handle; + struct wlr_surface *focused_surface; + + struct wl_listener focus_surface_destroy_listener; + struct wl_listener focus_resource_destroy_listener; +}; + struct wlr_seat { struct wl_global *wl_global; struct wl_display *display; @@ -39,6 +48,7 @@ struct wlr_seat { struct wlr_data_device *data_device; struct wlr_seat_pointer_state pointer_state; + struct wlr_seat_keyboard_state keyboard_state; struct { struct wl_signal client_bound; @@ -112,4 +122,24 @@ uint32_t wlr_seat_pointer_send_button(struct wlr_seat *wlr_seat, uint32_t time, void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, enum wlr_axis_orientation orientation, double value); +/** + * Send a keyboard enter event to the given surface and consider it to be the + * focused surface for the keyboard. This will send a leave event to the last + * surface that was entered. + */ +void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, + struct wlr_surface *surface); + +/** + * Clear the focused surface for the keyboard and leave all entered surfaces. + */ +void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); + +/** + * Send a key event to the surface with keyboard focus. Returns the event + * serial. + */ +uint32_t wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time, + uint32_t key, uint32_t state); + #endif -- cgit v1.2.3 From 30b5d764265b689d6247a04e9bbef8efb0204e2f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 22 Sep 2017 17:09:47 -0400 Subject: wlr-seat: keyboard modifiers --- examples/compositor.c | 11 +++++++++++ include/wlr/types/wlr_seat.h | 8 ++++++++ types/wlr_seat.c | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) (limited to 'include') diff --git a/examples/compositor.c b/examples/compositor.c index cd334dc6..0d0df88c 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -343,6 +343,17 @@ static void handle_keyboard_key(struct keyboard_state *keyboard, struct compositor_state *state = keyboard->compositor; struct sample_state *sample = state->data; + uint32_t depressed = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_DEPRESSED); + uint32_t latched = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LATCHED); + uint32_t locked = xkb_state_serialize_mods(keyboard->xkb_state, + XKB_STATE_MODS_LOCKED); + uint32_t group = xkb_state_serialize_layout(keyboard->xkb_state, + XKB_STATE_LAYOUT_EFFECTIVE); + + wlr_seat_keyboard_send_modifiers(sample->wl_seat, depressed, latched, + locked, group); wlr_seat_keyboard_send_key(sample->wl_seat, (uint32_t)time_usec, keycode, key_state); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 15aa6ad8..21f2350d 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -142,4 +142,12 @@ void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat); uint32_t wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time, uint32_t key, uint32_t state); +/** + * Send the modifiers event to the surface with keyboard focus. Also sends the + * event to the surface with pointer focus. + */ +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *wlr_seat, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group); + #endif diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 2aa94922..d0955959 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -481,3 +481,30 @@ uint32_t wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time, return serial; } + +void wlr_seat_keyboard_send_modifiers(struct wlr_seat *wlr_seat, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) { + uint32_t serial = 0; + struct wl_resource *keyboard; + + if (wlr_seat_keyboard_has_focus_resource(wlr_seat)) { + serial = wl_display_next_serial(wlr_seat->display); + keyboard = wlr_seat->keyboard_state.focused_handle->keyboard; + wl_keyboard_send_modifiers(keyboard, serial, mods_depressed, + mods_latched, mods_locked, group); + } + + if (wlr_seat_pointer_has_focus_resource(wlr_seat) && + wlr_seat->pointer_state.focused_handle->keyboard && + wlr_seat->pointer_state.focused_handle != + wlr_seat->keyboard_state.focused_handle) { + if (serial == 0) { + serial = wl_display_next_serial(wlr_seat->display); + } + keyboard = wlr_seat->pointer_state.focused_handle->keyboard; + + wl_keyboard_send_modifiers(keyboard, serial, mods_depressed, + mods_latched, mods_locked, group); + } +} -- cgit v1.2.3 From 389559399830c89eee01028a9029f1f3a49a8455 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 23 Sep 2017 13:21:57 -0400 Subject: wlr-seat: keyboard layout --- examples/compositor.c | 19 ++++--------------- include/wlr/types/wlr_seat.h | 9 +++++++++ types/wlr_seat.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/examples/compositor.c b/examples/compositor.c index 0d0df88c..e09fdc14 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -362,19 +362,6 @@ static void handle_keyboard_key(struct keyboard_state *keyboard, } } -static void handle_keyboard_bound(struct wl_listener *listener, void *data) { - struct wlr_seat_handle *handle = data; - struct sample_state *state = - wl_container_of(listener, state, keyboard_bound); - - wl_keyboard_send_keymap(handle->keyboard, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, - state->keymap_fd, state->keymap_size); - - if (wl_resource_get_version(handle->keyboard) >= 2) { - wl_keyboard_send_repeat_info(handle->keyboard, 25, 600); - } -} - static struct wlr_xdg_surface_v6 *example_xdg_surface_at( struct sample_state *sample, int lx, int ly) { struct wlr_xdg_surface_v6 *xdg_surface; @@ -654,8 +641,6 @@ int main(int argc, char *argv[]) { state.wl_seat = wlr_seat_create(compositor.display, "seat0"); assert(state.wl_seat); - state.keyboard_bound.notify = handle_keyboard_bound; - wl_signal_add(&state.wl_seat->events.keyboard_bound, &state.keyboard_bound); wlr_seat_set_capabilities(state.wl_seat, WL_SEAT_CAPABILITY_KEYBOARD | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH); @@ -672,6 +657,10 @@ int main(int argc, char *argv[]) { free(keymap); break; } + + wlr_seat_keyboard_set_keymap(state.wl_seat, state.keymap_fd, + state.keymap_size); + state.xwayland = wlr_xwayland_create(compositor.display, state.wlr_compositor); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 21f2350d..c6bab180 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -35,6 +35,9 @@ struct wlr_seat_keyboard_state { struct wlr_seat_handle *focused_handle; struct wlr_surface *focused_surface; + int keymap_fd; + size_t keymap_size; + struct wl_listener focus_surface_destroy_listener; struct wl_listener focus_resource_destroy_listener; }; @@ -150,4 +153,10 @@ void wlr_seat_keyboard_send_modifiers(struct wlr_seat *wlr_seat, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group); +/** + * Set the keymap and send it to seat keyboard resources. + */ +void wlr_seat_keyboard_set_keymap(struct wlr_seat *wlr_seat, int keymap_fd, + size_t keymap_size); + #endif diff --git a/types/wlr_seat.c b/types/wlr_seat.c index d0955959..1028cf09 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -70,7 +70,7 @@ static void wl_seat_get_keyboard(struct wl_client *client, } if (handle->keyboard) { // TODO: this is probably a protocol violation but it simplifies our - // code and it'd be stupid for clients to create several pointers for + // code and it'd be stupid for clients to create several keyboards for // the same seat wl_resource_destroy(handle->keyboard); } @@ -78,6 +78,20 @@ static void wl_seat_get_keyboard(struct wl_client *client, wl_resource_get_version(_handle), id); wl_resource_set_implementation(handle->keyboard, &wl_keyboard_impl, handle, &wl_keyboard_destroy); + + if (wl_resource_get_version(handle->keyboard) >= + WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { + wl_keyboard_send_repeat_info(handle->keyboard, 25, 600); + } + + if (handle->wlr_seat->keyboard_state.keymap_size) { + // TODO: handle no keymap + wl_keyboard_send_keymap(handle->keyboard, + WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, + handle->wlr_seat->keyboard_state.keymap_fd, + handle->wlr_seat->keyboard_state.keymap_size); + } + wl_signal_emit(&handle->wlr_seat->events.keyboard_bound, handle); } @@ -508,3 +522,18 @@ void wlr_seat_keyboard_send_modifiers(struct wlr_seat *wlr_seat, mods_latched, mods_locked, group); } } + +void wlr_seat_keyboard_set_keymap(struct wlr_seat *wlr_seat, int keymap_fd, + size_t keymap_size) { + // TODO: we probably should wait to send the keymap if keys are pressed + struct wlr_seat_handle *handle; + wl_list_for_each(handle, &wlr_seat->handles, link) { + if (handle->keyboard) { + wl_keyboard_send_keymap(handle->keyboard, + WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size); + } + } + + wlr_seat->keyboard_state.keymap_fd = keymap_fd; + wlr_seat->keyboard_state.keymap_size = keymap_size; +} -- cgit v1.2.3 From 84a8f1b42dbd1882bef295cff66cd0c24afeb978 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 23 Sep 2017 14:40:56 -0400 Subject: add keys array param to seat keyboard enter --- examples/compositor.c | 5 ++++- include/wlr/types/wlr_seat.h | 4 ++-- types/wlr_seat.c | 9 ++++----- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/examples/compositor.c b/examples/compositor.c index e09fdc14..8154c2e3 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -129,7 +129,10 @@ static void example_set_focused_surface(struct sample_state *sample, } if (surface) { - wlr_seat_keyboard_enter(sample->wl_seat, surface->surface); + // TODO: send array of currently pressed keys + struct wl_array keys; + wl_array_init(&keys); + wlr_seat_keyboard_enter(sample->wl_seat, surface->surface, keys); } else { wlr_seat_keyboard_clear_focus(sample->wl_seat); } diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index c6bab180..a8df7131 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -128,10 +128,10 @@ void wlr_seat_pointer_send_axis(struct wlr_seat *wlr_seat, uint32_t time, /** * Send a keyboard enter event to the given surface and consider it to be the * focused surface for the keyboard. This will send a leave event to the last - * surface that was entered. + * surface that was entered. Pass an array of currently pressed keys. */ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface); + struct wlr_surface *surface, struct wl_array keys); /** * Clear the focused surface for the keyboard and leave all entered surfaces. diff --git a/types/wlr_seat.c b/types/wlr_seat.c index fc3b1c76..1d544902 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -414,7 +414,7 @@ static void handle_keyboard_focus_resource_destroyed( } void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, - struct wlr_surface *surface) { + struct wlr_surface *surface, struct wl_array keys) { if (wlr_seat->keyboard_state.focused_surface == surface) { // this surface already got an enter notify return; @@ -442,9 +442,6 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, // enter the current surface if (handle && handle->keyboard) { uint32_t serial = wl_display_next_serial(wlr_seat->display); - // TODO: send currently pressed keys - struct wl_array keys; - wl_array_init(&keys); wl_keyboard_send_enter(handle->keyboard, serial, surface->resource, &keys); @@ -475,7 +472,9 @@ void wlr_seat_keyboard_enter(struct wlr_seat *wlr_seat, } void wlr_seat_keyboard_clear_focus(struct wlr_seat *wlr_seat) { - wlr_seat_keyboard_enter(wlr_seat, NULL); + struct wl_array keys; + wl_array_init(&keys); + wlr_seat_keyboard_enter(wlr_seat, NULL, keys); } static bool wlr_seat_keyboard_has_focus_resource(struct wlr_seat *wlr_seat) { -- cgit v1.2.3