mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-07 13:29:49 -05:00
wlr-seat-keyboard: basic events
This commit is contained in:
parent
06ae9e7c9f
commit
cef1f60522
7 changed files with 159 additions and 43 deletions
|
|
@ -128,6 +128,12 @@ static void example_set_focused_surface(struct sample_state *sample,
|
|||
}
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
wlr_seat_keyboard_enter(sample->wl_seat, surface->surface);
|
||||
} else {
|
||||
wlr_seat_keyboard_clear_focus(sample->wl_seat);
|
||||
}
|
||||
|
||||
sample->focused_surface = surface;
|
||||
}
|
||||
|
||||
|
|
@ -332,45 +338,13 @@ static void handle_output_frame(struct output_state *output,
|
|||
}
|
||||
|
||||
static void handle_keyboard_key(struct keyboard_state *keyboard,
|
||||
uint32_t keycode, xkb_keysym_t sym, enum wlr_key_state key_state) {
|
||||
uint32_t keycode, xkb_keysym_t sym, enum wlr_key_state key_state,
|
||||
uint64_t time_usec) {
|
||||
struct compositor_state *state = keyboard->compositor;
|
||||
struct sample_state *sample = state->data;
|
||||
|
||||
struct wl_resource *res = NULL;
|
||||
struct wlr_seat_handle *seat_handle = NULL;
|
||||
wl_list_for_each(res, &sample->wlr_compositor->surfaces, link) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (res) {
|
||||
seat_handle = wlr_seat_handle_for_client(sample->wl_seat,
|
||||
wl_resource_get_client(res));
|
||||
}
|
||||
|
||||
if (res != sample->focus && seat_handle && seat_handle->keyboard) {
|
||||
struct wl_array keys;
|
||||
wl_array_init(&keys);
|
||||
uint32_t serial = wl_display_next_serial(state->display);
|
||||
wl_keyboard_send_enter(seat_handle->keyboard, serial, res, &keys);
|
||||
sample->focus = res;
|
||||
}
|
||||
|
||||
if (seat_handle && seat_handle->keyboard) {
|
||||
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);
|
||||
uint32_t modifiers_serial = wl_display_next_serial(state->display);
|
||||
uint32_t key_serial = wl_display_next_serial(state->display);
|
||||
wl_keyboard_send_modifiers(seat_handle->keyboard, modifiers_serial,
|
||||
depressed, latched, locked, group);
|
||||
wl_keyboard_send_key(seat_handle->keyboard, key_serial, 0, keycode,
|
||||
key_state);
|
||||
}
|
||||
wlr_seat_keyboard_send_key(sample->wl_seat, (uint32_t)time_usec, keycode,
|
||||
key_state);
|
||||
|
||||
if (sym == XKB_KEY_Super_L || sym == XKB_KEY_Super_R) {
|
||||
sample->mod_down = key_state == WLR_KEY_PRESSED;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue