diff --git a/include/wlr/util/box.h b/include/wlr/util/box.h index e866b1dfb..64dcbc5cf 100644 --- a/include/wlr/util/box.h +++ b/include/wlr/util/box.h @@ -71,6 +71,14 @@ bool wlr_box_intersection(struct wlr_box *dest, const struct wlr_box *box_a, */ bool wlr_box_contains_point(const struct wlr_box *box, double x, double y); +/** + * 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_box_contains_box(const struct wlr_box *bigger, const struct wlr_box *smaller); + /** * Checks whether a box is empty or not. * diff --git a/util/box.c b/util/box.c index a615e2f3e..6a6becf33 100644 --- a/util/box.c +++ b/util/box.c @@ -79,6 +79,17 @@ 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) { + if (wlr_box_empty(bigger) || wlr_box_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};