remove ia64 keywords
[gentoo-zh.git] / gui-wm / swayfx / files / swayfx-0.3.2-im.patch
blobd5980c21247a6295a438bbad167df148c87e653a
1 From c9b99f407feab95418411ab20df5b0bfe167703a Mon Sep 17 00:00:00 2001
2 From: ShootingStarDragons <ShootingStarDragons@protonmail.com>
3 Date: Wed, 3 May 2023 14:21:27 +0800
4 Subject: [PATCH] swayfx-im
6 ---
7 .gitignore | 1 +
8 include/sway/input/text_input.h | 24 +++
9 include/sway/output.h | 4 +
10 sway/desktop/output.c | 30 +++
11 sway/desktop/render.c | 17 +-
12 sway/input/cursor.c | 26 +++
13 sway/input/text_input.c | 351 +++++++++++++++++++++++++++++++-
14 sway/tree/container.c | 3 +
15 sway/tree/view.c | 3 +
16 9 files changed, 451 insertions(+), 8 deletions(-)
18 diff --git a/.gitignore b/.gitignore
19 index ba02e504c..0a1a8eed8 100644
20 --- a/.gitignore
21 +++ b/.gitignore
22 @@ -14,3 +14,4 @@ config-debug
23 wayland-*-protocol.*
24 /subprojects/wlroots
25 subprojects
26 +.cache
27 diff --git a/include/sway/input/text_input.h b/include/sway/input/text_input.h
28 index c70fd935b..f1c08f6be 100644
29 --- a/include/sway/input/text_input.h
30 +++ b/include/sway/input/text_input.h
31 @@ -22,18 +22,37 @@ struct sway_input_method_relay {
32 struct sway_seat *seat;
34 struct wl_list text_inputs; // sway_text_input::link
35 + struct wl_list input_popups; // sway_input_popup::link
36 struct wlr_input_method_v2 *input_method; // doesn't have to be present
38 struct wl_listener text_input_new;
40 struct wl_listener input_method_new;
41 struct wl_listener input_method_commit;
42 + struct wl_listener input_method_new_popup_surface;
43 struct wl_listener input_method_grab_keyboard;
44 struct wl_listener input_method_destroy;
46 struct wl_listener input_method_keyboard_grab_destroy;
49 +struct sway_input_popup {
50 + struct sway_input_method_relay *relay;
51 + struct wlr_input_popup_surface_v2 *popup_surface;
53 + int x, y;
54 + bool visible;
56 + struct wl_list link;
58 + struct wl_listener popup_map;
59 + struct wl_listener popup_unmap;
60 + struct wl_listener popup_destroy;
61 + struct wl_listener popup_surface_commit;
63 + struct wl_listener focused_surface_unmap;
64 +};
66 struct sway_text_input {
67 struct sway_input_method_relay *relay;
69 @@ -66,4 +85,9 @@ struct sway_text_input *sway_text_input_create(
70 struct sway_input_method_relay *relay,
71 struct wlr_text_input_v3 *text_input);
73 +bool sway_input_popup_get_position(
74 + struct sway_input_popup *popup, int *lx, int *ly);
76 +void sway_input_popup_damage(struct sway_input_popup *popup);
78 #endif
79 diff --git a/include/sway/output.h b/include/sway/output.h
80 index 3215c8531..b2e1f60b7 100644
81 --- a/include/sway/output.h
82 +++ b/include/sway/output.h
83 @@ -154,6 +154,10 @@ void output_unmanaged_for_each_surface(struct sway_output *output,
84 void *user_data);
85 #endif
87 +void output_input_popups_for_each_surface(struct sway_output *output,
88 + struct wl_list *input_popups, sway_surface_iterator_func_t iterator,
89 + void *user_data);
91 void output_drag_icons_for_each_surface(struct sway_output *output,
92 struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
93 void *user_data);
94 diff --git a/sway/desktop/output.c b/sway/desktop/output.c
95 index c41088acc..727fda29f 100644
96 --- a/sway/desktop/output.c
97 +++ b/sway/desktop/output.c
98 @@ -22,6 +22,8 @@
99 #include "sway/desktop/transaction.h"
100 #include "sway/input/input-manager.h"
101 #include "sway/input/seat.h"
102 +#include "sway/input/text_input.h"
103 +#include "sway/ipc-server.h"
104 #include "sway/layers.h"
105 #include "sway/output.h"
106 #include "sway/server.h"
107 @@ -254,6 +256,31 @@ void output_unmanaged_for_each_surface(struct sway_output *output,
109 #endif
111 +void output_input_popups_for_each_surface(struct sway_output *output,
112 + struct wl_list *input_popups, sway_surface_iterator_func_t iterator,
113 + void *user_data) {
114 + struct sway_input_popup *popup;
115 + wl_list_for_each(popup, input_popups, link) {
116 + int lx, ly;
117 + if (!sway_input_popup_get_position(popup, &lx, &ly)) {
118 + continue;
120 + if (!popup->popup_surface->mapped || !popup->visible) {
121 + continue;
124 + // damage the popup if surface is updated
125 + sway_input_popup_damage(popup);
127 + double ox = lx - output->lx;
128 + double oy = ly - output->ly;
130 + output_surface_for_each_surface(output,
131 + popup->popup_surface->surface, ox, oy,
132 + iterator, user_data);
136 void output_drag_icons_for_each_surface(struct sway_output *output,
137 struct wl_list *drag_icons, sway_surface_iterator_func_t iterator,
138 void *user_data) {
139 @@ -364,6 +391,9 @@ static void output_for_each_surface(struct sway_output *output,
140 output_layer_for_each_surface(output,
141 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY],
142 iterator, user_data);
143 + output_input_popups_for_each_surface(
144 + output, &input_manager_current_seat()->im_relay.input_popups,
145 + iterator, user_data);
146 output_drag_icons_for_each_surface(output, &root->drag_icons,
147 iterator, user_data);
149 diff --git a/sway/desktop/render.c b/sway/desktop/render.c
150 index 43abc81c2..d9565e54d 100644
151 --- a/sway/desktop/render.c
152 +++ b/sway/desktop/render.c
153 @@ -526,6 +526,16 @@ static void render_unmanaged(struct sway_output *output,
155 #endif
157 +static void render_input_popups(struct sway_output *output,
158 + pixman_region32_t *damage, struct wl_list *input_popups) {
159 + struct render_data data = {
160 + .damage = damage,
161 + .deco_data = get_undecorated_decoration_data(),
162 + };
163 + output_input_popups_for_each_surface(output, input_popups,
164 + render_surface_iterator, &data);
167 static void render_drag_icons(struct sway_output *output,
168 pixman_region32_t *damage, struct wl_list *drag_icons) {
169 struct render_data data = {
170 @@ -1859,6 +1869,10 @@ void output_render(struct sway_output *output, struct timespec *when,
171 goto renderer_end;
174 + struct sway_seat *seat = input_manager_current_seat();
175 + struct sway_container *focus = seat_get_focused_container(seat);
176 + // here use seat
178 if (output_has_opaque_overlay_layer_surface(output)) {
179 goto render_overlay;
181 @@ -1986,8 +2000,6 @@ void output_render(struct sway_output *output, struct timespec *when,
183 render_seatops(output, damage);
185 - struct sway_seat *seat = input_manager_current_seat();
186 - struct sway_container *focus = seat_get_focused_container(seat);
187 if (focus && focus->view) {
188 struct decoration_data deco_data = {
189 .alpha = focus->alpha,
190 @@ -2010,6 +2022,7 @@ void output_render(struct sway_output *output, struct timespec *when,
191 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
192 render_layer_popups(output, damage,
193 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
194 + render_input_popups(output, damage, &seat->im_relay.input_popups);
195 render_drag_icons(output, damage, &root->drag_icons);
197 renderer_end:
198 diff --git a/sway/input/cursor.c b/sway/input/cursor.c
199 index a5f1204ba..ed2188cd4 100644
200 --- a/sway/input/cursor.c
201 +++ b/sway/input/cursor.c
202 @@ -37,6 +37,28 @@ static uint32_t get_current_time_msec(void) {
203 return now.tv_sec * 1000 + now.tv_nsec / 1000000;
206 +static struct wlr_surface *input_popup_surface_at(struct sway_output *output,
207 + struct sway_input_method_relay *relay, double ox, double oy, double *sx, double *sy) {
208 + struct sway_input_popup *popup;
209 + wl_list_for_each(popup, &relay->input_popups, link) {
210 + int lx, ly;
211 + if (!sway_input_popup_get_position(popup, &lx, &ly)) {
212 + continue;
214 + if (!popup->popup_surface->mapped || !popup->visible) {
215 + continue;
217 + double _sx = ox - lx;
218 + double _sy = oy - ly;
219 + struct wlr_surface *sub = wlr_surface_surface_at(
220 + popup->popup_surface->surface, _sx, _sy, sx, sy);
221 + if (sub) {
222 + return sub;
225 + return NULL;
228 static struct wlr_surface *layer_surface_at(struct sway_output *output,
229 struct wl_list *layer, double ox, double oy, double *sx, double *sy) {
230 struct sway_layer_surface *sway_layer;
231 @@ -122,6 +144,10 @@ struct sway_node *node_at_coords(
232 return NULL;
235 + if ((*surface = input_popup_surface_at(output,
236 + &seat->im_relay, ox, oy, sx, sy))) {
237 + return NULL;
239 // check for unmanaged views
240 #if HAVE_XWAYLAND
241 struct wl_list *unmanaged = &root->xwayland_unmanaged;
242 diff --git a/sway/input/text_input.c b/sway/input/text_input.c
243 index 58911c2de..9ddebb1b3 100644
244 --- a/sway/input/text_input.c
245 +++ b/sway/input/text_input.c
246 @@ -1,8 +1,16 @@
247 #include <assert.h>
248 +#include <stdio.h>
249 #include <stdlib.h>
250 #include "log.h"
251 #include "sway/input/seat.h"
252 #include "sway/input/text_input.h"
253 +#include "sway/tree/view.h"
254 +#include "sway/tree/container.h"
255 +#include "sway/desktop.h"
256 +#include "sway/output.h"
257 +#include "sway/layers.h"
259 +#define wlr_layer_surface_v1_try_from_wlr_surface(surface) (wlr_surface_is_layer_surface(surface) ? wlr_layer_surface_v1_from_wlr_surface(surface) : NULL)
261 static struct sway_text_input *relay_get_focusable_text_input(
262 struct sway_input_method_relay *relay) {
263 @@ -26,6 +34,328 @@ static struct sway_text_input *relay_get_focused_text_input(
264 return NULL;
267 +// damage the popup
268 +void sway_input_popup_damage(struct sway_input_popup *popup) {
269 + if (!popup->visible) {
270 + return;
273 + struct sway_text_input *text_input =
274 + relay_get_focused_text_input(popup->relay);
275 + if (text_input == NULL || text_input->input->focused_surface == NULL) {
276 + return;
279 + struct wlr_surface *focused_surface = text_input->input->focused_surface;
280 + struct wlr_layer_surface_v1 *layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
281 + if (layer_surface != NULL) {
282 + struct sway_layer_surface *layer =
283 + layer_from_wlr_layer_surface_v1(layer_surface);
284 + output_damage_surface(layer->layer_surface->output->data,
285 + layer->geo.x + popup->x, layer->geo.y + popup->y,
286 + popup->popup_surface->surface, true);
287 + return;
290 + struct sway_view *view = view_from_wlr_surface(
291 + text_input->input->focused_surface);
292 + if (view->container == NULL) {
293 + sway_log(SWAY_INFO, "Tried to damage popup, but view is gone");
294 + return;
296 + desktop_damage_surface(popup->popup_surface->surface,
297 + view->container->surface_x - view->geometry.x + popup->x,
298 + view->container->surface_y - view->geometry.y + popup->y, true);
301 +static void input_popup_update(struct sway_input_popup *popup) {
302 + sway_input_popup_damage(popup);
304 + struct sway_text_input *text_input =
305 + relay_get_focused_text_input(popup->relay);
307 + if (text_input == NULL || text_input->input->focused_surface == NULL) {
308 + return;
311 + if (!popup->popup_surface->mapped) {
312 + return;
315 + bool cursor_rect = text_input->input->current.features
316 + & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
317 + struct wlr_surface *focused_surface = text_input->input->focused_surface;
318 + struct wlr_box cursor = text_input->input->current.cursor_rectangle;
320 + struct wlr_output *output;
321 + struct wlr_box output_box;
322 + struct wlr_box parent;
323 + struct wlr_layer_surface_v1 *layer_surface =
324 + wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
325 + if (layer_surface != NULL) {
326 + struct sway_layer_surface *layer =
327 + layer_from_wlr_layer_surface_v1(layer_surface);
328 + output = layer->layer_surface->output;
329 + wlr_output_layout_get_box(root->output_layout, output, &output_box);
330 + parent = layer->geo;
331 + parent.x += output_box.x;
332 + parent.y += output_box.y;
333 + } else {
334 + struct sway_view *view = view_from_wlr_surface(focused_surface);
335 + output = wlr_output_layout_output_at(root->output_layout,
336 + view->container->surface_x + view->geometry.x,
337 + view->container->surface_y + view->geometry.y);
338 + wlr_output_layout_get_box(root->output_layout, output, &output_box);
339 + parent.x = view->container->surface_x + view->geometry.x;
340 + parent.y = view->container->surface_y + view->geometry.y;
341 + parent.width = view->geometry.width;
342 + parent.height = view->geometry.height;
345 + if (!cursor_rect) {
346 + cursor.x = 0;
347 + cursor.y = 0;
348 + cursor.width = parent.width;
349 + cursor.height = parent.height;
352 + int popup_width = popup->popup_surface->surface->current.width;
353 + int popup_height = popup->popup_surface->surface->current.height;
354 + int x1 = parent.x + cursor.x;
355 + int x2 = parent.x + cursor.x + cursor.width;
356 + int y1 = parent.y + cursor.y;
357 + int y2 = parent.y + cursor.y + cursor.height;
358 + int x = x1;
359 + int y = y2;
361 + int available_right = output_box.x + output_box.width - x1;
362 + int available_left = x2 - output_box.x;
363 + if (available_right < popup_width && available_left > available_right) {
364 + x = x2 - popup_width;
367 + int available_down = output_box.y + output_box.height - y2;
368 + int available_up = y1 - output_box.y;
369 + if (available_down < popup_height && available_up > available_down) {
370 + y = y1 - popup_height;
373 + popup->x = x - parent.x;
374 + popup->y = y - parent.y;
376 + // Hide popup if cursor position is completely out of bounds
377 + bool x1_in_bounds = (cursor.x >= 0 && cursor.x < parent.width);
378 + bool y1_in_bounds = (cursor.y >= 0 && cursor.y < parent.height);
379 + bool x2_in_bounds = (cursor.x + cursor.width >= 0
380 + && cursor.x + cursor.width < parent.width);
381 + bool y2_in_bounds = (cursor.y + cursor.height >= 0
382 + && cursor.y + cursor.height < parent.height);
383 + popup->visible =
384 + (x1_in_bounds && y1_in_bounds) || (x2_in_bounds && y2_in_bounds);
386 + if (cursor_rect) {
387 + struct wlr_box box = {
388 + .x = x1 - x,
389 + .y = y1 - y,
390 + .width = cursor.width,
391 + .height = cursor.height,
392 + };
393 + wlr_input_popup_surface_v2_send_text_input_rectangle(
394 + popup->popup_surface, &box);
397 + sway_input_popup_damage(popup);
400 +static void surface_send_enter_iterator(struct wlr_surface *surface,
401 + int x, int y, void *data) {
402 + struct wlr_output *wlr_output = data;
403 + wlr_surface_send_enter(surface, wlr_output);
406 +static void surface_send_leave_iterator(struct wlr_surface *surface,
407 + int x, int y, void *data) {
408 + struct wlr_output *wlr_output = data;
409 + wlr_surface_send_leave(surface, wlr_output);
412 +static void input_popup_send_outputs(struct sway_input_popup *popup,
413 + wlr_surface_iterator_func_t iterator) {
414 + struct sway_text_input *text_input =
415 + relay_get_focused_text_input(popup->relay);
416 + if (text_input == NULL || text_input->input->focused_surface == NULL) {
417 + return;
419 + struct wlr_surface *focused_surface = text_input->input->focused_surface;
420 + struct wlr_layer_surface_v1 *layer_surface =
421 + wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
422 + if (layer_surface != NULL) {
423 + struct sway_layer_surface *layer =
424 + layer_from_wlr_layer_surface_v1(layer_surface);
425 + wlr_surface_for_each_surface(popup->popup_surface->surface,
426 + iterator, layer->layer_surface->output);
427 + return;
429 + struct sway_view *view = view_from_wlr_surface(focused_surface);
430 + for (int i = 0; i < view->container->outputs->length; i++) {
431 + struct sway_output *output = view->container->outputs->items[i];
432 + wlr_surface_for_each_surface(popup->popup_surface->surface,
433 + iterator, output->wlr_output);
437 +static void handle_im_popup_map(struct wl_listener *listener, void *data) {
438 + struct sway_input_popup *popup =
439 + wl_container_of(listener, popup, popup_map);
440 + input_popup_send_outputs(popup, surface_send_enter_iterator);
441 + input_popup_update(popup);
444 +static void handle_im_popup_unmap(struct wl_listener *listener, void *data) {
445 + struct sway_input_popup *popup =
446 + wl_container_of(listener, popup, popup_unmap);
447 + input_popup_send_outputs(popup, surface_send_leave_iterator);
448 + input_popup_update(popup);
451 +static void handle_im_popup_destroy(struct wl_listener *listener, void *data) {
452 + struct sway_input_popup *popup =
453 + wl_container_of(listener, popup, popup_destroy);
454 + wl_list_remove(&popup->focused_surface_unmap.link);
455 + wl_list_remove(&popup->popup_surface_commit.link);
456 + wl_list_remove(&popup->popup_destroy.link);
457 + wl_list_remove(&popup->popup_unmap.link);
458 + wl_list_remove(&popup->popup_map.link);
459 + wl_list_remove(&popup->link);
460 + free(popup);
463 +static void handle_im_popup_surface_commit(struct wl_listener *listener,
464 + void *data) {
465 + struct sway_input_popup *popup =
466 + wl_container_of(listener, popup, popup_surface_commit);
467 + input_popup_update(popup);
470 +static void handle_im_focused_surface_unmap(
471 + struct wl_listener *listener, void *data) {
472 + struct sway_input_popup *popup =
473 + wl_container_of(listener, popup, focused_surface_unmap);
474 + input_popup_update(popup);
477 +static void input_popup_set_focus(struct sway_input_popup *popup,
478 + struct wlr_surface *surface) {
479 + wl_list_remove(&popup->focused_surface_unmap.link);
481 + if (surface == NULL) {
482 + wl_list_init(&popup->focused_surface_unmap.link);
483 + input_popup_update(popup);
484 + return;
486 + struct wlr_layer_surface_v1 *layer_surface =
487 + wlr_layer_surface_v1_try_from_wlr_surface(surface);
488 + if (layer_surface != NULL) {
489 + struct sway_layer_surface *layer =
490 + layer_from_wlr_layer_surface_v1(layer_surface);
491 + wl_signal_add(
492 + &layer->layer_surface->events.unmap, &popup->focused_surface_unmap);
493 + input_popup_update(popup);
494 + return;
497 + struct sway_view *view = view_from_wlr_surface(surface);
498 + wl_signal_add(&view->events.unmap, &popup->focused_surface_unmap);
500 + // Since the focus has changed, the popup may have to adjust
503 +static void handle_im_new_popup_surface(struct wl_listener *listener,
504 + void *data) {
505 + struct sway_input_method_relay *relay = wl_container_of(listener, relay,
506 + input_method_new_popup_surface);
507 + struct sway_input_popup *popup = calloc(1, sizeof(*popup));
508 + popup->relay = relay;
509 + popup->popup_surface = data;
510 + popup->popup_surface->data = popup;
512 + wl_signal_add(&popup->popup_surface->events.map, &popup->popup_map);
513 + popup->popup_map.notify = handle_im_popup_map;
514 + wl_signal_add(
515 + &popup->popup_surface->events.unmap, &popup->popup_unmap);
516 + popup->popup_unmap.notify = handle_im_popup_unmap;
517 + wl_signal_add(
518 + &popup->popup_surface->events.destroy, &popup->popup_destroy);
519 + popup->popup_destroy.notify = handle_im_popup_destroy;
520 + wl_signal_add(&popup->popup_surface->surface->events.commit,
521 + &popup->popup_surface_commit);
522 + popup->popup_surface_commit.notify = handle_im_popup_surface_commit;
523 + wl_list_init(&popup->focused_surface_unmap.link);
524 + popup->focused_surface_unmap.notify = handle_im_focused_surface_unmap;
526 + struct sway_text_input *text_input = relay_get_focused_text_input(relay);
527 + if (text_input != NULL) {
528 + input_popup_set_focus(popup, text_input->input->focused_surface);
529 + } else {
530 + input_popup_set_focus(popup, NULL);
533 + wl_list_insert(&relay->input_popups, &popup->link);
536 +bool sway_input_popup_get_position(
537 + struct sway_input_popup *popup, int *lx, int *ly) {
538 + struct sway_text_input *text_input =
539 + relay_get_focused_text_input(popup->relay);
540 + if (text_input == NULL || text_input->input->focused_surface == NULL) {
541 + *lx = 0;
542 + *ly = 0;
543 + return false;
546 + struct wlr_surface *focused_surface = text_input->input->focused_surface;
547 + struct wlr_layer_surface_v1 *layer_surface =
548 + wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
549 + if (layer_surface != NULL) {
550 + struct sway_layer_surface *layer =
551 + layer_from_wlr_layer_surface_v1(layer_surface);
552 + *lx = layer->geo.x + popup->x;
553 + *ly = layer->geo.y + popup->y;
554 + return true;
558 + struct sway_view *view = view_from_wlr_surface(
559 + text_input->input->focused_surface);
560 + if (view->container == NULL || view == NULL) {
561 + sway_log(SWAY_INFO, "Tried to find popup, but view is gone");
562 + return false;
564 + *lx = view->container->surface_x - view->geometry.x + popup->x;
565 + *ly = view->container->surface_y - view->geometry.y + popup->y;
566 + return true;
569 +static void text_input_send_enter(struct sway_text_input *text_input,
570 + struct wlr_surface *surface) {
571 + wlr_text_input_v3_send_enter(text_input->input, surface);
572 + struct sway_input_popup *popup;
573 + wl_list_for_each(popup, &text_input->relay->input_popups, link) {
574 + input_popup_set_focus(popup, surface);
578 +static void text_input_send_leave(struct sway_text_input *text_input,
579 + struct wlr_surface *surface) {
580 + wlr_text_input_v3_send_leave(text_input->input);
581 + if (text_input->input->focused_surface == surface) {
582 + struct sway_input_popup *popup;
583 + wl_list_for_each(popup, &text_input->relay->input_popups, link) {
584 + input_popup_set_focus(popup, NULL);
589 static void handle_im_commit(struct wl_listener *listener, void *data) {
590 struct sway_input_method_relay *relay = wl_container_of(listener, relay,
591 input_method_commit);
592 @@ -109,7 +439,7 @@ static void handle_im_destroy(struct wl_listener *listener, void *data) {
593 // the input method returns
594 text_input_set_pending_focused_surface(text_input,
595 text_input->input->focused_surface);
596 - wlr_text_input_v3_send_leave(text_input->input);
597 + text_input_send_leave(text_input, text_input->input->focused_surface);
601 @@ -133,8 +463,13 @@ static void relay_send_im_state(struct sway_input_method_relay *relay,
602 input->current.content_type.hint,
603 input->current.content_type.purpose);
605 + struct sway_input_popup *popup;
606 + wl_list_for_each(popup, &relay->input_popups, link) {
607 + // send_text_input_rectangle is called in this function
608 + input_popup_update(popup);
610 wlr_input_method_v2_send_done(input_method);
611 - // TODO: pass intent, display popup size
612 + // TODO: pass intent
615 static void handle_text_input_enable(struct wl_listener *listener, void *data) {
616 @@ -274,6 +609,9 @@ static void relay_handle_input_method(struct wl_listener *listener,
617 wl_signal_add(&relay->input_method->events.commit,
618 &relay->input_method_commit);
619 relay->input_method_commit.notify = handle_im_commit;
620 + wl_signal_add(&relay->input_method->events.new_popup_surface,
621 + &relay->input_method_new_popup_surface);
622 + relay->input_method_new_popup_surface.notify = handle_im_new_popup_surface;
623 wl_signal_add(&relay->input_method->events.grab_keyboard,
624 &relay->input_method_grab_keyboard);
625 relay->input_method_grab_keyboard.notify = handle_im_grab_keyboard;
626 @@ -283,8 +621,7 @@ static void relay_handle_input_method(struct wl_listener *listener,
628 struct sway_text_input *text_input = relay_get_focusable_text_input(relay);
629 if (text_input) {
630 - wlr_text_input_v3_send_enter(text_input->input,
631 - text_input->pending_focused_surface);
632 + text_input_send_enter(text_input, text_input->pending_focused_surface);
633 text_input_set_pending_focused_surface(text_input, NULL);
636 @@ -293,6 +630,7 @@ void sway_input_method_relay_init(struct sway_seat *seat,
637 struct sway_input_method_relay *relay) {
638 relay->seat = seat;
639 wl_list_init(&relay->text_inputs);
640 + wl_list_init(&relay->input_popups);
642 relay->text_input_new.notify = relay_handle_text_input;
643 wl_signal_add(&server.text_input->events.text_input,
644 @@ -321,8 +659,9 @@ void sway_input_method_relay_set_focus(struct sway_input_method_relay *relay,
645 } else if (text_input->input->focused_surface) {
646 assert(text_input->pending_focused_surface == NULL);
647 if (surface != text_input->input->focused_surface) {
648 + text_input_send_leave(
649 + text_input, text_input->input->focused_surface);
650 relay_disable_text_input(relay, text_input);
651 - wlr_text_input_v3_send_leave(text_input->input);
652 } else {
653 sway_log(SWAY_DEBUG, "IM relay set_focus already focused");
654 continue;
655 @@ -333,7 +672,7 @@ void sway_input_method_relay_set_focus(struct sway_input_method_relay *relay,
656 && wl_resource_get_client(text_input->input->resource)
657 == wl_resource_get_client(surface->resource)) {
658 if (relay->input_method) {
659 - wlr_text_input_v3_send_enter(text_input->input, surface);
660 + text_input_send_enter(text_input, surface);
661 } else {
662 text_input_set_pending_focused_surface(text_input, surface);
664 diff --git a/sway/tree/container.c b/sway/tree/container.c
665 index 2e61ff5c9..14d0e6079 100644
666 --- a/sway/tree/container.c
667 +++ b/sway/tree/container.c
668 @@ -400,6 +400,9 @@ static bool surface_is_popup(struct wlr_surface *surface) {
669 wlr_subsurface_from_wlr_surface(surface);
670 surface = subsurface->parent;
672 + if (wlr_surface_is_input_popup_surface_v2(surface)) {
673 + return true;
675 struct wlr_xdg_surface *xdg_surface =
676 wlr_xdg_surface_from_wlr_surface(surface);
677 return xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP;
678 diff --git a/sway/tree/view.c b/sway/tree/view.c
679 index 272967f4a..70d02a199 100644
680 --- a/sway/tree/view.c
681 +++ b/sway/tree/view.c
682 @@ -1249,6 +1249,9 @@ struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) {
683 if (wlr_surface_is_layer_surface(wlr_surface)) {
684 return NULL;
686 + if (wlr_surface_is_input_popup_surface_v2(wlr_surface)) {
687 + return NULL;
690 const char *role = wlr_surface->role ? wlr_surface->role->name : NULL;
691 sway_log(SWAY_DEBUG, "Surface of unknown type (role %s): %p",