aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/server.h4
-rw-r--r--include/sway/view.h16
-rw-r--r--sway/desktop/xwayland.c134
-rw-r--r--sway/meson.build1
-rw-r--r--sway/server.c7
5 files changed, 162 insertions, 0 deletions
diff --git a/include/sway/server.h b/include/sway/server.h
index b0684d15..30b15e75 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -30,6 +30,9 @@ struct sway_server {
30 30
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
34 struct wlr_xwayland *xwayland;
35 struct wl_listener xwayland_surface;
33}; 36};
34 37
35struct sway_server server; 38struct sway_server server;
@@ -42,5 +45,6 @@ void output_add_notify(struct wl_listener *listener, void *data);
42void output_remove_notify(struct wl_listener *listener, void *data); 45void output_remove_notify(struct wl_listener *listener, void *data);
43 46
44void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data); 47void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data);
48void handle_xwayland_surface(struct wl_listener *listener, void *data);
45 49
46#endif 50#endif
diff --git a/include/sway/view.h b/include/sway/view.h
index cf2e6f66..2d9b4ef5 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
7struct sway_container; 8struct sway_container;
8struct sway_view; 9struct 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
23struct 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
22enum sway_view_type { 36enum sway_view_type {
23 SWAY_WL_SHELL_VIEW, 37 SWAY_WL_SHELL_VIEW,
24 SWAY_XDG_SHELL_V6_VIEW, 38 SWAY_XDG_SHELL_V6_VIEW,
@@ -46,10 +60,12 @@ struct sway_view {
46 60
47 union { 61 union {
48 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; 62 struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6;
63 struct wlr_xwayland_surface *wlr_xwayland_surface;
49 }; 64 };
50 65
51 union { 66 union {
52 struct sway_xdg_surface_v6 *sway_xdg_surface_v6; 67 struct sway_xdg_surface_v6 *sway_xdg_surface_v6;
68 struct sway_xwayland_surface *sway_xwayland_surface;
53 }; 69 };
54 70
55 struct { 71 struct {
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
17static 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
31static 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
43static 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
55static 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
67static 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
79void 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 cf2aa913..e8e9013f 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -7,6 +7,7 @@ sway_sources = files(
7 'ipc-server.c', 7 'ipc-server.c',
8 'desktop/output.c', 8 'desktop/output.c',
9 'desktop/xdg_shell_v6.c', 9 'desktop/xdg_shell_v6.c',
10 'desktop/xwayland.c',
10 'tree/container.c', 11 'tree/container.c',
11 'tree/layout.c', 12 'tree/layout.c',
12 'tree/workspace.c', 13 'tree/workspace.c',
diff --git a/sway/server.c b/sway/server.c
index 6e66bc3c..2694cea0 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -40,6 +40,13 @@ bool server_init(struct sway_server *server) {
40 &server->xdg_shell_v6_surface); 40 &server->xdg_shell_v6_surface);
41 server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface; 41 server->xdg_shell_v6_surface.notify = handle_xdg_shell_v6_surface;
42 42
43 // TODO make xwayland optional
44 server->xwayland =
45 wlr_xwayland_create(server->wl_display, server->compositor);
46 wl_signal_add(&server->xwayland->events.new_surface,
47 &server->xwayland_surface);
48 server->xwayland_surface.notify = handle_xwayland_surface;
49
43 server->socket = wl_display_add_socket_auto(server->wl_display); 50 server->socket = wl_display_add_socket_auto(server->wl_display);
44 if (!sway_assert(server->socket, "Unable to open wayland socket")) { 51 if (!sway_assert(server->socket, "Unable to open wayland socket")) {
45 wlr_backend_destroy(server->backend); 52 wlr_backend_destroy(server->backend);