summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-05-13 13:45:15 -0400
committerLibravatar GitHub <noreply@github.com>2018-05-13 13:45:15 -0400
commitb2dec1236837f0c441a9fd6162b6294c52fac5e0 (patch)
tree6710b0e9261285f22df2751a1404b05371cff000
parentAdd pixman to swayidle deps (diff)
parentAdd xdg-shell stable support (diff)
downloadsway-b2dec1236837f0c441a9fd6162b6294c52fac5e0.tar.gz
sway-b2dec1236837f0c441a9fd6162b6294c52fac5e0.tar.zst
sway-b2dec1236837f0c441a9fd6162b6294c52fac5e0.zip
Merge pull request #1970 from emersion/xdg-shell-stable
Add xdg-shell stable support
-rw-r--r--include/sway/server.h5
-rw-r--r--include/sway/tree/view.h27
-rw-r--r--protocols/meson.build1
-rw-r--r--sway/desktop/xdg_shell.c277
-rw-r--r--sway/meson.build3
-rw-r--r--sway/server.c5
-rw-r--r--sway/tree/container.c12
-rw-r--r--sway/tree/view.c2
8 files changed, 331 insertions, 1 deletions
diff --git a/include/sway/server.h b/include/sway/server.h
index ac685bf8..d04ea896 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -8,6 +8,7 @@
8#include <wlr/types/wlr_data_device.h> 8#include <wlr/types/wlr_data_device.h>
9#include <wlr/types/wlr_layer_shell.h> 9#include <wlr/types/wlr_layer_shell.h>
10#include <wlr/types/wlr_xdg_shell_v6.h> 10#include <wlr/types/wlr_xdg_shell_v6.h>
11#include <wlr/types/wlr_xdg_shell.h>
11#include <wlr/render/wlr_renderer.h> 12#include <wlr/render/wlr_renderer.h>
12// TODO WLR: make Xwayland optional 13// TODO WLR: make Xwayland optional
13#include <wlr/xwayland.h> 14#include <wlr/xwayland.h>
@@ -33,6 +34,9 @@ struct sway_server {
33 struct wlr_xdg_shell_v6 *xdg_shell_v6; 34 struct wlr_xdg_shell_v6 *xdg_shell_v6;
34 struct wl_listener xdg_shell_v6_surface; 35 struct wl_listener xdg_shell_v6_surface;
35 36
37 struct wlr_xdg_shell *xdg_shell;
38 struct wl_listener xdg_shell_surface;
39
36 struct wlr_xwayland *xwayland; 40 struct wlr_xwayland *xwayland;
37 struct wlr_xcursor_manager *xcursor_manager; 41 struct wlr_xcursor_manager *xcursor_manager;
38 struct wl_listener xwayland_surface; 42 struct wl_listener xwayland_surface;
@@ -52,6 +56,7 @@ void handle_new_output(struct wl_listener *listener, void *data);
52 56
53void handle_layer_shell_surface(struct wl_listener *listener, void *data); 57void handle_layer_shell_surface(struct wl_listener *listener, void *data);
54void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); 58void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
59void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
55void handle_xwayland_surface(struct wl_listener *listener, void *data); 60void handle_xwayland_surface(struct wl_listener *listener, void *data);
56void handle_wl_shell_surface(struct wl_listener *listener, void *data); 61void handle_wl_shell_surface(struct wl_listener *listener, void *data);
57 62
diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 8091fe0c..17e579c8 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -12,6 +12,7 @@ struct sway_container;
12enum sway_view_type { 12enum sway_view_type {
13 SWAY_VIEW_WL_SHELL, 13 SWAY_VIEW_WL_SHELL,
14 SWAY_VIEW_XDG_SHELL_V6, 14 SWAY_VIEW_XDG_SHELL_V6,
15 SWAY_VIEW_XDG_SHELL,
15 SWAY_VIEW_XWAYLAND, 16 SWAY_VIEW_XWAYLAND,
16}; 17};
17 18
@@ -54,6 +55,7 @@ struct sway_view {
54 55
55 union { 56 union {
56 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; 57 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
58 struct wlr_xdg_surface *wlr_xdg_surface;
57 struct wlr_xwayland_surface *wlr_xwayland_surface; 59 struct wlr_xwayland_surface *wlr_xwayland_surface;
58 struct wlr_wl_shell_surface *wlr_wl_shell_surface; 60 struct wlr_wl_shell_surface *wlr_wl_shell_surface;
59 }; 61 };
@@ -82,6 +84,22 @@ struct sway_xdg_shell_v6_view {
82 int pending_width, pending_height; 84 int pending_width, pending_height;
83}; 85};
84 86
87struct sway_xdg_shell_view {
88 struct sway_view view;
89
90 struct wl_listener commit;
91 struct wl_listener request_move;
92 struct wl_listener request_resize;
93 struct wl_listener request_maximize;
94 struct wl_listener request_fullscreen;
95 struct wl_listener new_popup;
96 struct wl_listener map;
97 struct wl_listener unmap;
98 struct wl_listener destroy;
99
100 int pending_width, pending_height;
101};
102
85struct sway_xwayland_view { 103struct sway_xwayland_view {
86 struct sway_view view; 104 struct sway_view view;
87 105
@@ -156,6 +174,15 @@ struct sway_xdg_popup_v6 {
156 struct wl_listener destroy; 174 struct wl_listener destroy;
157}; 175};
158 176
177struct sway_xdg_popup {
178 struct sway_view_child child;
179
180 struct wlr_xdg_surface *wlr_xdg_surface;
181
182 struct wl_listener new_popup;
183 struct wl_listener destroy;
184};
185
159const char *view_get_title(struct sway_view *view); 186const char *view_get_title(struct sway_view *view);
160 187
161const char *view_get_app_id(struct sway_view *view); 188const char *view_get_app_id(struct sway_view *view);
diff --git a/protocols/meson.build b/protocols/meson.build
index fa6d696c..9966c02f 100644
--- a/protocols/meson.build
+++ b/protocols/meson.build
@@ -35,6 +35,7 @@ client_protocols = [
35] 35]
36 36
37server_protocols = [ 37server_protocols = [
38 [wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
38 [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 39 [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'],
39 ['wlr-layer-shell-unstable-v1.xml'], 40 ['wlr-layer-shell-unstable-v1.xml'],
40 ['wlr-input-inhibitor-unstable-v1.xml'] 41 ['wlr-input-inhibitor-unstable-v1.xml']
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
new file mode 100644
index 00000000..48b659f2
--- /dev/null
+++ b/sway/desktop/xdg_shell.c
@@ -0,0 +1,277 @@
1#define _POSIX_C_SOURCE 199309L
2#include <stdbool.h>
3#include <stdlib.h>
4#include <wayland-server.h>
5#include <wlr/types/wlr_xdg_shell.h>
6#include "sway/tree/container.h"
7#include "sway/tree/layout.h"
8#include "sway/server.h"
9#include "sway/tree/view.h"
10#include "sway/input/seat.h"
11#include "sway/input/input-manager.h"
12#include "log.h"
13
14static const struct sway_view_child_impl popup_impl;
15
16static void popup_destroy(struct sway_view_child *child) {
17 if (!sway_assert(child->impl == &popup_impl,
18 "Expected an xdg_shell popup")) {
19 return;
20 }
21 struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child;
22 wl_list_remove(&popup->new_popup.link);
23 wl_list_remove(&popup->destroy.link);
24 free(popup);
25}
26
27static const struct sway_view_child_impl popup_impl = {
28 .destroy = popup_destroy,
29};
30
31static struct sway_xdg_popup *popup_create(
32 struct wlr_xdg_popup *wlr_popup, struct sway_view *view);
33
34static void popup_handle_new_popup(struct wl_listener *listener, void *data) {
35 struct sway_xdg_popup *popup =
36 wl_container_of(listener, popup, new_popup);
37 struct wlr_xdg_popup *wlr_popup = data;
38 popup_create(wlr_popup, popup->child.view);
39}
40
41static void popup_handle_destroy(struct wl_listener *listener, void *data) {
42 struct sway_xdg_popup *popup = wl_container_of(listener, popup, destroy);
43 view_child_destroy(&popup->child);
44}
45
46static struct sway_xdg_popup *popup_create(
47 struct wlr_xdg_popup *wlr_popup, struct sway_view *view) {
48 struct wlr_xdg_surface *xdg_surface = wlr_popup->base;
49
50 struct sway_xdg_popup *popup =
51 calloc(1, sizeof(struct sway_xdg_popup));
52 if (popup == NULL) {
53 return NULL;
54 }
55 view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface);
56
57 wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup);
58 popup->new_popup.notify = popup_handle_new_popup;
59 wl_signal_add(&xdg_surface->events.destroy, &popup->destroy);
60 popup->destroy.notify = popup_handle_destroy;
61
62 return popup;
63}
64
65
66static struct sway_xdg_shell_view *xdg_shell_view_from_view(
67 struct sway_view *view) {
68 if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL,
69 "Expected xdg_shell view")) {
70 return NULL;
71 }
72 return (struct sway_xdg_shell_view *)view;
73}
74
75static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
76 if (xdg_shell_view_from_view(view) == NULL) {
77 return NULL;
78 }
79 switch (prop) {
80 case VIEW_PROP_TITLE:
81 return view->wlr_xdg_surface->toplevel->title;
82 case VIEW_PROP_APP_ID:
83 return view->wlr_xdg_surface->toplevel->app_id;
84 default:
85 return NULL;
86 }
87}
88
89static void configure(struct sway_view *view, double ox, double oy, int width,
90 int height) {
91 struct sway_xdg_shell_view *xdg_shell_view =
92 xdg_shell_view_from_view(view);
93 if (xdg_shell_view == NULL) {
94 return;
95 }
96
97 xdg_shell_view->pending_width = width;
98 xdg_shell_view->pending_height = height;
99 wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
100}
101
102static void set_activated(struct sway_view *view, bool activated) {
103 if (xdg_shell_view_from_view(view) == NULL) {
104 return;
105 }
106 struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
107 if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
108 wlr_xdg_toplevel_set_activated(surface, activated);
109 }
110}
111
112static void set_fullscreen(struct sway_view *view, bool fullscreen) {
113 if (xdg_shell_view_from_view(view) == NULL) {
114 return;
115 }
116 struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
117 wlr_xdg_toplevel_set_fullscreen(surface, fullscreen);
118}
119
120static void for_each_surface(struct sway_view *view,
121 wlr_surface_iterator_func_t iterator, void *user_data) {
122 if (xdg_shell_view_from_view(view) == NULL) {
123 return;
124 }
125 wlr_xdg_surface_for_each_surface(view->wlr_xdg_surface, iterator,
126 user_data);
127}
128
129static void _close(struct sway_view *view) {
130 if (xdg_shell_view_from_view(view) == NULL) {
131 return;
132 }
133 struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
134 if (surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL) {
135 wlr_xdg_surface_send_close(surface);
136 }
137}
138
139static void destroy(struct sway_view *view) {
140 struct sway_xdg_shell_view *xdg_shell_view =
141 xdg_shell_view_from_view(view);
142 if (xdg_shell_view == NULL) {
143 return;
144 }
145 wl_list_remove(&xdg_shell_view->destroy.link);
146 wl_list_remove(&xdg_shell_view->map.link);
147 wl_list_remove(&xdg_shell_view->unmap.link);
148 wl_list_remove(&xdg_shell_view->request_fullscreen.link);
149 free(xdg_shell_view);
150}
151
152static const struct sway_view_impl view_impl = {
153 .get_prop = get_prop,
154 .configure = configure,
155 .set_activated = set_activated,
156 .set_fullscreen = set_fullscreen,
157 .for_each_surface = for_each_surface,
158 .close = _close,
159 .destroy = destroy,
160};
161
162static void handle_commit(struct wl_listener *listener, void *data) {
163 struct sway_xdg_shell_view *xdg_shell_view =
164 wl_container_of(listener, xdg_shell_view, commit);
165 struct sway_view *view = &xdg_shell_view->view;
166 // NOTE: We intentionally discard the view's desired width here
167 // TODO: Store this for restoration when moving to floating plane
168 // TODO: Let floating views do whatever
169 view_update_size(view, xdg_shell_view->pending_width,
170 xdg_shell_view->pending_height);
171 view_update_title(view, false);
172 view_damage_from(view);
173}
174
175static void handle_new_popup(struct wl_listener *listener, void *data) {
176 struct sway_xdg_shell_view *xdg_shell_view =
177 wl_container_of(listener, xdg_shell_view, new_popup);
178 struct wlr_xdg_popup *wlr_popup = data;
179 popup_create(wlr_popup, &xdg_shell_view->view);
180}
181
182static void handle_unmap(struct wl_listener *listener, void *data) {
183 struct sway_xdg_shell_view *xdg_shell_view =
184 wl_container_of(listener, xdg_shell_view, unmap);
185
186 view_unmap(&xdg_shell_view->view);
187
188 wl_list_remove(&xdg_shell_view->commit.link);
189 wl_list_remove(&xdg_shell_view->new_popup.link);
190}
191
192static void handle_map(struct wl_listener *listener, void *data) {
193 struct sway_xdg_shell_view *xdg_shell_view =
194 wl_container_of(listener, xdg_shell_view, map);
195 struct sway_view *view = &xdg_shell_view->view;
196 struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
197
198 view_map(view, view->wlr_xdg_surface->surface);
199
200 xdg_shell_view->commit.notify = handle_commit;
201 wl_signal_add(&xdg_surface->surface->events.commit,
202 &xdg_shell_view->commit);
203
204 xdg_shell_view->new_popup.notify = handle_new_popup;
205 wl_signal_add(&xdg_surface->events.new_popup,
206 &xdg_shell_view->new_popup);
207
208 if (xdg_surface->toplevel->client_pending.fullscreen) {
209 view_set_fullscreen(view, true);
210 }
211}
212
213static void handle_destroy(struct wl_listener *listener, void *data) {
214 struct sway_xdg_shell_view *xdg_shell_view =
215 wl_container_of(listener, xdg_shell_view, destroy);
216 view_destroy(&xdg_shell_view->view);
217}
218
219static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
220 struct sway_xdg_shell_view *xdg_shell_view =
221 wl_container_of(listener, xdg_shell_view, request_fullscreen);
222 struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
223 struct wlr_xdg_surface *xdg_surface =
224 xdg_shell_view->view.wlr_xdg_surface;
225
226 if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL,
227 "xdg_shell requested fullscreen of surface with role %i",
228 xdg_surface->role)) {
229 return;
230 }
231 if (!xdg_surface->mapped) {
232 return;
233 }
234
235 view_set_fullscreen(&xdg_shell_view->view, e->fullscreen);
236}
237
238void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
239 struct sway_server *server = wl_container_of(listener, server,
240 xdg_shell_surface);
241 struct wlr_xdg_surface *xdg_surface = data;
242
243 if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
244 wlr_log(L_DEBUG, "New xdg_shell popup");
245 return;
246 }
247
248 wlr_log(L_DEBUG, "New xdg_shell toplevel title='%s' app_id='%s'",
249 xdg_surface->toplevel->title, xdg_surface->toplevel->app_id);
250 wlr_xdg_surface_ping(xdg_surface);
251 wlr_xdg_toplevel_set_maximized(xdg_surface, true);
252
253 struct sway_xdg_shell_view *xdg_shell_view =
254 calloc(1, sizeof(struct sway_xdg_shell_view));
255 if (!sway_assert(xdg_shell_view, "Failed to allocate view")) {
256 return;
257 }
258
259 view_init(&xdg_shell_view->view, SWAY_VIEW_XDG_SHELL, &view_impl);
260 xdg_shell_view->view.wlr_xdg_surface = xdg_surface;
261
262 // TODO:
263 // - Look up pid and open on appropriate workspace
264
265 xdg_shell_view->map.notify = handle_map;
266 wl_signal_add(&xdg_surface->events.map, &xdg_shell_view->map);
267
268 xdg_shell_view->unmap.notify = handle_unmap;
269 wl_signal_add(&xdg_surface->events.unmap, &xdg_shell_view->unmap);
270
271 xdg_shell_view->destroy.notify = handle_destroy;
272 wl_signal_add(&xdg_surface->events.destroy, &xdg_shell_view->destroy);
273
274 xdg_shell_view->request_fullscreen.notify = handle_request_fullscreen;
275 wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen,
276 &xdg_shell_view->request_fullscreen);
277}
diff --git a/sway/meson.build b/sway/meson.build
index acf4a3e4..570d4783 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -10,10 +10,11 @@ sway_sources = files(
10 'security.c', 10 'security.c',
11 11
12 'desktop/desktop.c', 12 'desktop/desktop.c',
13 'desktop/output.c',
14 'desktop/layer_shell.c', 13 'desktop/layer_shell.c',
14 'desktop/output.c',
15 'desktop/wl_shell.c', 15 'desktop/wl_shell.c',
16 'desktop/xdg_shell_v6.c', 16 'desktop/xdg_shell_v6.c',
17 'desktop/xdg_shell.c',
17 'desktop/xwayland.c', 18 'desktop/xwayland.c',
18 19
19 'input/input-manager.c', 20 'input/input-manager.c',
diff --git a/sway/server.c b/sway/server.c
index ccc215eb..2c38970e 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -83,6 +83,11 @@ bool server_init(struct sway_server *server) {
83 &server->xdg_shell_v6_surface); 83 &server->xdg_shell_v6_surface);
84 server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; 84 server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface;
85 85
86 server->xdg_shell = wlr_xdg_shell_create(server->wl_display);
87 wl_signal_add(&server->xdg_shell->events.new_surface,
88 &server->xdg_shell_surface);
89 server->xdg_shell_surface.notify = handle_xdg_shell_surface;
90
86 server->wl_shell = wlr_wl_shell_create(server->wl_display); 91 server->wl_shell = wlr_wl_shell_create(server->wl_display);
87 wl_signal_add(&server->wl_shell->events.new_surface, 92 wl_signal_add(&server->wl_shell->events.new_surface,
88 &server->wl_shell_surface); 93 &server->wl_shell_surface);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index fc35a81c..9f7294db 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -7,6 +7,8 @@
7#include <wayland-server.h> 7#include <wayland-server.h>
8#include <wlr/types/wlr_output_layout.h> 8#include <wlr/types/wlr_output_layout.h>
9#include <wlr/types/wlr_wl_shell.h> 9#include <wlr/types/wlr_wl_shell.h>
10#include <wlr/types/wlr_xdg_shell_v6.h>
11#include <wlr/types/wlr_xdg_shell.h>
10#include "cairo.h" 12#include "cairo.h"
11#include "pango.h" 13#include "pango.h"
12#include "sway/config.h" 14#include "sway/config.h"
@@ -459,6 +461,16 @@ struct sway_container *container_at(struct sway_container *parent,
459 sview->wlr_xdg_surface_v6, 461 sview->wlr_xdg_surface_v6,
460 view_sx, view_sy, &_sx, &_sy); 462 view_sx, view_sy, &_sx, &_sy);
461 break; 463 break;
464 case SWAY_VIEW_XDG_SHELL:
465 // the top left corner of the sway container is the
466 // coordinate of the top left corner of the window geometry
467 view_sx += sview->wlr_xdg_surface->geometry.x;
468 view_sy += sview->wlr_xdg_surface->geometry.y;
469
470 _surface = wlr_xdg_surface_surface_at(
471 sview->wlr_xdg_surface,
472 view_sx, view_sy, &_sx, &_sy);
473 break;
462 } 474 }
463 if (_surface) { 475 if (_surface) {
464 *sx = _sx; 476 *sx = _sx;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 9bdc5198..2fdb14a2 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -76,6 +76,8 @@ const char *view_get_type(struct sway_view *view) {
76 return "wl_shell"; 76 return "wl_shell";
77 case SWAY_VIEW_XDG_SHELL_V6: 77 case SWAY_VIEW_XDG_SHELL_V6:
78 return "xdg_shell_v6"; 78 return "xdg_shell_v6";
79 case SWAY_VIEW_XDG_SHELL:
80 return "xdg_shell";
79 case SWAY_VIEW_XWAYLAND: 81 case SWAY_VIEW_XWAYLAND:
80 return "xwayland"; 82 return "xwayland";
81 } 83 }