From 3562b9d30329b0c3efd81f81ec4801bcbd88729c Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 16 Jun 2021 20:52:40 +0200 Subject: [PATCH] Implement surface-suspension-v1 --- include/sway/server.h | 2 ++ sway/server.c | 4 ++++ sway/tree/workspace.c | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/sway/server.h b/include/sway/server.h index 3a5670d92..d5635a07e 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -90,6 +90,8 @@ struct sway_server { struct wlr_xdg_activation_v1 *xdg_activation_v1; struct wl_listener xdg_activation_v1_request_activate; + struct wlr_surface_suspension_manager_v1 *surface_suspension_manager_v1; + // The timeout for transactions, after which a transaction is applied // regardless of readiness. size_t txn_timeout_ms; diff --git a/sway/server.c b/sway/server.c index 2e5ab1045..2279b1f0a 100644 --- a/sway/server.c +++ b/sway/server.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,9 @@ bool server_init(struct sway_server *server) { wl_signal_add(&server->xdg_activation_v1->events.request_activate, &server->xdg_activation_v1_request_activate); + server->surface_suspension_manager_v1 = + wlr_surface_suspension_manager_v1_create(server->wl_display); + // Avoid using "wayland-0" as display socket char name_candidate[16]; for (int i = 1; i <= 32; ++i) { diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index c0da9c934..3bca3ccc8 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "stringop.h" #include "sway/input/input-manager.h" #include "sway/input/cursor.h" @@ -561,6 +562,23 @@ struct sway_workspace *workspace_output_prev( return workspace_output_prev_next_impl(current->output, -1, create); } +static void set_surface_suspended_iterator(struct wlr_surface *surface, + int x, int y, void *data) { + bool *suspended = data; + wlr_surface_suspension_manager_v1_set_suspended( + server.surface_suspension_manager_v1, surface, *suspended); +} + +static void set_container_suspended(struct sway_container *container, + void *data) { + if (!container->view || container_is_floating(container)) { + return; + } + + view_for_each_surface(container->view, + set_surface_suspended_iterator, data); +} + bool workspace_switch(struct sway_workspace *workspace, bool no_auto_back_and_forth) { struct sway_seat *seat = input_manager_current_seat(); @@ -589,6 +607,15 @@ bool workspace_switch(struct sway_workspace *workspace, } seat_set_focus(seat, next); arrange_workspace(workspace); + + if (active_ws) { + bool suspended = true; + workspace_for_each_container(active_ws, set_container_suspended, &suspended); + } + + bool suspended = false; + workspace_for_each_container(workspace, set_container_suspended, &suspended); + return true; }