summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-06-26 20:31:32 -0700
committerLibravatar GitHub <noreply@github.com>2018-06-26 20:31:32 -0700
commit152ccd7fb14dc0f09f9c6f902f727f7addf7657a (patch)
tree0c0951e0ec5c36a6de14535903092b539bdbbf9b
parentMerge pull request #2162 from martinetd/float_xdg_shell (diff)
parentMerge branch 'master' into xwayland-wants-float (diff)
downloadsway-152ccd7fb14dc0f09f9c6f902f727f7addf7657a.tar.gz
sway-152ccd7fb14dc0f09f9c6f902f727f7addf7657a.tar.zst
sway-152ccd7fb14dc0f09f9c6f902f727f7addf7657a.zip
Merge pull request #2145 from emersion/xwayland-wants-float
Automatically float xwayland windows
-rw-r--r--include/sway/server.h9
-rw-r--r--include/sway/xwayland.h25
-rw-r--r--meson.build3
-rw-r--r--sway/desktop/xwayland.c91
-rw-r--r--sway/input/seat.c3
-rw-r--r--sway/meson.build1
-rw-r--r--sway/server.c18
7 files changed, 122 insertions, 28 deletions
diff --git a/include/sway/server.h b/include/sway/server.h
index 963d4dc1..b016aba8 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -11,7 +11,7 @@
11#include <wlr/types/wlr_xdg_shell.h> 11#include <wlr/types/wlr_xdg_shell.h>
12#include <wlr/render/wlr_renderer.h> 12#include <wlr/render/wlr_renderer.h>
13// TODO WLR: make Xwayland optional 13// TODO WLR: make Xwayland optional
14#include <wlr/xwayland.h> 14#include "sway/xwayland.h"
15 15
16struct sway_server { 16struct sway_server {
17 struct wl_display *wl_display; 17 struct wl_display *wl_display;
@@ -37,12 +37,9 @@ struct sway_server {
37 struct wlr_xdg_shell *xdg_shell; 37 struct wlr_xdg_shell *xdg_shell;
38 struct wl_listener xdg_shell_surface; 38 struct wl_listener xdg_shell_surface;
39 39
40 struct wlr_xwayland *xwayland; 40 struct sway_xwayland xwayland;
41 struct wlr_xcursor_manager *xcursor_manager;
42 struct wl_listener xwayland_surface; 41 struct wl_listener xwayland_surface;
43 42 struct wl_listener xwayland_ready;
44 struct wlr_wl_shell *wl_shell;
45 struct wl_listener wl_shell_surface;
46}; 43};
47 44
48struct sway_server server; 45struct sway_server server;
diff --git a/include/sway/xwayland.h b/include/sway/xwayland.h
new file mode 100644
index 00000000..78d1053b
--- /dev/null
+++ b/include/sway/xwayland.h
@@ -0,0 +1,25 @@
1#ifndef SWAY_XWAYLAND_H
2#define SWAY_XWAYLAND_H
3
4#include <wlr/xwayland.h>
5#include <xcb/xproto.h>
6
7enum atom_name {
8 NET_WM_WINDOW_TYPE_DIALOG,
9 NET_WM_WINDOW_TYPE_UTILITY,
10 NET_WM_WINDOW_TYPE_TOOLBAR,
11 NET_WM_WINDOW_TYPE_SPLASH,
12 NET_WM_STATE_MODAL,
13 ATOM_LAST,
14};
15
16struct sway_xwayland {
17 struct wlr_xwayland *wlr_xwayland;
18 struct wlr_xcursor_manager *xcursor_manager;
19
20 xcb_atom_t atoms[ATOM_LAST];
21};
22
23void handle_xwayland_ready(struct wl_listener *listener, void *data);
24
25#endif
diff --git a/meson.build b/meson.build
index d4ee1a11..1d40581a 100644
--- a/meson.build
+++ b/meson.build
@@ -43,7 +43,8 @@ systemd = dependency('libsystemd', required: false)
43elogind = dependency('libelogind', required: false) 43elogind = dependency('libelogind', required: false)
44math = cc.find_library('m') 44math = cc.find_library('m')
45rt = cc.find_library('rt') 45rt = cc.find_library('rt')
46git = find_program('git', required: false) 46xcb = dependency('xcb')
47git = find_program('git', required: false)
47 48
48conf_data = configuration_data() 49conf_data = configuration_data()
49 50
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 6447b711..eb39dc4b 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -15,6 +15,14 @@
15#include "sway/tree/layout.h" 15#include "sway/tree/layout.h"
16#include "sway/tree/view.h" 16#include "sway/tree/view.h"
17 17
18static const char *atom_map[ATOM_LAST] = {
19 "_NET_WM_WINDOW_TYPE_DIALOG",
20 "_NET_WM_WINDOW_TYPE_UTILITY",
21 "_NET_WM_WINDOW_TYPE_TOOLBAR",
22 "_NET_WM_WINDOW_TYPE_SPLASH",
23 "_NET_WM_STATE_MODAL",
24};
25
18static void unmanaged_handle_request_configure(struct wl_listener *listener, 26static void unmanaged_handle_request_configure(struct wl_listener *listener,
19 void *data) { 27 void *data) {
20 struct sway_xwayland_unmanaged *surface = 28 struct sway_xwayland_unmanaged *surface =
@@ -61,7 +69,8 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) {
61 69
62 if (!wlr_xwayland_surface_is_unmanaged(xsurface)) { 70 if (!wlr_xwayland_surface_is_unmanaged(xsurface)) {
63 struct sway_seat *seat = input_manager_current_seat(input_manager); 71 struct sway_seat *seat = input_manager_current_seat(input_manager);
64 struct wlr_xwayland *xwayland = seat->input->server->xwayland; 72 struct wlr_xwayland *xwayland =
73 seat->input->server->xwayland.wlr_xwayland;
65 wlr_xwayland_set_seat(xwayland, seat->wlr_seat); 74 wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
66 seat_set_focus_surface(seat, xsurface->surface); 75 seat_set_focus_surface(seat, xsurface->surface);
67 } 76 }
@@ -199,15 +208,32 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) {
199} 208}
200 209
201static bool wants_floating(struct sway_view *view) { 210static bool wants_floating(struct sway_view *view) {
202 // TODO: 211 if (xwayland_view_from_view(view) == NULL) {
203 // We want to return true if the window type contains any of these: 212 return false;
204 // NET_WM_WINDOW_TYPE_DIALOG 213 }
205 // NET_WM_WINDOW_TYPE_UTILITY 214 struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface;
206 // NET_WM_WINDOW_TYPE_TOOLBAR 215 struct sway_xwayland *xwayland = &server.xwayland;
207 // NET_WM_WINDOW_TYPE_SPLASH 216
208 // 217 // TODO: return true if the NET_WM_STATE is MODAL
209 // We also want to return true if the NET_WM_STATE is MODAL. 218
210 // wlroots doesn't appear to provide all this information at the moment. 219 for (size_t i = 0; i < surface->window_type_len; ++i) {
220 xcb_atom_t type = surface->window_type[i];
221 if (type == xwayland->atoms[NET_WM_WINDOW_TYPE_DIALOG] ||
222 type == xwayland->atoms[NET_WM_WINDOW_TYPE_UTILITY] ||
223 type == xwayland->atoms[NET_WM_WINDOW_TYPE_TOOLBAR] ||
224 type == xwayland->atoms[NET_WM_WINDOW_TYPE_SPLASH]) {
225 return true;
226 }
227 }
228
229 struct wlr_xwayland_surface_size_hints *size_hints = surface->size_hints;
230 if (size_hints != NULL &&
231 size_hints->min_width != 0 && size_hints->min_height != 0 &&
232 size_hints->max_width == size_hints->min_width &&
233 size_hints->max_height == size_hints->min_height) {
234 return true;
235 }
236
211 return false; 237 return false;
212} 238}
213 239
@@ -308,8 +334,12 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
308 ev->width, ev->height); 334 ev->width, ev->height);
309 return; 335 return;
310 } 336 }
311 // TODO: Let floating views do whatever 337 if (container_is_floating(view->swayc)) {
312 configure(view, view->swayc->x, view->swayc->y, view->width, view->height); 338 configure(view, view->swayc->x, view->swayc->y, ev->width, ev->height);
339 } else {
340 configure(view, view->swayc->x, view->swayc->y,
341 view->width, view->height);
342 }
313} 343}
314 344
315static void handle_request_fullscreen(struct wl_listener *listener, void *data) { 345static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
@@ -411,3 +441,40 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
411 wl_signal_add(&xsurface->events.map, &xwayland_view->map); 441 wl_signal_add(&xsurface->events.map, &xwayland_view->map);
412 xwayland_view->map.notify = handle_map; 442 xwayland_view->map.notify = handle_map;
413} 443}
444
445void handle_xwayland_ready(struct wl_listener *listener, void *data) {
446 struct sway_server *server =
447 wl_container_of(listener, server, xwayland_ready);
448 struct sway_xwayland *xwayland = &server->xwayland;
449
450 xcb_connection_t *xcb_conn = xcb_connect(NULL, NULL);
451 int err = xcb_connection_has_error(xcb_conn);
452 if (err) {
453 wlr_log(L_ERROR, "XCB connect failed: %d", err);
454 return;
455 }
456
457 xcb_intern_atom_cookie_t cookies[ATOM_LAST];
458 for (size_t i = 0; i < ATOM_LAST; i++) {
459 cookies[i] =
460 xcb_intern_atom(xcb_conn, 0, strlen(atom_map[i]), atom_map[i]);
461 }
462 for (size_t i = 0; i < ATOM_LAST; i++) {
463 xcb_generic_error_t *error = NULL;
464 xcb_intern_atom_reply_t *reply =
465 xcb_intern_atom_reply(xcb_conn, cookies[i], &error);
466 if (reply != NULL && error == NULL) {
467 xwayland->atoms[i] = reply->atom;
468 }
469 free(reply);
470
471 if (error != NULL) {
472 wlr_log(L_ERROR, "could not resolve atom %s, X11 error code %d",
473 atom_map[i], error->error_code);
474 free(error);
475 break;
476 }
477 }
478
479 xcb_disconnect(xcb_conn);
480}
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 1ea36466..1c2434b0 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -99,7 +99,8 @@ static void seat_send_focus(struct sway_container *con,
99 if (con->type == C_VIEW 99 if (con->type == C_VIEW
100 && seat_is_input_allowed(seat, con->sway_view->surface)) { 100 && seat_is_input_allowed(seat, con->sway_view->surface)) {
101 if (con->sway_view->type == SWAY_VIEW_XWAYLAND) { 101 if (con->sway_view->type == SWAY_VIEW_XWAYLAND) {
102 struct wlr_xwayland *xwayland = seat->input->server->xwayland; 102 struct wlr_xwayland *xwayland =
103 seat->input->server->xwayland.wlr_xwayland;
103 wlr_xwayland_set_seat(xwayland, seat->wlr_seat); 104 wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
104 } 105 }
105 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat); 106 struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->wlr_seat);
diff --git a/sway/meson.build b/sway/meson.build
index 0da67ed7..2cf90b11 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -152,6 +152,7 @@ sway_deps = [
152 server_protos, 152 server_protos,
153 wayland_server, 153 wayland_server,
154 wlroots, 154 wlroots,
155 xcb,
155 xkbcommon, 156 xkbcommon,
156] 157]
157 158
diff --git a/sway/server.c b/sway/server.c
index a467283b..5b052494 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -19,12 +19,11 @@
19#include <wlr/types/wlr_xdg_output.h> 19#include <wlr/types/wlr_xdg_output.h>
20#include <wlr/util/log.h> 20#include <wlr/util/log.h>
21// TODO WLR: make Xwayland optional 21// TODO WLR: make Xwayland optional
22#include <wlr/xwayland.h>
23#include "sway/config.h" 22#include "sway/config.h"
24#include "sway/input/input-manager.h" 23#include "sway/input/input-manager.h"
25#include "sway/server.h" 24#include "sway/server.h"
26#include "sway/tree/layout.h" 25#include "sway/tree/layout.h"
27 26#include "sway/xwayland.h"
28 27
29bool server_privileged_prepare(struct sway_server *server) { 28bool server_privileged_prepare(struct sway_server *server) {
30 wlr_log(L_DEBUG, "Preparing Wayland server initialization"); 29 wlr_log(L_DEBUG, "Preparing Wayland server initialization");
@@ -78,20 +77,23 @@ bool server_init(struct sway_server *server) {
78 server->xdg_shell_surface.notify = handle_xdg_shell_surface; 77 server->xdg_shell_surface.notify = handle_xdg_shell_surface;
79 78
80 // TODO make xwayland optional 79 // TODO make xwayland optional
81 server->xwayland = 80 server->xwayland.wlr_xwayland =
82 wlr_xwayland_create(server->wl_display, server->compositor, true); 81 wlr_xwayland_create(server->wl_display, server->compositor, true);
83 wl_signal_add(&server->xwayland->events.new_surface, 82 wl_signal_add(&server->xwayland.wlr_xwayland->events.new_surface,
84 &server->xwayland_surface); 83 &server->xwayland_surface);
85 server->xwayland_surface.notify = handle_xwayland_surface; 84 server->xwayland_surface.notify = handle_xwayland_surface;
85 wl_signal_add(&server->xwayland.wlr_xwayland->events.ready,
86 &server->xwayland_ready);
87 server->xwayland_ready.notify = handle_xwayland_ready;
86 88
87 // TODO: configurable cursor theme and size 89 // TODO: configurable cursor theme and size
88 server->xcursor_manager = wlr_xcursor_manager_create(NULL, 24); 90 server->xwayland.xcursor_manager = wlr_xcursor_manager_create(NULL, 24);
89 wlr_xcursor_manager_load(server->xcursor_manager, 1); 91 wlr_xcursor_manager_load(server->xwayland.xcursor_manager, 1);
90 struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( 92 struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(
91 server->xcursor_manager, "left_ptr", 1); 93 server->xwayland.xcursor_manager, "left_ptr", 1);
92 if (xcursor != NULL) { 94 if (xcursor != NULL) {
93 struct wlr_xcursor_image *image = xcursor->images[0]; 95 struct wlr_xcursor_image *image = xcursor->images[0];
94 wlr_xwayland_set_cursor(server->xwayland, image->buffer, 96 wlr_xwayland_set_cursor(server->xwayland.wlr_xwayland, image->buffer,
95 image->width * 4, image->width, image->height, image->hotspot_x, 97 image->width * 4, image->width, image->height, image->hotspot_x,
96 image->hotspot_y); 98 image->hotspot_y);
97 } 99 }