diff options
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/desktop.c | 20 | ||||
-rw-r--r-- | sway/desktop/output.c | 25 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 1 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 73 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 132 |
5 files changed, 214 insertions, 37 deletions
diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c new file mode 100644 index 00000000..3a13191f --- /dev/null +++ b/sway/desktop/desktop.c | |||
@@ -0,0 +1,20 @@ | |||
1 | #include "sway/tree/container.h" | ||
2 | #include "sway/desktop.h" | ||
3 | #include "sway/output.h" | ||
4 | |||
5 | void desktop_damage_whole_surface(struct wlr_surface *surface, double lx, | ||
6 | double ly) { | ||
7 | for (int i = 0; i < root_container.children->length; ++i) { | ||
8 | struct sway_container *cont = root_container.children->items[i]; | ||
9 | if (cont->type == C_OUTPUT) { | ||
10 | output_damage_whole_surface(cont->sway_output, | ||
11 | lx - cont->x, ly - cont->y, surface); | ||
12 | } | ||
13 | } | ||
14 | } | ||
15 | |||
16 | void desktop_damage_from_surface(struct wlr_surface *surface, double lx, | ||
17 | double ly) { | ||
18 | // TODO | ||
19 | desktop_damage_whole_surface(surface, lx, ly); | ||
20 | } | ||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0e8a9485..aa18f1b8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -267,17 +267,14 @@ static void render_output(struct sway_output *output, struct timespec *when, | |||
267 | 267 | ||
268 | // render unmanaged views on top | 268 | // render unmanaged views on top |
269 | struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged; | 269 | struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged; |
270 | struct sway_xwayland_unmanaged *sway_surface; | 270 | struct sway_xwayland_unmanaged *unmanaged_surface; |
271 | wl_list_for_each(sway_surface, unmanaged, link) { | 271 | wl_list_for_each(unmanaged_surface, unmanaged, link) { |
272 | struct wlr_xwayland_surface *xsurface = | 272 | struct wlr_xwayland_surface *xsurface = |
273 | sway_surface->wlr_xwayland_surface; | 273 | unmanaged_surface->wlr_xwayland_surface; |
274 | if (xsurface->surface == NULL) { | ||
275 | continue; | ||
276 | } | ||
277 | 274 | ||
278 | const struct wlr_box view_box = { | 275 | const struct wlr_box view_box = { |
279 | .x = xsurface->x, | 276 | .x = unmanaged_surface->lx, |
280 | .y = xsurface->y, | 277 | .y = unmanaged_surface->ly, |
281 | .width = xsurface->width, | 278 | .width = xsurface->width, |
282 | .height = xsurface->height, | 279 | .height = xsurface->height, |
283 | }; | 280 | }; |
@@ -335,12 +332,24 @@ void output_damage_whole(struct sway_output *output) { | |||
335 | wlr_output_damage_add_whole(output->damage); | 332 | wlr_output_damage_add_whole(output->damage); |
336 | } | 333 | } |
337 | 334 | ||
335 | void output_damage_whole_surface(struct sway_output *output, | ||
336 | double ox, double oy, struct wlr_surface *surface) { | ||
337 | // TODO | ||
338 | output_damage_whole(output); | ||
339 | } | ||
340 | |||
338 | void output_damage_whole_view(struct sway_output *output, | 341 | void output_damage_whole_view(struct sway_output *output, |
339 | struct sway_view *view) { | 342 | struct sway_view *view) { |
340 | // TODO | 343 | // TODO |
341 | output_damage_whole(output); | 344 | output_damage_whole(output); |
342 | } | 345 | } |
343 | 346 | ||
347 | void output_damage_whole_container(struct sway_output *output, | ||
348 | struct sway_container *con) { | ||
349 | // TODO | ||
350 | output_damage_whole(output); | ||
351 | } | ||
352 | |||
344 | static void damage_handle_destroy(struct wl_listener *listener, void *data) { | 353 | static void damage_handle_destroy(struct wl_listener *listener, void *data) { |
345 | struct sway_output *output = | 354 | struct sway_output *output = |
346 | wl_container_of(listener, output, damage_destroy); | 355 | wl_container_of(listener, output, damage_destroy); |
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index 5955fa9d..fff31da8 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c | |||
@@ -68,6 +68,7 @@ static const struct sway_view_impl view_impl = { | |||
68 | .get_prop = get_prop, | 68 | .get_prop = get_prop, |
69 | .configure = configure, | 69 | .configure = configure, |
70 | .close = _close, | 70 | .close = _close, |
71 | .destroy = destroy, | ||
71 | }; | 72 | }; |
72 | 73 | ||
73 | static void handle_commit(struct wl_listener *listener, void *data) { | 74 | static void handle_commit(struct wl_listener *listener, void *data) { |
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 | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 384f4236..e3da1da7 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -2,42 +2,110 @@ | |||
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <wayland-server.h> | 4 | #include <wayland-server.h> |
5 | #include <wlr/xwayland.h> | ||
6 | #include <wlr/types/wlr_output_layout.h> | 5 | #include <wlr/types/wlr_output_layout.h> |
7 | #include <wlr/types/wlr_output.h> | 6 | #include <wlr/types/wlr_output.h> |
7 | #include <wlr/xwayland.h> | ||
8 | #include "log.h" | ||
9 | #include "sway/desktop.h" | ||
10 | #include "sway/input/input-manager.h" | ||
11 | #include "sway/input/seat.h" | ||
12 | #include "sway/output.h" | ||
13 | #include "sway/server.h" | ||
8 | #include "sway/tree/container.h" | 14 | #include "sway/tree/container.h" |
9 | #include "sway/tree/layout.h" | 15 | #include "sway/tree/layout.h" |
10 | #include "sway/server.h" | ||
11 | #include "sway/tree/view.h" | 16 | #include "sway/tree/view.h" |
12 | #include "sway/output.h" | ||
13 | #include "sway/input/seat.h" | ||
14 | #include "sway/input/input-manager.h" | ||
15 | #include "log.h" | ||
16 | 17 | ||
17 | static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) { | 18 | static void unmanaged_handle_request_configure(struct wl_listener *listener, |
18 | struct sway_xwayland_unmanaged *sway_surface = | 19 | void *data) { |
19 | wl_container_of(listener, sway_surface, destroy); | 20 | struct sway_xwayland_unmanaged *surface = |
20 | wl_list_remove(&sway_surface->destroy.link); | 21 | wl_container_of(listener, surface, request_configure); |
21 | wl_list_remove(&sway_surface->link); | 22 | struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; |
22 | free(sway_surface); | 23 | struct wlr_xwayland_surface_configure_event *ev = data; |
24 | wlr_xwayland_surface_configure(xsurface, ev->x, ev->y, | ||
25 | ev->width, ev->height); | ||
23 | } | 26 | } |
24 | 27 | ||
25 | static void create_unmanaged(struct wlr_xwayland_surface *xsurface) { | 28 | static void unmanaged_handle_commit(struct wl_listener *listener, void *data) { |
26 | struct sway_xwayland_unmanaged *sway_surface = | 29 | struct sway_xwayland_unmanaged *surface = |
27 | calloc(1, sizeof(struct sway_xwayland_unmanaged)); | 30 | wl_container_of(listener, surface, commit); |
28 | if (!sway_assert(sway_surface, "Failed to allocate surface")) { | 31 | struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; |
29 | return; | 32 | |
33 | if (xsurface->x != surface->lx || xsurface->y != surface->ly) { | ||
34 | // Surface has moved | ||
35 | desktop_damage_whole_surface(xsurface->surface, | ||
36 | surface->lx, surface->ly); | ||
37 | surface->lx = xsurface->x; | ||
38 | surface->ly = xsurface->y; | ||
39 | desktop_damage_whole_surface(xsurface->surface, | ||
40 | surface->lx, surface->ly); | ||
41 | } else { | ||
42 | desktop_damage_from_surface(xsurface->surface, | ||
43 | xsurface->x, xsurface->y); | ||
30 | } | 44 | } |
45 | } | ||
31 | 46 | ||
32 | sway_surface->wlr_xwayland_surface = xsurface; | 47 | static void unmanaged_handle_map(struct wl_listener *listener, void *data) { |
33 | 48 | struct sway_xwayland_unmanaged *surface = | |
34 | wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); | 49 | wl_container_of(listener, surface, map); |
35 | sway_surface->destroy.notify = unmanaged_handle_destroy; | 50 | struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; |
36 | 51 | ||
37 | wl_list_insert(&root_container.sway_root->xwayland_unmanaged, | 52 | wl_list_insert(&root_container.sway_root->xwayland_unmanaged, |
38 | &sway_surface->link); | 53 | &surface->link); |
54 | |||
55 | wl_signal_add(&xsurface->surface->events.commit, &surface->commit); | ||
56 | surface->commit.notify = unmanaged_handle_commit; | ||
57 | |||
58 | surface->lx = xsurface->x; | ||
59 | surface->ly = xsurface->y; | ||
60 | desktop_damage_whole_surface(xsurface->surface, surface->lx, surface->ly); | ||
61 | } | ||
62 | |||
63 | static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { | ||
64 | struct sway_xwayland_unmanaged *surface = | ||
65 | wl_container_of(listener, surface, unmap); | ||
66 | struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; | ||
67 | desktop_damage_whole_surface(xsurface->surface, xsurface->x, xsurface->y); | ||
68 | wl_list_remove(&surface->link); | ||
69 | wl_list_remove(&surface->commit.link); | ||
70 | } | ||
39 | 71 | ||
40 | // TODO: damage tracking | 72 | static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) { |
73 | struct sway_xwayland_unmanaged *surface = | ||
74 | wl_container_of(listener, surface, destroy); | ||
75 | struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; | ||
76 | if (xsurface->mapped) { | ||
77 | unmanaged_handle_unmap(&surface->unmap, xsurface); | ||
78 | } | ||
79 | wl_list_remove(&surface->map.link); | ||
80 | wl_list_remove(&surface->unmap.link); | ||
81 | wl_list_remove(&surface->destroy.link); | ||
82 | free(surface); | ||
83 | } | ||
84 | |||
85 | static struct sway_xwayland_unmanaged *create_unmanaged( | ||
86 | struct wlr_xwayland_surface *xsurface) { | ||
87 | struct sway_xwayland_unmanaged *surface = | ||
88 | calloc(1, sizeof(struct sway_xwayland_unmanaged)); | ||
89 | if (surface == NULL) { | ||
90 | wlr_log(L_ERROR, "Allocation failed"); | ||
91 | return NULL; | ||
92 | } | ||
93 | |||
94 | surface->wlr_xwayland_surface = xsurface; | ||
95 | |||
96 | wl_signal_add(&xsurface->events.request_configure, | ||
97 | &surface->request_configure); | ||
98 | surface->request_configure.notify = unmanaged_handle_request_configure; | ||
99 | wl_signal_add(&xsurface->events.map, &surface->map); | ||
100 | surface->map.notify = unmanaged_handle_map; | ||
101 | wl_signal_add(&xsurface->events.unmap, &surface->unmap); | ||
102 | surface->unmap.notify = unmanaged_handle_unmap; | ||
103 | wl_signal_add(&xsurface->events.destroy, &surface->destroy); | ||
104 | surface->destroy.notify = unmanaged_handle_destroy; | ||
105 | |||
106 | unmanaged_handle_map(&surface->map, xsurface); | ||
107 | |||
108 | return surface; | ||
41 | } | 109 | } |
42 | 110 | ||
43 | 111 | ||
@@ -127,6 +195,7 @@ static const struct sway_view_impl view_impl = { | |||
127 | .configure = configure, | 195 | .configure = configure, |
128 | .set_activated = set_activated, | 196 | .set_activated = set_activated, |
129 | .close = _close, | 197 | .close = _close, |
198 | .destroy = destroy, | ||
130 | }; | 199 | }; |
131 | 200 | ||
132 | static void handle_commit(struct wl_listener *listener, void *data) { | 201 | static void handle_commit(struct wl_listener *listener, void *data) { |
@@ -140,12 +209,6 @@ static void handle_commit(struct wl_listener *listener, void *data) { | |||
140 | view_damage_from(view); | 209 | view_damage_from(view); |
141 | } | 210 | } |
142 | 211 | ||
143 | static void handle_destroy(struct wl_listener *listener, void *data) { | ||
144 | struct sway_xwayland_view *xwayland_view = | ||
145 | wl_container_of(listener, xwayland_view, destroy); | ||
146 | view_destroy(&xwayland_view->view); | ||
147 | } | ||
148 | |||
149 | static void handle_unmap(struct wl_listener *listener, void *data) { | 212 | static void handle_unmap(struct wl_listener *listener, void *data) { |
150 | struct sway_xwayland_view *xwayland_view = | 213 | struct sway_xwayland_view *xwayland_view = |
151 | wl_container_of(listener, xwayland_view, unmap); | 214 | wl_container_of(listener, xwayland_view, unmap); |
@@ -169,6 +232,17 @@ static void handle_map(struct wl_listener *listener, void *data) { | |||
169 | view_map(view, xsurface->surface); | 232 | view_map(view, xsurface->surface); |
170 | } | 233 | } |
171 | 234 | ||
235 | static void handle_destroy(struct wl_listener *listener, void *data) { | ||
236 | struct sway_xwayland_view *xwayland_view = | ||
237 | wl_container_of(listener, xwayland_view, destroy); | ||
238 | struct sway_view *view = &xwayland_view->view; | ||
239 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | ||
240 | if (xsurface->mapped) { | ||
241 | handle_unmap(&xwayland_view->unmap, xsurface); | ||
242 | } | ||
243 | view_destroy(&xwayland_view->view); | ||
244 | } | ||
245 | |||
172 | static void handle_request_configure(struct wl_listener *listener, void *data) { | 246 | static void handle_request_configure(struct wl_listener *listener, void *data) { |
173 | struct sway_xwayland_view *xwayland_view = | 247 | struct sway_xwayland_view *xwayland_view = |
174 | wl_container_of(listener, xwayland_view, request_configure); | 248 | wl_container_of(listener, xwayland_view, request_configure); |