diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-09-23 13:21:57 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-09-23 14:09:54 -0400 |
commit | 389559399830c89eee01028a9029f1f3a49a8455 (patch) | |
tree | 61e898e4dfcdb3a42ad00fc26557899557489422 | |
parent | 30b5d764265b689d6247a04e9bbef8efb0204e2f (diff) |
wlr-seat: keyboard layout
-rw-r--r-- | examples/compositor.c | 19 | ||||
-rw-r--r-- | include/wlr/types/wlr_seat.h | 9 | ||||
-rw-r--r-- | types/wlr_seat.c | 31 |
3 files changed, 43 insertions, 16 deletions
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; +} |