From 3f5d8e1d48353dce13953160b4f770b98b32052c Mon Sep 17 00:00:00 2001 From: Loukas Agorgianitis Date: Mon, 14 Apr 2025 11:42:06 +0200 Subject: [PATCH] util/box: introduce wlr_fbox_contains_box Signed-off-by: Loukas Agorgianitis --- include/wlr/util/box.h | 8 ++++++++ util/box.c | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wlr/util/box.h b/include/wlr/util/box.h index 816bece7e..287653904 100644 --- a/include/wlr/util/box.h +++ b/include/wlr/util/box.h @@ -87,6 +87,14 @@ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y); */ bool wlr_box_contains_box(const struct wlr_box *bigger, const struct wlr_box *smaller); +/** + * Verifies that a box is fully contained within another box. + * + * Returns true if the "smaller" box is fully contained within the "bigger" box. + * If either of the boxes are empty, false is returned. + */ +bool wlr_fbox_contains_box(const struct wlr_fbox *bigger, const struct wlr_fbox *smaller); + /** * Checks whether a box is empty or not. * diff --git a/util/box.c b/util/box.c index 087a33d19..2ceb6e2c3 100644 --- a/util/box.c +++ b/util/box.c @@ -122,6 +122,17 @@ bool wlr_box_contains_box(const struct wlr_box *bigger, const struct wlr_box *sm smaller->y + smaller->height <= bigger->y + bigger->height; } +bool wlr_fbox_contains_box(const struct wlr_fbox *bigger, const struct wlr_fbox *smaller) { + if (wlr_fbox_empty(bigger) || wlr_fbox_empty(smaller)) { + return false; + } + + return smaller->x >= bigger->x && + smaller->x + smaller->width <= bigger->x + bigger->width && + smaller->y >= bigger->y && + smaller->y + smaller->height <= bigger->y + bigger->height; +} + void wlr_box_transform(struct wlr_box *dest, const struct wlr_box *box, enum wl_output_transform transform, int width, int height) { struct wlr_box src = {0};