aboutsummaryrefslogtreecommitdiffstats
path: root/sway/desktop/xdg_shell.c
diff options
context:
space:
mode:
authorLibravatar Kirill Primak <vyivel@eclair.cafe>2023-07-11 15:09:14 +0300
committerLibravatar Simon Ser <contact@emersion.fr>2023-11-23 19:41:57 +0100
commit47e6a1164c25b5b49bfb919a681b88641d2ce37c (patch)
tree7d801aeea31eef9ab2f60cbaaa52d2b9d55289b3 /sway/desktop/xdg_shell.c
parentPass wl_display to wlr_output_layout (diff)
downloadsway-47e6a1164c25b5b49bfb919a681b88641d2ce37c.tar.gz
sway-47e6a1164c25b5b49bfb919a681b88641d2ce37c.tar.zst
sway-47e6a1164c25b5b49bfb919a681b88641d2ce37c.zip
xdg-shell: chase events update
Diffstat (limited to 'sway/desktop/xdg_shell.c')
-rw-r--r--sway/desktop/xdg_shell.c87
1 files changed, 51 insertions, 36 deletions
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 4c59b42a..63a0835b 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -38,6 +38,7 @@ static void popup_destroy(struct sway_view_child *child) {
38 return; 38 return;
39 } 39 }
40 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child; 40 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child;
41 wl_list_remove(&popup->surface_commit.link);
41 wl_list_remove(&popup->new_popup.link); 42 wl_list_remove(&popup->new_popup.link);
42 wl_list_remove(&popup->destroy.link); 43 wl_list_remove(&popup->destroy.link);
43 free(popup); 44 free(popup);
@@ -51,18 +52,6 @@ static const struct sway_view_child_impl popup_impl = {
51static struct sway_xdg_popup *popup_create( 52static struct sway_xdg_popup *popup_create(
52 struct wlr_xdg_popup *wlr_popup, struct sway_view *view); 53 struct wlr_xdg_popup *wlr_popup, struct sway_view *view);
53 54
54static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
55 struct sway_xdg_popup *popup =
56 wl_container_of(listener, popup, new_popup);
57 struct wlr_xdg_popup *wlr_popup = data;
58 popup_create(wlr_popup, popup->child.view);
59}
60
61static void popup_handle_destroy(struct wl_listener *listener, void *data) {
62 struct sway_xdg_popup *popup = wl_container_of(listener, popup, destroy);
63 view_child_destroy(&popup->child);
64}
65
66static void popup_unconstrain(struct sway_xdg_popup *popup) { 55static void popup_unconstrain(struct sway_xdg_popup *popup) {
67 struct sway_view *view = popup->child.view; 56 struct sway_view *view = popup->child.view;
68 struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_popup; 57 struct wlr_xdg_popup *wlr_popup = popup->wlr_xdg_popup;
@@ -87,6 +76,25 @@ static void popup_unconstrain(struct sway_xdg_popup *popup) {
87 wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box); 76 wlr_xdg_popup_unconstrain_from_box(wlr_popup, &output_toplevel_sx_box);
88} 77}
89 78
79static void popup_handle_surface_commit(struct wl_listener *listener, void *data) {
80 struct sway_xdg_popup *popup = wl_container_of(listener, popup, surface_commit);
81 if (popup->wlr_xdg_popup->base->initial_commit) {
82 popup_unconstrain(popup);
83 }
84}
85
86static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
87 struct sway_xdg_popup *popup =
88 wl_container_of(listener, popup, new_popup);
89 struct wlr_xdg_popup *wlr_popup = data;
90 popup_create(wlr_popup, popup->child.view);
91}
92
93static void popup_handle_destroy(struct wl_listener *listener, void *data) {
94 struct sway_xdg_popup *popup = wl_container_of(listener, popup, destroy);
95 view_child_destroy(&popup->child);
96}
97
90static struct sway_xdg_popup *popup_create( 98static struct sway_xdg_popup *popup_create(
91 struct wlr_xdg_popup *wlr_popup, struct sway_view *view) { 99 struct wlr_xdg_popup *wlr_popup, struct sway_view *view) {
92 struct wlr_xdg_surface *xdg_surface = wlr_popup->base; 100 struct wlr_xdg_surface *xdg_surface = wlr_popup->base;
@@ -97,22 +105,21 @@ static struct sway_xdg_popup *popup_create(
97 return NULL; 105 return NULL;
98 } 106 }
99 view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface); 107 view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface);
100 popup->wlr_xdg_popup = xdg_surface->popup; 108 popup->wlr_xdg_popup = wlr_popup;
101 109
110 wl_signal_add(&xdg_surface->surface->events.commit, &popup->surface_commit);
111 popup->surface_commit.notify = popup_handle_surface_commit;
102 wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup); 112 wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup);
103 popup->new_popup.notify = popup_handle_new_popup; 113 popup->new_popup.notify = popup_handle_new_popup;
104 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); 114 wl_signal_add(&wlr_popup->events.destroy, &popup->destroy);
105 popup->destroy.notify = popup_handle_destroy; 115 popup->destroy.notify = popup_handle_destroy;
106 116
107 wl_signal_add(&xdg_surface->surface->events.map, &popup->child.surface_map); 117 wl_signal_add(&xdg_surface->surface->events.map, &popup->child.surface_map);
108 wl_signal_add(&xdg_surface->surface->events.unmap, &popup->child.surface_unmap); 118 wl_signal_add(&xdg_surface->surface->events.unmap, &popup->child.surface_unmap);
109 119
110 popup_unconstrain(popup);
111
112 return popup; 120 return popup;
113} 121}
114 122
115
116static struct sway_xdg_shell_view *xdg_shell_view_from_view( 123static struct sway_xdg_shell_view *xdg_shell_view_from_view(
117 struct sway_view *view) { 124 struct sway_view *view) {
118 if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL, 125 if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL,
@@ -286,6 +293,19 @@ static void handle_commit(struct wl_listener *listener, void *data) {
286 struct sway_view *view = &xdg_shell_view->view; 293 struct sway_view *view = &xdg_shell_view->view;
287 struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_toplevel->base; 294 struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_toplevel->base;
288 295
296 if (xdg_surface->initial_commit) {
297 if (view->xdg_decoration != NULL) {
298 set_xdg_decoration_mode(view->xdg_decoration);
299 }
300 // XXX: https://github.com/swaywm/sway/issues/2176
301 wlr_xdg_surface_schedule_configure(xdg_surface);
302 return;
303 }
304
305 if (!xdg_surface->surface->mapped) {
306 return;
307 }
308
289 struct wlr_box new_geo; 309 struct wlr_box new_geo;
290 wlr_xdg_surface_get_geometry(xdg_surface, &new_geo); 310 wlr_xdg_surface_get_geometry(xdg_surface, &new_geo);
291 bool new_size = new_geo.width != view->geometry.width || 311 bool new_size = new_geo.width != view->geometry.width ||
@@ -421,7 +441,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
421 441
422 view_unmap(view); 442 view_unmap(view);
423 443
424 wl_list_remove(&xdg_shell_view->commit.link);
425 wl_list_remove(&xdg_shell_view->new_popup.link); 444 wl_list_remove(&xdg_shell_view->new_popup.link);
426 wl_list_remove(&xdg_shell_view->request_maximize.link); 445 wl_list_remove(&xdg_shell_view->request_maximize.link);
427 wl_list_remove(&xdg_shell_view->request_fullscreen.link); 446 wl_list_remove(&xdg_shell_view->request_fullscreen.link);
@@ -464,10 +483,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
464 483
465 transaction_commit_dirty(); 484 transaction_commit_dirty();
466 485
467 xdg_shell_view->commit.notify = handle_commit;
468 wl_signal_add(&toplevel->base->surface->events.commit,
469 &xdg_shell_view->commit);
470
471 xdg_shell_view->new_popup.notify = handle_new_popup; 486 xdg_shell_view->new_popup.notify = handle_new_popup;
472 wl_signal_add(&toplevel->base->events.new_popup, 487 wl_signal_add(&toplevel->base->events.new_popup,
473 &xdg_shell_view->new_popup); 488 &xdg_shell_view->new_popup);
@@ -507,6 +522,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
507 wl_list_remove(&xdg_shell_view->destroy.link); 522 wl_list_remove(&xdg_shell_view->destroy.link);
508 wl_list_remove(&xdg_shell_view->map.link); 523 wl_list_remove(&xdg_shell_view->map.link);
509 wl_list_remove(&xdg_shell_view->unmap.link); 524 wl_list_remove(&xdg_shell_view->unmap.link);
525 wl_list_remove(&xdg_shell_view->commit.link);
510 view->wlr_xdg_toplevel = NULL; 526 view->wlr_xdg_toplevel = NULL;
511 if (view->xdg_decoration) { 527 if (view->xdg_decoration) {
512 view->xdg_decoration->view = NULL; 528 view->xdg_decoration->view = NULL;
@@ -519,17 +535,12 @@ struct sway_view *view_from_wlr_xdg_surface(
519 return xdg_surface->data; 535 return xdg_surface->data;
520} 536}
521 537
522void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { 538void handle_xdg_shell_toplevel(struct wl_listener *listener, void *data) {
523 struct wlr_xdg_surface *xdg_surface = data; 539 struct wlr_xdg_toplevel *xdg_toplevel = data;
524
525 if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
526 sway_log(SWAY_DEBUG, "New xdg_shell popup");
527 return;
528 }
529 540
530 sway_log(SWAY_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'", 541 sway_log(SWAY_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'",
531 xdg_surface->toplevel->title, xdg_surface->toplevel->app_id); 542 xdg_toplevel->title, xdg_toplevel->app_id);
532 wlr_xdg_surface_ping(xdg_surface); 543 wlr_xdg_surface_ping(xdg_toplevel->base);
533 544
534 struct sway_xdg_shell_view *xdg_shell_view = 545 struct sway_xdg_shell_view *xdg_shell_view =
535 calloc(1, sizeof(struct sway_xdg_shell_view)); 546 calloc(1, sizeof(struct sway_xdg_shell_view));
@@ -538,16 +549,20 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
538 } 549 }
539 550
540 view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl); 551 view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl);
541 xdg_shell_view->view.wlr_xdg_toplevel = xdg_surface->toplevel; 552 xdg_shell_view->view.wlr_xdg_toplevel = xdg_toplevel;
542 553
543 xdg_shell_view->map.notify = handle_map; 554 xdg_shell_view->map.notify = handle_map;
544 wl_signal_add(&xdg_surface->surface->events.map, &xdg_shell_view->map); 555 wl_signal_add(&xdg_toplevel->base->surface->events.map, &xdg_shell_view->map);
545 556
546 xdg_shell_view->unmap.notify = handle_unmap; 557 xdg_shell_view->unmap.notify = handle_unmap;
547 wl_signal_add(&xdg_surface->surface->events.unmap, &xdg_shell_view->unmap); 558 wl_signal_add(&xdg_toplevel->base->surface->events.unmap, &xdg_shell_view->unmap);
559
560 xdg_shell_view->commit.notify = handle_commit;
561 wl_signal_add(&xdg_toplevel->base->surface->events.commit,
562 &xdg_shell_view->commit);
548 563
549 xdg_shell_view->destroy.notify = handle_destroy; 564 xdg_shell_view->destroy.notify = handle_destroy;
550 wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy); 565 wl_signal_add(&xdg_toplevel->events.destroy, &xdg_shell_view->destroy);
551 566
552 xdg_surface->data = xdg_shell_view; 567 xdg_toplevel->base->data = xdg_shell_view;
553} 568}