mirror of
				https://github.com/swaywm/sway.git
				synced 2025-11-03 09:01:43 -05:00 
			
		
		
		
	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.
			
			
This commit is contained in:
		
							parent
							
								
									58af001517
								
							
						
					
					
						commit
						7b138e5ef0
					
				
					 18 changed files with 251 additions and 141 deletions
				
			
		| 
						 | 
				
			
			@ -54,6 +54,10 @@ struct sway_server {
 | 
			
		|||
	struct wl_listener server_decoration;
 | 
			
		||||
	struct wl_list decorations; // sway_server_decoration::link
 | 
			
		||||
 | 
			
		||||
	struct wlr_xdg_decoration_manager_v1 *xdg_decoration_manager;
 | 
			
		||||
	struct wl_listener xdg_decoration;
 | 
			
		||||
	struct wl_list xdg_decorations; // sway_xdg_decoration::link
 | 
			
		||||
 | 
			
		||||
	size_t txn_timeout_ms;
 | 
			
		||||
	list_t *transactions;
 | 
			
		||||
	list_t *dirty_nodes;
 | 
			
		||||
| 
						 | 
				
			
			@ -78,5 +82,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data);
 | 
			
		|||
void handle_xwayland_surface(struct wl_listener *listener, void *data);
 | 
			
		||||
#endif
 | 
			
		||||
void handle_server_decoration(struct wl_listener *listener, void *data);
 | 
			
		||||
void handle_xdg_decoration(struct wl_listener *listener, void *data);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ enum sway_container_border {
 | 
			
		|||
	B_NONE,
 | 
			
		||||
	B_PIXEL,
 | 
			
		||||
	B_NORMAL,
 | 
			
		||||
	B_CSD,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct sway_root;
 | 
			
		||||
| 
						 | 
				
			
			@ -63,7 +64,6 @@ struct sway_container_state {
 | 
			
		|||
	bool border_bottom;
 | 
			
		||||
	bool border_left;
 | 
			
		||||
	bool border_right;
 | 
			
		||||
	bool using_csd;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct sway_container {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,7 @@
 | 
			
		|||
#include "sway/input/seat.h"
 | 
			
		||||
 | 
			
		||||
struct sway_container;
 | 
			
		||||
struct sway_xdg_decoration;
 | 
			
		||||
 | 
			
		||||
enum sway_view_type {
 | 
			
		||||
	SWAY_VIEW_XDG_SHELL_V6,
 | 
			
		||||
| 
						 | 
				
			
			@ -44,7 +45,6 @@ struct sway_view_impl {
 | 
			
		|||
	void (*set_tiled)(struct sway_view *view, bool tiled);
 | 
			
		||||
	void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
 | 
			
		||||
	bool (*wants_floating)(struct sway_view *view);
 | 
			
		||||
	bool (*has_client_side_decorations)(struct sway_view *view);
 | 
			
		||||
	void (*for_each_surface)(struct sway_view *view,
 | 
			
		||||
		wlr_surface_iterator_func_t iterator, void *user_data);
 | 
			
		||||
	void (*for_each_popup)(struct sway_view *view,
 | 
			
		||||
| 
						 | 
				
			
			@ -60,6 +60,7 @@ struct sway_view {
 | 
			
		|||
 | 
			
		||||
	struct sway_container *container; // NULL if unmapped and transactions finished
 | 
			
		||||
	struct wlr_surface *surface; // NULL for unmapped views
 | 
			
		||||
	struct sway_xdg_decoration *xdg_decoration;
 | 
			
		||||
 | 
			
		||||
	pid_t pid;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -76,12 +77,12 @@ struct sway_view {
 | 
			
		|||
 | 
			
		||||
	char *title_format;
 | 
			
		||||
	enum sway_container_border border;
 | 
			
		||||
	enum sway_container_border saved_border;
 | 
			
		||||
	int border_thickness;
 | 
			
		||||
	bool border_top;
 | 
			
		||||
	bool border_bottom;
 | 
			
		||||
	bool border_left;
 | 
			
		||||
	bool border_right;
 | 
			
		||||
	bool using_csd;
 | 
			
		||||
 | 
			
		||||
	struct timespec urgent;
 | 
			
		||||
	bool allow_request_urgent;
 | 
			
		||||
| 
						 | 
				
			
			@ -127,8 +128,6 @@ struct sway_view {
 | 
			
		|||
struct sway_xdg_shell_v6_view {
 | 
			
		||||
	struct sway_view view;
 | 
			
		||||
 | 
			
		||||
	enum wlr_server_decoration_manager_mode deco_mode;
 | 
			
		||||
 | 
			
		||||
	struct wl_listener commit;
 | 
			
		||||
	struct wl_listener request_move;
 | 
			
		||||
	struct wl_listener request_resize;
 | 
			
		||||
| 
						 | 
				
			
			@ -145,8 +144,6 @@ struct sway_xdg_shell_v6_view {
 | 
			
		|||
struct sway_xdg_shell_view {
 | 
			
		||||
	struct sway_view view;
 | 
			
		||||
 | 
			
		||||
	enum wlr_server_decoration_manager_mode deco_mode;
 | 
			
		||||
 | 
			
		||||
	struct wl_listener commit;
 | 
			
		||||
	struct wl_listener request_move;
 | 
			
		||||
	struct wl_listener request_resize;
 | 
			
		||||
| 
						 | 
				
			
			@ -175,6 +172,7 @@ struct sway_xwayland_view {
 | 
			
		|||
	struct wl_listener set_role;
 | 
			
		||||
	struct wl_listener set_window_type;
 | 
			
		||||
	struct wl_listener set_hints;
 | 
			
		||||
	struct wl_listener set_decorations;
 | 
			
		||||
	struct wl_listener map;
 | 
			
		||||
	struct wl_listener unmap;
 | 
			
		||||
	struct wl_listener destroy;
 | 
			
		||||
| 
						 | 
				
			
			@ -268,6 +266,17 @@ void view_set_activated(struct sway_view *view, bool activated);
 | 
			
		|||
 */
 | 
			
		||||
void view_request_activate(struct sway_view *view);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * If possible, instructs the client to change their decoration mode.
 | 
			
		||||
 */
 | 
			
		||||
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_set_tiled(struct sway_view *view, bool tiled);
 | 
			
		||||
 | 
			
		||||
void view_close(struct sway_view *view);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										19
									
								
								include/sway/xdg_decoration.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								include/sway/xdg_decoration.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
#ifndef _SWAY_XDG_DECORATION_H
 | 
			
		||||
#define _SWAY_XDG_DECORATION_H
 | 
			
		||||
 | 
			
		||||
#include <wlr/types/wlr_xdg_decoration_v1.h>
 | 
			
		||||
 | 
			
		||||
struct sway_xdg_decoration {
 | 
			
		||||
	struct wlr_xdg_toplevel_decoration_v1 *wlr_xdg_decoration;
 | 
			
		||||
	struct wl_list link;
 | 
			
		||||
 | 
			
		||||
	struct sway_view *view;
 | 
			
		||||
 | 
			
		||||
	struct wl_listener destroy;
 | 
			
		||||
	struct wl_listener surface_commit;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct sway_xdg_decoration *xdg_decoration_from_surface(
 | 
			
		||||
	struct wlr_surface *surface);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -7,6 +7,17 @@
 | 
			
		|||
#include "sway/tree/container.h"
 | 
			
		||||
#include "sway/tree/view.h"
 | 
			
		||||
 | 
			
		||||
static void set_border(struct sway_view *view,
 | 
			
		||||
		enum sway_container_border new_border) {
 | 
			
		||||
	if (view->border == B_CSD && new_border != B_CSD) {
 | 
			
		||||
		view_set_csd_from_server(view, false);
 | 
			
		||||
	} else if (view->border != B_CSD && new_border == B_CSD) {
 | 
			
		||||
		view_set_csd_from_server(view, true);
 | 
			
		||||
	}
 | 
			
		||||
	view->saved_border = view->border;
 | 
			
		||||
	view->border = new_border;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct cmd_results *cmd_border(int argc, char **argv) {
 | 
			
		||||
	struct cmd_results *error = NULL;
 | 
			
		||||
	if ((error = checkarg(argc, "border", EXPECTED_AT_LEAST, 1))) {
 | 
			
		||||
| 
						 | 
				
			
			@ -21,13 +32,15 @@ struct cmd_results *cmd_border(int argc, char **argv) {
 | 
			
		|||
	struct sway_view *view = container->view;
 | 
			
		||||
 | 
			
		||||
	if (strcmp(argv[0], "none") == 0) {
 | 
			
		||||
		view->border = B_NONE;
 | 
			
		||||
		set_border(view, B_NONE);
 | 
			
		||||
	} else if (strcmp(argv[0], "normal") == 0) {
 | 
			
		||||
		view->border = B_NORMAL;
 | 
			
		||||
		set_border(view, B_NORMAL);
 | 
			
		||||
	} else if (strcmp(argv[0], "pixel") == 0) {
 | 
			
		||||
		view->border = B_PIXEL;
 | 
			
		||||
		set_border(view, B_PIXEL);
 | 
			
		||||
	} else if (strcmp(argv[0], "csd") == 0) {
 | 
			
		||||
		set_border(view, B_CSD);
 | 
			
		||||
	} else if (strcmp(argv[0], "toggle") == 0) {
 | 
			
		||||
		view->border = (view->border + 1) % 3;
 | 
			
		||||
		set_border(view, (view->border + 1) % 4);
 | 
			
		||||
	} else {
 | 
			
		||||
		return cmd_results_new(CMD_INVALID, "border",
 | 
			
		||||
				"Expected 'border <none|normal|pixel|toggle>' "
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -272,7 +272,7 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
 | 
			
		|||
		render_view_toplevels(view, output, damage, view->container->alpha);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (view->container->current.using_csd) {
 | 
			
		||||
	if (con->current.border == B_NONE || con->current.border == B_CSD) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -281,7 +281,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
 | 
			
		|||
	float color[4];
 | 
			
		||||
	struct sway_container_state *state = &con->current;
 | 
			
		||||
 | 
			
		||||
	if (state->border != B_NONE) {
 | 
			
		||||
	if (state->border_left) {
 | 
			
		||||
		memcpy(&color, colors->child_border, sizeof(float) * 4);
 | 
			
		||||
		premultiply_alpha(color, con->alpha);
 | 
			
		||||
| 
						 | 
				
			
			@ -327,7 +326,6 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
 | 
			
		|||
		render_rect(output->wlr_output, damage, &box, color);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Render a titlebar.
 | 
			
		||||
| 
						 | 
				
			
			@ -645,15 +643,13 @@ static void render_containers_linear(struct sway_output *output,
 | 
			
		|||
				marks_texture = view->marks_unfocused;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (!view->container->current.using_csd) {
 | 
			
		||||
			if (state->border == B_NORMAL) {
 | 
			
		||||
				render_titlebar(output, damage, child, state->con_x,
 | 
			
		||||
						state->con_y, state->con_width, colors,
 | 
			
		||||
						title_texture, marks_texture);
 | 
			
		||||
				} else {
 | 
			
		||||
			} else if (state->border == B_PIXEL) {
 | 
			
		||||
				render_top_border(output, damage, child, colors);
 | 
			
		||||
			}
 | 
			
		||||
			}
 | 
			
		||||
			render_view(output, damage, child, colors);
 | 
			
		||||
		} else {
 | 
			
		||||
			render_container(output, damage, child,
 | 
			
		||||
| 
						 | 
				
			
			@ -859,15 +855,13 @@ static void render_floating_container(struct sway_output *soutput,
 | 
			
		|||
			marks_texture = view->marks_unfocused;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!view->container->current.using_csd) {
 | 
			
		||||
		if (con->current.border == B_NORMAL) {
 | 
			
		||||
			render_titlebar(soutput, damage, con, con->current.con_x,
 | 
			
		||||
					con->current.con_y, con->current.con_width, colors,
 | 
			
		||||
					title_texture, marks_texture);
 | 
			
		||||
			} else if (con->current.border != B_NONE) {
 | 
			
		||||
		} else if (con->current.border == B_PIXEL) {
 | 
			
		||||
			render_top_border(soutput, damage, con, colors);
 | 
			
		||||
		}
 | 
			
		||||
		}
 | 
			
		||||
		render_view(soutput, damage, con, colors);
 | 
			
		||||
	} else {
 | 
			
		||||
		render_container(soutput, damage, con, con->current.focused);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -167,7 +167,6 @@ static void copy_container_state(struct sway_container *container,
 | 
			
		|||
		state->border_left = view->border_left;
 | 
			
		||||
		state->border_right = view->border_right;
 | 
			
		||||
		state->border_bottom = view->border_bottom;
 | 
			
		||||
		state->using_csd = view->using_csd;
 | 
			
		||||
	} else {
 | 
			
		||||
		state->children = create_list();
 | 
			
		||||
		list_cat(state->children, container->children);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -175,15 +175,6 @@ static bool wants_floating(struct sway_view *view) {
 | 
			
		|||
		|| toplevel->parent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool has_client_side_decorations(struct sway_view *view) {
 | 
			
		||||
	struct sway_xdg_shell_view *xdg_shell_view =
 | 
			
		||||
		xdg_shell_view_from_view(view);
 | 
			
		||||
	if (xdg_shell_view == NULL) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	return xdg_shell_view->deco_mode != WLR_SERVER_DECORATION_MANAGER_MODE_SERVER;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void for_each_surface(struct sway_view *view,
 | 
			
		||||
		wlr_surface_iterator_func_t iterator, void *user_data) {
 | 
			
		||||
	if (xdg_shell_view_from_view(view) == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -240,7 +231,6 @@ static const struct sway_view_impl view_impl = {
 | 
			
		|||
	.set_tiled = set_tiled,
 | 
			
		||||
	.set_fullscreen = set_fullscreen,
 | 
			
		||||
	.wants_floating = wants_floating,
 | 
			
		||||
	.has_client_side_decorations = has_client_side_decorations,
 | 
			
		||||
	.for_each_surface = for_each_surface,
 | 
			
		||||
	.for_each_popup = for_each_popup,
 | 
			
		||||
	.close = _close,
 | 
			
		||||
| 
						 | 
				
			
			@ -385,15 +375,13 @@ static void handle_map(struct wl_listener *listener, void *data) {
 | 
			
		|||
		view->natural_height = view->wlr_xdg_surface->surface->current.height;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view_map(view, view->wlr_xdg_surface->surface);
 | 
			
		||||
 | 
			
		||||
	struct sway_server_decoration *deco =
 | 
			
		||||
		decoration_from_surface(xdg_surface->surface);
 | 
			
		||||
	if (deco != NULL) {
 | 
			
		||||
		xdg_shell_view->deco_mode = deco->wlr_server_decoration->mode;
 | 
			
		||||
	} else {
 | 
			
		||||
		xdg_shell_view->deco_mode = WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view_map(view, view->wlr_xdg_surface->surface);
 | 
			
		||||
	bool csd = !deco || deco->wlr_server_decoration->mode ==
 | 
			
		||||
		WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
 | 
			
		||||
	view_set_csd_from_client(view, csd);
 | 
			
		||||
 | 
			
		||||
	if (xdg_surface->toplevel->client_pending.fullscreen) {
 | 
			
		||||
		container_set_fullscreen(view->container, true);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -171,15 +171,6 @@ static bool wants_floating(struct sway_view *view) {
 | 
			
		|||
		|| toplevel->parent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool has_client_side_decorations(struct sway_view *view) {
 | 
			
		||||
	struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
 | 
			
		||||
		xdg_shell_v6_view_from_view(view);
 | 
			
		||||
	if (xdg_shell_v6_view == NULL) {
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
	return xdg_shell_v6_view->deco_mode != WLR_SERVER_DECORATION_MANAGER_MODE_SERVER;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void for_each_surface(struct sway_view *view,
 | 
			
		||||
		wlr_surface_iterator_func_t iterator, void *user_data) {
 | 
			
		||||
	if (xdg_shell_v6_view_from_view(view) == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -237,7 +228,6 @@ static const struct sway_view_impl view_impl = {
 | 
			
		|||
	.set_tiled = set_tiled,
 | 
			
		||||
	.set_fullscreen = set_fullscreen,
 | 
			
		||||
	.wants_floating = wants_floating,
 | 
			
		||||
	.has_client_side_decorations = has_client_side_decorations,
 | 
			
		||||
	.for_each_surface = for_each_surface,
 | 
			
		||||
	.for_each_popup = for_each_popup,
 | 
			
		||||
	.close = _close,
 | 
			
		||||
| 
						 | 
				
			
			@ -382,15 +372,13 @@ static void handle_map(struct wl_listener *listener, void *data) {
 | 
			
		|||
		view->natural_height = view->wlr_xdg_surface_v6->surface->current.height;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view_map(view, view->wlr_xdg_surface_v6->surface);
 | 
			
		||||
 | 
			
		||||
	struct sway_server_decoration *deco =
 | 
			
		||||
		decoration_from_surface(xdg_surface->surface);
 | 
			
		||||
	if (deco != NULL) {
 | 
			
		||||
		xdg_shell_v6_view->deco_mode = deco->wlr_server_decoration->mode;
 | 
			
		||||
	} else {
 | 
			
		||||
		xdg_shell_v6_view->deco_mode = WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	view_map(view, view->wlr_xdg_surface_v6->surface);
 | 
			
		||||
	bool csd = !deco || deco->wlr_server_decoration->mode ==
 | 
			
		||||
			WLR_SERVER_DECORATION_MANAGER_MODE_CLIENT;
 | 
			
		||||
	view_set_csd_from_client(view, csd);
 | 
			
		||||
 | 
			
		||||
	if (xdg_surface->toplevel->client_pending.fullscreen) {
 | 
			
		||||
		container_set_fullscreen(view->container, true);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -243,12 +243,14 @@ static bool wants_floating(struct sway_view *view) {
 | 
			
		|||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static bool has_client_side_decorations(struct sway_view *view) {
 | 
			
		||||
	if (xwayland_view_from_view(view) == NULL) {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface;
 | 
			
		||||
	return surface->decorations != WLR_XWAYLAND_SURFACE_DECORATIONS_ALL;
 | 
			
		||||
static void handle_set_decorations(struct wl_listener *listener, void *data) {
 | 
			
		||||
	struct sway_xwayland_view *xwayland_view =
 | 
			
		||||
		wl_container_of(listener, xwayland_view, set_decorations);
 | 
			
		||||
	struct sway_view *view = &xwayland_view->view;
 | 
			
		||||
	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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void _close(struct sway_view *view) {
 | 
			
		||||
| 
						 | 
				
			
			@ -274,7 +276,6 @@ static const struct sway_view_impl view_impl = {
 | 
			
		|||
	.set_tiled = set_tiled,
 | 
			
		||||
	.set_fullscreen = set_fullscreen,
 | 
			
		||||
	.wants_floating = wants_floating,
 | 
			
		||||
	.has_client_side_decorations = has_client_side_decorations,
 | 
			
		||||
	.close = _close,
 | 
			
		||||
	.destroy = destroy,
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -343,6 +344,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
 | 
			
		|||
	wl_list_remove(&xwayland_view->set_role.link);
 | 
			
		||||
	wl_list_remove(&xwayland_view->set_window_type.link);
 | 
			
		||||
	wl_list_remove(&xwayland_view->set_hints.link);
 | 
			
		||||
	wl_list_remove(&xwayland_view->set_decorations.link);
 | 
			
		||||
	wl_list_remove(&xwayland_view->map.link);
 | 
			
		||||
	wl_list_remove(&xwayland_view->unmap.link);
 | 
			
		||||
	view_begin_destroy(&xwayland_view->view);
 | 
			
		||||
| 
						 | 
				
			
			@ -613,6 +615,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) {
 | 
			
		|||
	wl_signal_add(&xsurface->events.set_hints, &xwayland_view->set_hints);
 | 
			
		||||
	xwayland_view->set_hints.notify = handle_set_hints;
 | 
			
		||||
 | 
			
		||||
	wl_signal_add(&xsurface->events.set_decorations,
 | 
			
		||||
			&xwayland_view->set_decorations);
 | 
			
		||||
	xwayland_view->set_decorations.notify = handle_set_decorations;
 | 
			
		||||
 | 
			
		||||
	wl_signal_add(&xsurface->events.unmap, &xwayland_view->unmap);
 | 
			
		||||
	xwayland_view->unmap.notify = handle_unmap;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -175,7 +175,8 @@ static enum wlr_edges find_edge(struct sway_container *cont,
 | 
			
		|||
		return WLR_EDGE_NONE;
 | 
			
		||||
	}
 | 
			
		||||
	struct sway_view *view = cont->view;
 | 
			
		||||
	if (view->border == B_NONE || !view->border_thickness || view->using_csd) {
 | 
			
		||||
	if (view->border == B_NONE || !view->border_thickness ||
 | 
			
		||||
			view->border == B_CSD) {
 | 
			
		||||
		return WLR_EDGE_NONE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -216,6 +216,8 @@ static const char *describe_container_border(enum sway_container_border border)
 | 
			
		|||
		return "pixel";
 | 
			
		||||
	case B_NORMAL:
 | 
			
		||||
		return "normal";
 | 
			
		||||
	case B_CSD:
 | 
			
		||||
		return "csd";
 | 
			
		||||
	}
 | 
			
		||||
	return "unknown";
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@ sway_sources = files(
 | 
			
		|||
	'security.c',
 | 
			
		||||
	'server.c',
 | 
			
		||||
	'swaynag.c',
 | 
			
		||||
	'xdg_decoration.c',
 | 
			
		||||
 | 
			
		||||
	'desktop/desktop.c',
 | 
			
		||||
	'desktop/idle_inhibit_v1.c',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,7 @@
 | 
			
		|||
#include <wlr/types/wlr_screencopy_v1.h>
 | 
			
		||||
#include <wlr/types/wlr_server_decoration.h>
 | 
			
		||||
#include <wlr/types/wlr_xcursor_manager.h>
 | 
			
		||||
#include <wlr/types/wlr_xdg_decoration_v1.h>
 | 
			
		||||
#include <wlr/types/wlr_xdg_output_v1.h>
 | 
			
		||||
#include <wlr/util/log.h>
 | 
			
		||||
#include "list.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -115,6 +116,14 @@ bool server_init(struct sway_server *server) {
 | 
			
		|||
	server->server_decoration.notify = handle_server_decoration;
 | 
			
		||||
	wl_list_init(&server->decorations);
 | 
			
		||||
 | 
			
		||||
	server->xdg_decoration_manager =
 | 
			
		||||
		wlr_xdg_decoration_manager_v1_create(server->wl_display);
 | 
			
		||||
	wl_signal_add(
 | 
			
		||||
			&server->xdg_decoration_manager->events.new_toplevel_decoration,
 | 
			
		||||
			&server->xdg_decoration);
 | 
			
		||||
	server->xdg_decoration.notify = handle_xdg_decoration;
 | 
			
		||||
	wl_list_init(&server->xdg_decorations);
 | 
			
		||||
 | 
			
		||||
	wlr_export_dmabuf_manager_v1_create(server->wl_display);
 | 
			
		||||
	wlr_screencopy_manager_v1_create(server->wl_display);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -715,7 +715,7 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
 | 
			
		|||
	size_t border_width = 0;
 | 
			
		||||
	size_t top = 0;
 | 
			
		||||
 | 
			
		||||
	if (!view->using_csd) {
 | 
			
		||||
	if (view->border != B_CSD) {
 | 
			
		||||
		border_width = view->border_thickness * (view->border != B_NONE);
 | 
			
		||||
		top = view->border == B_NORMAL ?
 | 
			
		||||
			container_titlebar_height() : border_width;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,8 @@
 | 
			
		|||
#include <wlr/render/wlr_renderer.h>
 | 
			
		||||
#include <wlr/types/wlr_buffer.h>
 | 
			
		||||
#include <wlr/types/wlr_output_layout.h>
 | 
			
		||||
#include <wlr/types/wlr_server_decoration.h>
 | 
			
		||||
#include <wlr/types/wlr_xdg_decoration_v1.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#ifdef HAVE_XWAYLAND
 | 
			
		||||
#include <wlr/xwayland.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +25,7 @@
 | 
			
		|||
#include "sway/tree/view.h"
 | 
			
		||||
#include "sway/tree/workspace.h"
 | 
			
		||||
#include "sway/config.h"
 | 
			
		||||
#include "sway/xdg_decoration.h"
 | 
			
		||||
#include "pango.h"
 | 
			
		||||
#include "stringop.h"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -231,12 +234,8 @@ void view_autoconfigure(struct sway_view *view) {
 | 
			
		|||
		view->border_top = false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	enum sway_container_border border = view->border;
 | 
			
		||||
	if (view->using_csd) {
 | 
			
		||||
		border = B_NONE;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	switch (border) {
 | 
			
		||||
	switch (view->border) {
 | 
			
		||||
	case B_CSD:
 | 
			
		||||
	case B_NONE:
 | 
			
		||||
		x = con->x;
 | 
			
		||||
		y = con->y + y_offset;
 | 
			
		||||
| 
						 | 
				
			
			@ -309,16 +308,26 @@ void view_request_activate(struct sway_view *view) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void view_set_tiled(struct sway_view *view, bool tiled) {
 | 
			
		||||
	if (!tiled) {
 | 
			
		||||
		view->using_csd = true;
 | 
			
		||||
		if (view->impl->has_client_side_decorations) {
 | 
			
		||||
			view->using_csd = view->impl->has_client_side_decorations(view);
 | 
			
		||||
void view_set_csd_from_server(struct sway_view *view, bool enabled) {
 | 
			
		||||
	if (view->xdg_decoration) {
 | 
			
		||||
		uint32_t mode = enabled ?
 | 
			
		||||
			WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE :
 | 
			
		||||
			WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
 | 
			
		||||
		wlr_xdg_toplevel_decoration_v1_set_mode(
 | 
			
		||||
				view->xdg_decoration->wlr_xdg_decoration, mode);
 | 
			
		||||
	}
 | 
			
		||||
	} else {
 | 
			
		||||
		view->using_csd = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void view_set_csd_from_client(struct sway_view *view, bool enabled) {
 | 
			
		||||
	if (enabled && view->border != B_CSD) {
 | 
			
		||||
		view->saved_border = view->border;
 | 
			
		||||
		view->border = B_CSD;
 | 
			
		||||
	} else if (!enabled && view->border == B_CSD) {
 | 
			
		||||
		view->border = view->saved_border;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void view_set_tiled(struct sway_view *view, bool tiled) {
 | 
			
		||||
	if (view->impl->set_tiled) {
 | 
			
		||||
		view->impl->set_tiled(view, tiled);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										73
									
								
								sway/xdg_decoration.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								sway/xdg_decoration.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,73 @@
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include "sway/desktop/transaction.h"
 | 
			
		||||
#include "sway/server.h"
 | 
			
		||||
#include "sway/tree/arrange.h"
 | 
			
		||||
#include "sway/tree/view.h"
 | 
			
		||||
#include "sway/xdg_decoration.h"
 | 
			
		||||
#include "log.h"
 | 
			
		||||
 | 
			
		||||
static void xdg_decoration_handle_destroy(struct wl_listener *listener,
 | 
			
		||||
		void *data) {
 | 
			
		||||
	struct sway_xdg_decoration *deco =
 | 
			
		||||
		wl_container_of(listener, deco, destroy);
 | 
			
		||||
	deco->view->xdg_decoration = NULL;
 | 
			
		||||
	wl_list_remove(&deco->destroy.link);
 | 
			
		||||
	wl_list_remove(&deco->surface_commit.link);
 | 
			
		||||
	wl_list_remove(&deco->link);
 | 
			
		||||
	free(deco);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void xdg_decoration_handle_surface_commit(struct wl_listener *listener,
 | 
			
		||||
		void *data) {
 | 
			
		||||
	struct sway_xdg_decoration *decoration =
 | 
			
		||||
		wl_container_of(listener, decoration, surface_commit);
 | 
			
		||||
 | 
			
		||||
	bool csd = decoration->wlr_xdg_decoration->current_mode ==
 | 
			
		||||
		WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
 | 
			
		||||
	struct sway_view *view = decoration->view;
 | 
			
		||||
 | 
			
		||||
	view_set_csd_from_client(view, csd);
 | 
			
		||||
 | 
			
		||||
	arrange_container(view->container);
 | 
			
		||||
	transaction_commit_dirty();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void handle_xdg_decoration(struct wl_listener *listener, void *data) {
 | 
			
		||||
	struct wlr_xdg_toplevel_decoration_v1 *wlr_deco = data;
 | 
			
		||||
	struct sway_xdg_shell_view *xdg_shell_view = wlr_deco->surface->data;
 | 
			
		||||
	struct wlr_xdg_surface *wlr_xdg_surface =
 | 
			
		||||
		xdg_shell_view->view.wlr_xdg_surface;
 | 
			
		||||
 | 
			
		||||
	struct sway_xdg_decoration *deco = calloc(1, sizeof(*deco));
 | 
			
		||||
	if (deco == NULL) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	deco->view = &xdg_shell_view->view;
 | 
			
		||||
	deco->view->xdg_decoration = deco;
 | 
			
		||||
	deco->wlr_xdg_decoration = wlr_deco;
 | 
			
		||||
 | 
			
		||||
	wl_signal_add(&wlr_deco->events.destroy, &deco->destroy);
 | 
			
		||||
	deco->destroy.notify = xdg_decoration_handle_destroy;
 | 
			
		||||
 | 
			
		||||
	// Note: We don't listen to the request_mode signal here, effectively
 | 
			
		||||
	// ignoring any modes the client asks to set. The client can still force a
 | 
			
		||||
	// mode upon us, in which case we get upset but live with it.
 | 
			
		||||
 | 
			
		||||
	deco->surface_commit.notify = xdg_decoration_handle_surface_commit;
 | 
			
		||||
	wl_signal_add(&wlr_xdg_surface->surface->events.commit,
 | 
			
		||||
		&deco->surface_commit);
 | 
			
		||||
 | 
			
		||||
	wl_list_insert(&server.xdg_decorations, &deco->link);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct sway_xdg_decoration *xdg_decoration_from_surface(
 | 
			
		||||
		struct wlr_surface *surface) {
 | 
			
		||||
	struct sway_xdg_decoration *deco;
 | 
			
		||||
	wl_list_for_each(deco, &server.xdg_decorations, link) {
 | 
			
		||||
		if (deco->wlr_xdg_decoration->surface->surface == surface) {
 | 
			
		||||
			return deco;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue