From a0450d219fbc8a453876e70f29b9b5c2f76b0c64 Mon Sep 17 00:00:00 2001 From: Kirill Primak Date: Tue, 11 Jun 2024 16:16:31 +0300 Subject: [PATCH] layer-shell: introduce wlr_layer_surface_v1_get_exclusive_edge() --- include/wlr/types/wlr_layer_shell_v1.h | 8 +++++++ types/wlr_layer_shell_v1.c | 30 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/wlr/types/wlr_layer_shell_v1.h b/include/wlr/types/wlr_layer_shell_v1.h index c0043ee1c..9be246e16 100644 --- a/include/wlr/types/wlr_layer_shell_v1.h +++ b/include/wlr/types/wlr_layer_shell_v1.h @@ -13,6 +13,7 @@ #include #include #include +#include #include "wlr-layer-shell-unstable-v1-protocol.h" /** @@ -187,4 +188,11 @@ struct wlr_surface *wlr_layer_surface_v1_popup_surface_at( struct wlr_layer_surface_v1 *wlr_layer_surface_v1_from_resource( struct wl_resource *resource); +/** + * Get the edge the exclusive zone must be applied to. + * + * Returns WLR_EDGE_NONE if the exclusive zone is nonpositive or must not be applied. + */ +enum wlr_edges wlr_layer_surface_v1_get_exclusive_edge(struct wlr_layer_surface_v1 *surface); + #endif diff --git a/types/wlr_layer_shell_v1.c b/types/wlr_layer_shell_v1.c index 718c63b74..6df4b7a8e 100644 --- a/types/wlr_layer_shell_v1.c +++ b/types/wlr_layer_shell_v1.c @@ -654,3 +654,33 @@ struct wlr_surface *wlr_layer_surface_v1_popup_surface_at( return NULL; } + +enum wlr_edges wlr_layer_surface_v1_get_exclusive_edge(struct wlr_layer_surface_v1 *surface) { + if (surface->current.exclusive_zone <= 0) { + return WLR_EDGE_NONE; + } + uint32_t anchor = surface->current.anchor; + if (surface->current.exclusive_edge != 0) { + anchor = surface->current.exclusive_edge; + } + switch (anchor) { + case ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP: + case ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP: + return WLR_EDGE_TOP; + case ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM: + case ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT | + ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM: + return WLR_EDGE_BOTTOM; + case ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT: + case ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | + ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT: + return WLR_EDGE_LEFT; + case ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT: + case ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | + ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT: + return WLR_EDGE_RIGHT; + default: + return WLR_EDGE_NONE; + } +}