diff options
-rw-r--r-- | include/sway/server.h | 4 | ||||
-rw-r--r-- | include/sway/view.h | 16 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 134 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/server.c | 7 |
5 files changed, 162 insertions, 0 deletions
diff --git a/include/sway/server.h b/include/sway/server.h index bfdb7b8a..3fa72e84 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -31,6 +31,9 @@ struct sway_server { | |||
31 | struct wlr_xdg_shell_v6 *xdg_shell_v6; | 31 | struct wlr_xdg_shell_v6 *xdg_shell_v6; |
32 | struct wl_listener xdg_shell_v6_surface; | 32 | struct wl_listener xdg_shell_v6_surface; |
33 | 33 | ||
34 | struct wlr_xwayland *xwayland; | ||
35 | struct wl_listener xwayland_surface; | ||
36 | |||
34 | struct wlr_wl_shell *wl_shell; | 37 | struct wlr_wl_shell *wl_shell; |
35 | struct wl_listener wl_shell_surface; | 38 | struct wl_listener wl_shell_surface; |
36 | }; | 39 | }; |
@@ -45,6 +48,7 @@ void output_add_notify(struct wl_listener *listener, void *data); | |||
45 | void output_remove_notify(struct wl_listener *listener, void *data); | 48 | void output_remove_notify(struct wl_listener *listener, void *data); |
46 | 49 | ||
47 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); | 50 | void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); |
51 | void handle_xwayland_surface(struct wl_listener *listener, void *data); | ||
48 | void handle_wl_shell_surface(struct wl_listener *listener, void *data); | 52 | void handle_wl_shell_surface(struct wl_listener *listener, void *data); |
49 | 53 | ||
50 | #endif | 54 | #endif |
diff --git a/include/sway/view.h b/include/sway/view.h index 7aa04794..83ac8285 100644 --- a/include/sway/view.h +++ b/include/sway/view.h | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <wayland-server.h> | 3 | #include <wayland-server.h> |
4 | #include <wlr/types/wlr_surface.h> | 4 | #include <wlr/types/wlr_surface.h> |
5 | #include <wlr/types/wlr_xdg_shell_v6.h> | 5 | #include <wlr/types/wlr_xdg_shell_v6.h> |
6 | #include <wlr/xwayland.h> | ||
6 | 7 | ||
7 | struct sway_container; | 8 | struct sway_container; |
8 | struct sway_view; | 9 | struct sway_view; |
@@ -19,6 +20,19 @@ struct sway_xdg_surface_v6 { | |||
19 | int pending_width, pending_height; | 20 | int pending_width, pending_height; |
20 | }; | 21 | }; |
21 | 22 | ||
23 | struct sway_xwayland_surface { | ||
24 | struct sway_view *view; | ||
25 | |||
26 | struct wl_listener commit; | ||
27 | struct wl_listener request_move; | ||
28 | struct wl_listener request_resize; | ||
29 | struct wl_listener request_maximize; | ||
30 | struct wl_listener request_configure; | ||
31 | struct wl_listener destroy; | ||
32 | |||
33 | int pending_width, pending_height; | ||
34 | }; | ||
35 | |||
22 | struct sway_wl_shell_surface { | 36 | struct sway_wl_shell_surface { |
23 | struct sway_view *view; | 37 | struct sway_view *view; |
24 | 38 | ||
@@ -58,11 +72,13 @@ struct sway_view { | |||
58 | 72 | ||
59 | union { | 73 | union { |
60 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; | 74 | struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; |
75 | struct wlr_xwayland_surface *wlr_xwayland_surface; | ||
61 | struct wlr_wl_shell_surface *wlr_wl_shell_surface; | 76 | struct wlr_wl_shell_surface *wlr_wl_shell_surface; |
62 | }; | 77 | }; |
63 | 78 | ||
64 | union { | 79 | union { |
65 | struct sway_xdg_surface_v6 *sway_xdg_surface_v6; | 80 | struct sway_xdg_surface_v6 *sway_xdg_surface_v6; |
81 | struct sway_xwayland_surface *sway_xwayland_surface; | ||
66 | struct sway_wl_shell_surface *sway_wl_shell_surface; | 82 | struct sway_wl_shell_surface *sway_wl_shell_surface; |
67 | }; | 83 | }; |
68 | 84 | ||
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c new file mode 100644 index 00000000..04ec118d --- /dev/null +++ b/sway/desktop/xwayland.c | |||
@@ -0,0 +1,134 @@ | |||
1 | #define _POSIX_C_SOURCE 199309L | ||
2 | #include <stdbool.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <wayland-server.h> | ||
5 | #include <wlr/xwayland.h> | ||
6 | #include "sway/container.h" | ||
7 | #include "sway/layout.h" | ||
8 | #include "sway/server.h" | ||
9 | #include "sway/view.h" | ||
10 | #include "log.h" | ||
11 | |||
12 | static bool assert_xwayland(struct sway_view *view) { | ||
13 | return sway_assert(view->type == SWAY_XWAYLAND_VIEW, | ||
14 | "Expected xwayland view!"); | ||
15 | } | ||
16 | |||
17 | static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { | ||
18 | if (!assert_xwayland(view)) { | ||
19 | return NULL; | ||
20 | } | ||
21 | switch (prop) { | ||
22 | case VIEW_PROP_TITLE: | ||
23 | return view->wlr_xwayland_surface->title; | ||
24 | case VIEW_PROP_CLASS: | ||
25 | return view->wlr_xwayland_surface->class; | ||
26 | default: | ||
27 | return NULL; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | static void set_size(struct sway_view *view, int width, int height) { | ||
32 | if (!assert_xwayland(view)) { | ||
33 | return; | ||
34 | } | ||
35 | view->sway_xwayland_surface->pending_width = width; | ||
36 | view->sway_xwayland_surface->pending_height = height; | ||
37 | |||
38 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | ||
39 | wlr_xwayland_surface_configure(xsurface, view->swayc->x, view->swayc->y, | ||
40 | width, height); | ||
41 | } | ||
42 | |||
43 | static void handle_commit(struct wl_listener *listener, void *data) { | ||
44 | struct sway_xwayland_surface *sway_surface = | ||
45 | wl_container_of(listener, sway_surface, commit); | ||
46 | struct sway_view *view = sway_surface->view; | ||
47 | sway_log(L_DEBUG, "xwayland surface commit %dx%d", | ||
48 | sway_surface->pending_width, sway_surface->pending_height); | ||
49 | // NOTE: We intentionally discard the view's desired width here | ||
50 | // TODO: Let floating views do whatever | ||
51 | view->width = sway_surface->pending_width; | ||
52 | view->height = sway_surface->pending_height; | ||
53 | } | ||
54 | |||
55 | static void handle_destroy(struct wl_listener *listener, void *data) { | ||
56 | struct sway_xwayland_surface *sway_surface = | ||
57 | wl_container_of(listener, sway_surface, destroy); | ||
58 | wl_list_remove(&sway_surface->commit.link); | ||
59 | wl_list_remove(&sway_surface->destroy.link); | ||
60 | wl_list_remove(&sway_surface->request_configure.link); | ||
61 | swayc_t *parent = destroy_view(sway_surface->view->swayc); | ||
62 | free(sway_surface->view); | ||
63 | free(sway_surface); | ||
64 | arrange_windows(parent, -1, -1); | ||
65 | } | ||
66 | |||
67 | static void handle_configure_request(struct wl_listener *listener, void *data) { | ||
68 | struct sway_xwayland_surface *sway_surface = | ||
69 | wl_container_of(listener, sway_surface, request_configure); | ||
70 | struct wlr_xwayland_surface_configure_event *ev = data; | ||
71 | struct sway_view *view = sway_surface->view; | ||
72 | struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; | ||
73 | // TODO: floating windows are allowed to move around like this, but make | ||
74 | // sure tiling windows always stay in place. | ||
75 | wlr_xwayland_surface_configure(xsurface, ev->x, ev->y, | ||
76 | ev->width, ev->height); | ||
77 | } | ||
78 | |||
79 | void handle_xwayland_surface(struct wl_listener *listener, void *data) { | ||
80 | struct sway_server *server = wl_container_of( | ||
81 | listener, server, xwayland_surface); | ||
82 | struct wlr_xwayland_surface *xsurface = data; | ||
83 | |||
84 | if (xsurface->override_redirect) { | ||
85 | // TODO: floating popups | ||
86 | return; | ||
87 | } | ||
88 | |||
89 | sway_log(L_DEBUG, "New xwayland surface title='%s' class='%s'", | ||
90 | xsurface->title, xsurface->class); | ||
91 | |||
92 | struct sway_xwayland_surface *sway_surface = | ||
93 | calloc(1, sizeof(struct sway_xwayland_surface)); | ||
94 | if (!sway_assert(sway_surface, "Failed to allocate surface!")) { | ||
95 | return; | ||
96 | } | ||
97 | |||
98 | struct sway_view *sway_view = calloc(1, sizeof(struct sway_view)); | ||
99 | if (!sway_assert(sway_view, "Failed to allocate view!")) { | ||
100 | return; | ||
101 | } | ||
102 | sway_view->type = SWAY_XWAYLAND_VIEW; | ||
103 | sway_view->iface.get_prop = get_prop; | ||
104 | sway_view->iface.set_size = set_size; | ||
105 | sway_view->wlr_xwayland_surface = xsurface; | ||
106 | sway_view->sway_xwayland_surface = sway_surface; | ||
107 | // TODO remove from the tree when the surface goes away (unmapped) | ||
108 | sway_view->surface = xsurface->surface; | ||
109 | sway_surface->view = sway_view; | ||
110 | |||
111 | // TODO: | ||
112 | // - Wire up listeners | ||
113 | // - Handle popups | ||
114 | // - Look up pid and open on appropriate workspace | ||
115 | // - Set new view to maximized so it behaves nicely | ||
116 | // - Criteria | ||
117 | |||
118 | sway_surface->commit.notify = handle_commit; | ||
119 | wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); | ||
120 | sway_surface->destroy.notify = handle_destroy; | ||
121 | wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); | ||
122 | sway_surface->request_configure.notify = handle_configure_request; | ||
123 | wl_signal_add(&xsurface->events.request_configure, | ||
124 | &sway_surface->request_configure); | ||
125 | |||
126 | // TODO: actual focus semantics | ||
127 | swayc_t *parent = root_container.children->items[0]; | ||
128 | parent = parent->children->items[0]; // workspace | ||
129 | |||
130 | swayc_t *cont = new_view(parent, sway_view); | ||
131 | sway_view->swayc = cont; | ||
132 | |||
133 | arrange_windows(cont->parent, -1, -1); | ||
134 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index dd3570bf..9f92f5d1 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -8,6 +8,7 @@ sway_sources = files( | |||
8 | 'desktop/output.c', | 8 | 'desktop/output.c', |
9 | 'desktop/wl_shell.c', | 9 | 'desktop/wl_shell.c', |
10 | 'desktop/xdg_shell_v6.c', | 10 | 'desktop/xdg_shell_v6.c', |
11 | 'desktop/xwayland.c', | ||
11 | 'tree/container.c', | 12 | 'tree/container.c', |
12 | 'tree/layout.c', | 13 | 'tree/layout.c', |
13 | 'tree/workspace.c', | 14 | 'tree/workspace.c', |
diff --git a/sway/server.c b/sway/server.c index bf5c37eb..024d8429 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -41,6 +41,13 @@ bool server_init(struct sway_server *server) { | |||
41 | &server->xdg_shell_v6_surface); | 41 | &server->xdg_shell_v6_surface); |
42 | server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; | 42 | server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; |
43 | 43 | ||
44 | // TODO make xwayland optional | ||
45 | server->xwayland = | ||
46 | wlr_xwayland_create(server->wl_display, server->compositor); | ||
47 | wl_signal_add(&server->xwayland->events.new_surface, | ||
48 | &server->xwayland_surface); | ||
49 | server->xwayland_surface.notify = handle_xwayland_surface; | ||
50 | |||
44 | server->wl_shell = wlr_wl_shell_create(server->wl_display); | 51 | server->wl_shell = wlr_wl_shell_create(server->wl_display); |
45 | wl_signal_add(&server->wl_shell->events.new_surface, | 52 | wl_signal_add(&server->wl_shell->events.new_surface, |
46 | &server->wl_shell_surface); | 53 | &server->wl_shell_surface); |