wlr-seat: keyboard modifiers

This commit is contained in:
Tony Crisci 2017-09-22 17:09:47 -04:00
parent cef1f60522
commit 30b5d76426
3 changed files with 46 additions and 0 deletions

View File

@ -343,6 +343,17 @@ static void handle_keyboard_key(struct keyboard_state *keyboard,
struct compositor_state *state = keyboard->compositor; struct compositor_state *state = keyboard->compositor;
struct sample_state *sample = state->data; 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, wlr_seat_keyboard_send_key(sample->wl_seat, (uint32_t)time_usec, keycode,
key_state); key_state);

View File

@ -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 wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time,
uint32_t key, uint32_t state); 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 #endif

View File

@ -481,3 +481,30 @@ uint32_t wlr_seat_keyboard_send_key(struct wlr_seat *wlr_seat, uint32_t time,
return serial; 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);
}
}