From 1cab17ada243385798b3340f88144f64ac33ee63 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 8 Feb 2023 15:25:14 +0100 Subject: [PATCH] Introduce surface_{enter,leave}_output() We can centralize all output-related surface events from there. --- include/sway/surface.h | 5 +++++ sway/desktop/layer_shell.c | 6 +++--- sway/desktop/surface.c | 11 +++++++++++ sway/lock.c | 3 ++- sway/tree/container.c | 13 +++++++------ sway/tree/view.c | 3 ++- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/include/sway/surface.h b/include/sway/surface.h index fb1cd775..50681897 100644 --- a/include/sway/surface.h +++ b/include/sway/surface.h @@ -15,4 +15,9 @@ struct sway_surface { struct wl_event_source *frame_done_timer; }; +void surface_enter_output(struct wlr_surface *surface, + struct sway_output *output); +void surface_leave_output(struct wlr_surface *surface, + struct sway_output *output); + #endif diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 6e3cc0e2..795eb4cd 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -13,6 +13,7 @@ #include "sway/layers.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/surface.h" #include "sway/tree/arrange.h" #include "sway/tree/workspace.h" @@ -382,8 +383,7 @@ static void handle_map(struct wl_listener *listener, void *data) { struct sway_output *output = wlr_output->data; output_damage_surface(output, sway_layer->geo.x, sway_layer->geo.y, sway_layer->layer_surface->surface, true); - wlr_surface_send_enter(sway_layer->layer_surface->surface, - sway_layer->layer_surface->output); + surface_enter_output(sway_layer->layer_surface->surface, output); cursor_rebase_all(); } @@ -510,7 +510,7 @@ static void popup_handle_map(struct wl_listener *listener, void *data) { struct sway_layer_surface *layer = popup_get_layer(popup); struct wlr_output *wlr_output = layer->layer_surface->output; sway_assert(wlr_output, "wlr_layer_surface_v1 has null output"); - wlr_surface_send_enter(popup->wlr_popup->base->surface, wlr_output); + surface_enter_output(popup->wlr_popup->base->surface, wlr_output->data); popup_damage(popup, true); } diff --git a/sway/desktop/surface.c b/sway/desktop/surface.c index 1d7b536d..a5a18917 100644 --- a/sway/desktop/surface.c +++ b/sway/desktop/surface.c @@ -4,6 +4,7 @@ #include #include "sway/server.h" #include "sway/surface.h" +#include "sway/output.h" static void handle_destroy(struct wl_listener *listener, void *data) { struct sway_surface *surface = wl_container_of(listener, surface, destroy); @@ -44,3 +45,13 @@ void handle_compositor_new_surface(struct wl_listener *listener, void *data) { wl_resource_post_no_memory(wlr_surface->resource); } } + +void surface_enter_output(struct wlr_surface *surface, + struct sway_output *output) { + wlr_surface_send_enter(surface, output->wlr_output); +} + +void surface_leave_output(struct wlr_surface *surface, + struct sway_output *output) { + wlr_surface_send_leave(surface, output->wlr_output); +} diff --git a/sway/lock.c b/sway/lock.c index 96af19c4..6d9e991b 100644 --- a/sway/lock.c +++ b/sway/lock.c @@ -5,6 +5,7 @@ #include "sway/input/seat.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/surface.h" struct sway_session_lock_surface { struct wlr_session_lock_surface_v1 *lock_surface; @@ -31,7 +32,7 @@ static void handle_surface_map(struct wl_listener *listener, void *data) { if (server.session_lock.focused == NULL) { set_lock_focused_surface(surf->surface); } - wlr_surface_send_enter(surf->surface, surf->output->wlr_output); + surface_enter_output(surf->surface, surf->output); output_damage_whole(surf->output); } diff --git a/sway/tree/container.c b/sway/tree/container.c index fa76dd6a..20701081 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -18,6 +18,7 @@ #include "sway/ipc-server.h" #include "sway/output.h" #include "sway/server.h" +#include "sway/surface.h" #include "sway/tree/arrange.h" #include "sway/tree/view.h" #include "sway/tree/workspace.h" @@ -1265,14 +1266,14 @@ bool container_is_fullscreen_or_child(struct sway_container *container) { static void surface_send_enter_iterator(struct wlr_surface *surface, int x, int y, void *data) { - struct wlr_output *wlr_output = data; - wlr_surface_send_enter(surface, wlr_output); + struct sway_output *output = data; + surface_enter_output(surface, output); } static void surface_send_leave_iterator(struct wlr_surface *surface, int x, int y, void *data) { - struct wlr_output *wlr_output = data; - wlr_surface_send_leave(surface, wlr_output); + struct sway_output *output = data; + surface_leave_output(surface, output); } void container_discover_outputs(struct sway_container *con) { @@ -1298,7 +1299,7 @@ void container_discover_outputs(struct sway_container *con) { sway_log(SWAY_DEBUG, "Container %p entered output %p", con, output); if (con->view) { view_for_each_surface(con->view, - surface_send_enter_iterator, output->wlr_output); + surface_send_enter_iterator, output); if (con->view->foreign_toplevel) { wlr_foreign_toplevel_handle_v1_output_enter( con->view->foreign_toplevel, output->wlr_output); @@ -1310,7 +1311,7 @@ void container_discover_outputs(struct sway_container *con) { sway_log(SWAY_DEBUG, "Container %p left output %p", con, output); if (con->view) { view_for_each_surface(con->view, - surface_send_leave_iterator, output->wlr_output); + surface_send_leave_iterator, output); if (con->view->foreign_toplevel) { wlr_foreign_toplevel_handle_v1_output_leave( con->view->foreign_toplevel, output->wlr_output); diff --git a/sway/tree/view.c b/sway/tree/view.c index ba3ef489..fcb78de3 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -25,6 +25,7 @@ #include "sway/output.h" #include "sway/input/seat.h" #include "sway/server.h" +#include "sway/surface.h" #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/view.h" @@ -1148,7 +1149,7 @@ void view_child_init(struct sway_view_child *child, if (container != NULL) { struct sway_workspace *workspace = container->pending.workspace; if (workspace) { - wlr_surface_send_enter(child->surface, workspace->output->wlr_output); + surface_enter_output(child->surface, workspace->output); } }