diff options
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r-- | sway/input/seat.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c index f28c1cb9..a4118a18 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
2 | #include <linux/input-event-codes.h> | 3 | #include <linux/input-event-codes.h> |
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
@@ -85,6 +86,38 @@ static void seat_send_activate(struct sway_node *node, struct sway_seat *seat) { | |||
85 | } | 86 | } |
86 | } | 87 | } |
87 | 88 | ||
89 | static struct sway_keyboard *sway_keyboard_for_wlr_keyboard( | ||
90 | struct sway_seat *seat, struct wlr_keyboard *wlr_keyboard) { | ||
91 | struct sway_seat_device *seat_device; | ||
92 | wl_list_for_each(seat_device, &seat->devices, link) { | ||
93 | struct sway_input_device *input_device = seat_device->input_device; | ||
94 | if (input_device->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { | ||
95 | continue; | ||
96 | } | ||
97 | if (input_device->wlr_device->keyboard == wlr_keyboard) { | ||
98 | return seat_device->keyboard; | ||
99 | } | ||
100 | } | ||
101 | return NULL; | ||
102 | } | ||
103 | |||
104 | static void seat_keyboard_notify_enter(struct sway_seat *seat, | ||
105 | struct wlr_surface *surface) { | ||
106 | struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | ||
107 | if (!keyboard) { | ||
108 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface, NULL, 0, NULL); | ||
109 | return; | ||
110 | } | ||
111 | |||
112 | struct sway_keyboard *sway_keyboard = | ||
113 | sway_keyboard_for_wlr_keyboard(seat, keyboard); | ||
114 | assert(sway_keyboard && "Cannot find sway_keyboard for seat keyboard"); | ||
115 | |||
116 | struct sway_shortcut_state *state = &sway_keyboard->state_pressed_sent; | ||
117 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface, | ||
118 | state->pressed_keycodes, state->npressed, &keyboard->modifiers); | ||
119 | } | ||
120 | |||
88 | /** | 121 | /** |
89 | * If con is a view, set it as active and enable keyboard input. | 122 | * If con is a view, set it as active and enable keyboard input. |
90 | * If con is a container, set all child views as active and don't enable | 123 | * If con is a container, set all child views as active and don't enable |
@@ -103,15 +136,8 @@ static void seat_send_focus(struct sway_node *node, struct sway_seat *seat) { | |||
103 | wlr_xwayland_set_seat(xwayland, seat->wlr_seat); | 136 | wlr_xwayland_set_seat(xwayland, seat->wlr_seat); |
104 | } | 137 | } |
105 | #endif | 138 | #endif |
106 | struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | 139 | |
107 | if (keyboard) { | 140 | seat_keyboard_notify_enter(seat, view->surface); |
108 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, | ||
109 | view->surface, keyboard->keycodes, | ||
110 | keyboard->num_keycodes, &keyboard->modifiers); | ||
111 | } else { | ||
112 | wlr_seat_keyboard_notify_enter( | ||
113 | seat->wlr_seat, view->surface, NULL, 0, NULL); | ||
114 | } | ||
115 | 141 | ||
116 | struct wlr_pointer_constraint_v1 *constraint = | 142 | struct wlr_pointer_constraint_v1 *constraint = |
117 | wlr_pointer_constraints_v1_constraint_for_surface( | 143 | wlr_pointer_constraints_v1_constraint_for_surface( |
@@ -578,8 +604,6 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
578 | if (!seat_device->keyboard) { | 604 | if (!seat_device->keyboard) { |
579 | sway_keyboard_create(seat, seat_device); | 605 | sway_keyboard_create(seat, seat_device); |
580 | } | 606 | } |
581 | struct wlr_keyboard *wlr_keyboard = | ||
582 | seat_device->input_device->wlr_device->keyboard; | ||
583 | sway_keyboard_configure(seat_device->keyboard); | 607 | sway_keyboard_configure(seat_device->keyboard); |
584 | wlr_seat_set_keyboard(seat->wlr_seat, | 608 | wlr_seat_set_keyboard(seat->wlr_seat, |
585 | seat_device->input_device->wlr_device); | 609 | seat_device->input_device->wlr_device); |
@@ -587,9 +611,7 @@ static void seat_configure_keyboard(struct sway_seat *seat, | |||
587 | if (focus && node_is_view(focus)) { | 611 | if (focus && node_is_view(focus)) { |
588 | // force notify reenter to pick up the new configuration | 612 | // force notify reenter to pick up the new configuration |
589 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); | 613 | wlr_seat_keyboard_clear_focus(seat->wlr_seat); |
590 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, | 614 | seat_keyboard_notify_enter(seat, focus->sway_container->view->surface); |
591 | focus->sway_container->view->surface, wlr_keyboard->keycodes, | ||
592 | wlr_keyboard->num_keycodes, &wlr_keyboard->modifiers); | ||
593 | } | 615 | } |
594 | } | 616 | } |
595 | 617 | ||
@@ -1049,13 +1071,7 @@ void seat_set_focus_surface(struct sway_seat *seat, | |||
1049 | seat_send_unfocus(focus, seat); | 1071 | seat_send_unfocus(focus, seat); |
1050 | seat->has_focus = false; | 1072 | seat->has_focus = false; |
1051 | } | 1073 | } |
1052 | struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); | 1074 | seat_keyboard_notify_enter(seat, surface); |
1053 | if (keyboard) { | ||
1054 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface, | ||
1055 | keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); | ||
1056 | } else { | ||
1057 | wlr_seat_keyboard_notify_enter(seat->wlr_seat, surface, NULL, 0, NULL); | ||
1058 | } | ||
1059 | } | 1075 | } |
1060 | 1076 | ||
1061 | void seat_set_focus_layer(struct sway_seat *seat, | 1077 | void seat_set_focus_layer(struct sway_seat *seat, |