aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/compositor.c11
-rw-r--r--include/wlr/types/wlr_seat.h8
-rw-r--r--types/wlr_seat.c27
3 files changed, 46 insertions, 0 deletions
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);
+ }
+}