aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dudemanguy <random342@airmail.cc>2021-08-10 12:01:37 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2021-08-12 10:02:17 +0200
commitacf946fe4c495b47c5a76230ba98f9b973bec96d (patch)
treeb73daeffd06e391527170d5117e1dc509c8e82b5
parentDocument view_map (diff)
downloadsway-acf946fe4c495b47c5a76230ba98f9b973bec96d.tar.gz
sway-acf946fe4c495b47c5a76230ba98f9b973bec96d.tar.zst
sway-acf946fe4c495b47c5a76230ba98f9b973bec96d.zip
xdg-decoration: let floating clients set borders
The xdg-decoration protocol allows clients to request whether they want to use server side decorations or client side decorations. Currently, sway ignores this and always enforces whatever the server is currently set to. Although tiled clients cannot be allowed to set borders, there is no harm in listening requests from floating clients. Sidenote: also fix an unrelated style error.
-rw-r--r--sway/desktop/xdg_shell.c7
-rw-r--r--sway/tree/container.c12
-rw-r--r--sway/xdg_decoration.c28
3 files changed, 43 insertions, 4 deletions
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index d34654fd..1f70b193 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -443,12 +443,15 @@ static void handle_map(struct wl_listener *listener, void *data) {
443 443
444 bool csd = false; 444 bool csd = false;
445 445
446 if (!view->xdg_decoration) { 446 if (view->xdg_decoration) {
447 enum wlr_xdg_toplevel_decoration_v1_mode mode =
448 view->xdg_decoration->wlr_xdg_decoration->client_pending_mode;
449 csd = mode == WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
450 } else {
447 struct sway_server_decoration *deco = 451 struct sway_server_decoration *deco =
448 decoration_from_surface(xdg_surface->surface); 452 decoration_from_surface(xdg_surface->surface);
449 csd = !deco || deco->wlr_server_decoration->mode == 453 csd = !deco || deco->wlr_server_decoration->mode ==
450 WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT; 454 WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
451
452 } 455 }
453 456
454 view_map(view, view->wlr_xdg_surface->surface, 457 view_map(view, view->wlr_xdg_surface->surface,
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 1e84e603..3b661046 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -20,6 +20,7 @@
20#include "sway/tree/arrange.h" 20#include "sway/tree/arrange.h"
21#include "sway/tree/view.h" 21#include "sway/tree/view.h"
22#include "sway/tree/workspace.h" 22#include "sway/tree/workspace.h"
23#include "sway/xdg_decoration.h"
23#include "list.h" 24#include "list.h"
24#include "log.h" 25#include "log.h"
25#include "stringop.h" 26#include "stringop.h"
@@ -835,7 +836,13 @@ void container_set_floating(struct sway_container *container, bool enable) {
835 if (container->view) { 836 if (container->view) {
836 view_set_tiled(container->view, false); 837 view_set_tiled(container->view, false);
837 if (container->view->using_csd) { 838 if (container->view->using_csd) {
839 container->saved_border = container->pending.border;
838 container->pending.border = B_CSD; 840 container->pending.border = B_CSD;
841 if (container->view->xdg_decoration) {
842 struct sway_xdg_decoration *deco = container->view->xdg_decoration;
843 wlr_xdg_toplevel_decoration_v1_set_mode(deco->wlr_xdg_decoration,
844 WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
845 }
839 } 846 }
840 } 847 }
841 container_floating_set_default_size(container); 848 container_floating_set_default_size(container);
@@ -873,6 +880,11 @@ void container_set_floating(struct sway_container *container, bool enable) {
873 view_set_tiled(container->view, true); 880 view_set_tiled(container->view, true);
874 if (container->view->using_csd) { 881 if (container->view->using_csd) {
875 container->pending.border = container->saved_border; 882 container->pending.border = container->saved_border;
883 if (container->view->xdg_decoration) {
884 struct sway_xdg_decoration *deco = container->view->xdg_decoration;
885 wlr_xdg_toplevel_decoration_v1_set_mode(deco->wlr_xdg_decoration,
886 WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
887 }
876 } 888 }
877 } 889 }
878 container->width_fraction = 0; 890 container->width_fraction = 0;
diff --git a/sway/xdg_decoration.c b/sway/xdg_decoration.c
index e7c3ea73..8a9a9a28 100644
--- a/sway/xdg_decoration.c
+++ b/sway/xdg_decoration.c
@@ -10,7 +10,7 @@ static void xdg_decoration_handle_destroy(struct wl_listener *listener,
10 void *data) { 10 void *data) {
11 struct sway_xdg_decoration *deco = 11 struct sway_xdg_decoration *deco =
12 wl_container_of(listener, deco, destroy); 12 wl_container_of(listener, deco, destroy);
13 if(deco->view) { 13 if (deco->view) {
14 deco->view->xdg_decoration = NULL; 14 deco->view->xdg_decoration = NULL;
15 } 15 }
16 wl_list_remove(&deco->destroy.link); 16 wl_list_remove(&deco->destroy.link);
@@ -23,8 +23,32 @@ static void xdg_decoration_handle_request_mode(struct wl_listener *listener,
23 void *data) { 23 void *data) {
24 struct sway_xdg_decoration *deco = 24 struct sway_xdg_decoration *deco =
25 wl_container_of(listener, deco, request_mode); 25 wl_container_of(listener, deco, request_mode);
26 struct sway_view *view = deco->view;
27 enum wlr_xdg_toplevel_decoration_v1_mode mode =
28 WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
29 enum wlr_xdg_toplevel_decoration_v1_mode client_mode =
30 deco->wlr_xdg_decoration->client_pending_mode;
31
32 bool floating;
33 if (view->container) {
34 floating = container_is_floating(view->container);
35 bool csd = false;
36 csd = client_mode ==
37 WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
38 view_update_csd_from_client(view, csd);
39 arrange_container(view->container);
40 transaction_commit_dirty();
41 } else {
42 floating = view->impl->wants_floating &&
43 view->impl->wants_floating(view);
44 }
45
46 if (floating && client_mode) {
47 mode = client_mode;
48 }
49
26 wlr_xdg_toplevel_decoration_v1_set_mode(deco->wlr_xdg_decoration, 50 wlr_xdg_toplevel_decoration_v1_set_mode(deco->wlr_xdg_decoration,
27 WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); 51 mode);
28} 52}
29 53
30void handle_xdg_decoration(struct wl_listener *listener, void *data) { 54void handle_xdg_decoration(struct wl_listener *listener, void *data) {