diff options
Diffstat (limited to 'sway/desktop/xdg_shell_v6.c')
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 7b9d5fb7..c66cc39a 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -11,6 +11,66 @@ | |||
11 | #include "sway/input/input-manager.h" | 11 | #include "sway/input/input-manager.h" |
12 | #include "log.h" | 12 | #include "log.h" |
13 | 13 | ||
14 | static const struct sway_view_child_impl popup_impl; | ||
15 | |||
16 | static void popup_destroy(struct sway_view_child *child) { | ||
17 | if (!sway_assert(child->impl == &popup_impl, | ||
18 | "Expected an xdg_shell_v6 popup")) { | ||
19 | return; | ||
20 | } | ||
21 | struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child; | ||
22 | wl_list_remove(&popup->new_popup.link); | ||
23 | wl_list_remove(&popup->unmap.link); | ||
24 | wl_list_remove(&popup->destroy.link); | ||
25 | free(popup); | ||
26 | } | ||
27 | |||
28 | static const struct sway_view_child_impl popup_impl = { | ||
29 | .destroy = popup_destroy, | ||
30 | }; | ||
31 | |||
32 | static struct sway_xdg_popup_v6 *popup_create( | ||
33 | struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view); | ||
34 | |||
35 | static void popup_handle_new_popup(struct wl_listener *listener, void *data) { | ||
36 | struct sway_xdg_popup_v6 *popup = | ||
37 | wl_container_of(listener, popup, new_popup); | ||
38 | struct wlr_xdg_popup_v6 *wlr_popup = data; | ||
39 | popup_create(wlr_popup, popup->child.view); | ||
40 | } | ||
41 | |||
42 | static void popup_handle_unmap(struct wl_listener *listener, void *data) { | ||
43 | struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, unmap); | ||
44 | view_child_destroy(&popup->child); | ||
45 | } | ||
46 | |||
47 | static void popup_handle_destroy(struct wl_listener *listener, void *data) { | ||
48 | struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, destroy); | ||
49 | view_child_destroy(&popup->child); | ||
50 | } | ||
51 | |||
52 | static struct sway_xdg_popup_v6 *popup_create( | ||
53 | struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view) { | ||
54 | struct wlr_xdg_surface_v6 *xdg_surface = wlr_popup->base; | ||
55 | |||
56 | struct sway_xdg_popup_v6 *popup = | ||
57 | calloc(1, sizeof(struct sway_xdg_popup_v6)); | ||
58 | if (popup == NULL) { | ||
59 | return NULL; | ||
60 | } | ||
61 | view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface); | ||
62 | |||
63 | wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup); | ||
64 | popup->new_popup.notify = popup_handle_new_popup; | ||
65 | wl_signal_add(&xdg_surface->events.unmap, &popup->unmap); | ||
66 | popup->unmap.notify = popup_handle_unmap; | ||
67 | wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); | ||
68 | popup->destroy.notify = popup_handle_destroy; | ||
69 | |||
70 | return popup; | ||
71 | } | ||
72 | |||
73 | |||
14 | static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view( | 74 | static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view( |
15 | struct sway_view *view) { | 75 | struct sway_view *view) { |
16 | if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, | 76 | if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, |
@@ -76,6 +136,7 @@ static void destroy(struct sway_view *view) { | |||
76 | } | 136 | } |
77 | wl_list_remove(&xdg_shell_v6_view->commit.link); | 137 | wl_list_remove(&xdg_shell_v6_view->commit.link); |
78 | wl_list_remove(&xdg_shell_v6_view->destroy.link); | 138 | wl_list_remove(&xdg_shell_v6_view->destroy.link); |
139 | wl_list_remove(&xdg_shell_v6_view->new_popup.link); | ||
79 | wl_list_remove(&xdg_shell_v6_view->map.link); | 140 | wl_list_remove(&xdg_shell_v6_view->map.link); |
80 | wl_list_remove(&xdg_shell_v6_view->unmap.link); | 141 | wl_list_remove(&xdg_shell_v6_view->unmap.link); |
81 | free(xdg_shell_v6_view); | 142 | free(xdg_shell_v6_view); |
@@ -86,6 +147,7 @@ static const struct sway_view_impl view_impl = { | |||
86 | .configure = configure, | 147 | .configure = configure, |
87 | .set_activated = set_activated, | 148 | .set_activated = set_activated, |
88 | .close = _close, | 149 | .close = _close, |
150 | .destroy = destroy, | ||
89 | }; | 151 | }; |
90 | 152 | ||
91 | static void handle_commit(struct wl_listener *listener, void *data) { | 153 | static void handle_commit(struct wl_listener *listener, void *data) { |
@@ -100,6 +162,13 @@ static void handle_commit(struct wl_listener *listener, void *data) { | |||
100 | view_damage_from(view); | 162 | view_damage_from(view); |
101 | } | 163 | } |
102 | 164 | ||
165 | static void handle_new_popup(struct wl_listener *listener, void *data) { | ||
166 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = | ||
167 | wl_container_of(listener, xdg_shell_v6_view, new_popup); | ||
168 | struct wlr_xdg_popup_v6 *wlr_popup = data; | ||
169 | popup_create(wlr_popup, &xdg_shell_v6_view->view); | ||
170 | } | ||
171 | |||
103 | static void handle_unmap(struct wl_listener *listener, void *data) { | 172 | static void handle_unmap(struct wl_listener *listener, void *data) { |
104 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = | 173 | struct sway_xdg_shell_v6_view *xdg_shell_v6_view = |
105 | wl_container_of(listener, xdg_shell_v6_view, unmap); | 174 | wl_container_of(listener, xdg_shell_v6_view, unmap); |
@@ -151,6 +220,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
151 | wl_signal_add(&xdg_surface->surface->events.commit, | 220 | wl_signal_add(&xdg_surface->surface->events.commit, |
152 | &xdg_shell_v6_view->commit); | 221 | &xdg_shell_v6_view->commit); |
153 | 222 | ||
223 | xdg_shell_v6_view->new_popup.notify = handle_new_popup; | ||
224 | wl_signal_add(&xdg_surface->events.new_popup, | ||
225 | &xdg_shell_v6_view->new_popup); | ||
226 | |||
154 | xdg_shell_v6_view->map.notify = handle_map; | 227 | xdg_shell_v6_view->map.notify = handle_map; |
155 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); | 228 | wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); |
156 | 229 | ||