From 7b138e5ef0f679c9bb0078019d7c9c63fef36273 Mon Sep 17 00:00:00 2001
From: Ryan Dwyer <ryandwyer1@gmail.com>
Date: Mon, 24 Sep 2018 20:54:57 +1000
Subject: Add CSD to border modes

This replaces view.using_csd with a new border mode: B_CSD. This also
removes sway_xdg_shell{_v6}_view.deco_mode and
view->has_client_side_decorations as we can now get these from the
border.

You can use `border toggle` to cycle through the modes including CSD, or
use `border csd` to set it directly. The client must support the
xdg-decoration protocol, and the only client I know of that does is the
example in wlroots.

If the client switches from SSD to CSD without us expecting it (via the
server-decoration protocol), we stash the previous border type into
view.saved_border so we can restore it if the client returns to SSD. I
haven't found a way to test this though.
---
 sway/decoration.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

(limited to 'sway/decoration.c')

diff --git a/sway/decoration.c b/sway/decoration.c
index 0e3e67ac..fea6ed4c 100644
--- a/sway/decoration.c
+++ b/sway/decoration.c
@@ -1,6 +1,8 @@
 #include <stdlib.h>
 #include "sway/decoration.h"
+#include "sway/desktop/transaction.h"
 #include "sway/server.h"
+#include "sway/tree/arrange.h"
 #include "sway/tree/view.h"
 #include "log.h"
 
@@ -24,20 +26,12 @@ static void server_decoration_handle_mode(struct wl_listener *listener,
 		return;
 	}
 
-	switch (view->type) {
-	case SWAY_VIEW_XDG_SHELL_V6:;
-		struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
-			(struct sway_xdg_shell_v6_view *)view;
-		xdg_shell_v6_view->deco_mode = deco->wlr_server_decoration->mode;
-		break;
-	case SWAY_VIEW_XDG_SHELL:;
-		struct sway_xdg_shell_view *xdg_shell_view =
-			(struct sway_xdg_shell_view *)view;
-		xdg_shell_view->deco_mode = deco->wlr_server_decoration->mode;
-		break;
-	default:
-		break;
-	}
+	bool csd = deco->wlr_server_decoration->mode ==
+			WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
+	view_set_csd_from_client(view, csd);
+
+	arrange_container(view->container);
+	transaction_commit_dirty();
 }
 
 void handle_server_decoration(struct wl_listener *listener, void *data) {
-- 
cgit v1.2.3


From 6d0442c0c2cfcb75f855348b8133abcb2f3c2427 Mon Sep 17 00:00:00 2001
From: Ryan Dwyer <ryandwyer1@gmail.com>
Date: Thu, 27 Sep 2018 17:09:05 +1000
Subject: Rename view_set_csd_from_client to view_update_csd_from_client

---
 include/sway/tree/view.h    | 2 +-
 sway/decoration.c           | 2 +-
 sway/desktop/xdg_shell.c    | 2 +-
 sway/desktop/xdg_shell_v6.c | 2 +-
 sway/desktop/xwayland.c     | 2 +-
 sway/tree/view.c            | 2 +-
 sway/xdg_decoration.c       | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

(limited to 'sway/decoration.c')

diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h
index 49df7c88..e7aaffd7 100644
--- a/include/sway/tree/view.h
+++ b/include/sway/tree/view.h
@@ -275,7 +275,7 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled);
  * Updates the view's border setting when the client unexpectedly changes their
  * decoration mode.
  */
-void view_set_csd_from_client(struct sway_view *view, bool enabled);
+void view_update_csd_from_client(struct sway_view *view, bool enabled);
 
 void view_set_tiled(struct sway_view *view, bool tiled);
 
diff --git a/sway/decoration.c b/sway/decoration.c
index fea6ed4c..849fa89c 100644
--- a/sway/decoration.c
+++ b/sway/decoration.c
@@ -28,7 +28,7 @@ static void server_decoration_handle_mode(struct wl_listener *listener,
 
 	bool csd = deco->wlr_server_decoration->mode ==
 			WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
-	view_set_csd_from_client(view, csd);
+	view_update_csd_from_client(view, csd);
 
 	arrange_container(view->container);
 	transaction_commit_dirty();
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index d563edae..2680af64 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -381,7 +381,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
 		decoration_from_surface(xdg_surface->surface);
 	bool csd = !deco || deco->wlr_server_decoration->mode ==
 		WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
-	view_set_csd_from_client(view, csd);
+	view_update_csd_from_client(view, csd);
 
 	if (xdg_surface->toplevel->client_pending.fullscreen) {
 		container_set_fullscreen(view->container, true);
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 8c8085f7..a7838c0f 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -378,7 +378,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
 		decoration_from_surface(xdg_surface->surface);
 	bool csd = !deco || deco->wlr_server_decoration->mode ==
 			WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
-	view_set_csd_from_client(view, csd);
+	view_update_csd_from_client(view, csd);
 
 	if (xdg_surface->toplevel->client_pending.fullscreen) {
 		container_set_fullscreen(view->container, true);
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index f1205518..4c710f7e 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -250,7 +250,7 @@ static void handle_set_decorations(struct wl_listener *listener, void *data) {
 	struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
 
 	bool csd = xsurface->decorations != WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
-	view_set_csd_from_client(view, csd);
+	view_update_csd_from_client(view, csd);
 }
 
 static void _close(struct sway_view *view) {
diff --git a/sway/tree/view.c b/sway/tree/view.c
index c370de2d..1c94de4c 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -318,7 +318,7 @@ void view_set_csd_from_server(struct sway_view *view, bool enabled) {
 	}
 }
 
-void view_set_csd_from_client(struct sway_view *view, bool enabled) {
+void view_update_csd_from_client(struct sway_view *view, bool enabled) {
 	if (enabled && view->border != B_CSD) {
 		view->saved_border = view->border;
 		view->border = B_CSD;
diff --git a/sway/xdg_decoration.c b/sway/xdg_decoration.c
index 2e7e4bd0..80b2f57e 100644
--- a/sway/xdg_decoration.c
+++ b/sway/xdg_decoration.c
@@ -26,7 +26,7 @@ static void xdg_decoration_handle_surface_commit(struct wl_listener *listener,
 		WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
 	struct sway_view *view = decoration->view;
 
-	view_set_csd_from_client(view, csd);
+	view_update_csd_from_client(view, csd);
 
 	arrange_container(view->container);
 	transaction_commit_dirty();
-- 
cgit v1.2.3