mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
wlr-seat: keyboard layout
This commit is contained in:
parent
30b5d76426
commit
3895593998
3 changed files with 43 additions and 16 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue