From 6a9e6dcae11df17bc565eab4e7739329e4444a8f Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Sat, 21 Feb 2026 14:56:40 -0500 Subject: [PATCH] view: factor out view_compute_cascaded_position() --- src/view.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/view.c b/src/view.c index ad89515d..0aee1b00 100644 --- a/src/view.c +++ b/src/view.c @@ -978,13 +978,16 @@ view_center(struct view *view, const struct wlr_box *ref) * Algorithm based on KWin's implementation: * https://github.com/KDE/kwin/blob/df9f8f8346b5b7645578e37365dabb1a7b02ca5a/src/placement.cpp#L589 */ -static void -view_cascade(struct view *view) +static bool +view_compute_cascaded_position(struct view *view, struct wlr_box *geom) { /* "cascade" policy places a new view at center by default */ - struct wlr_box center = view->pending; - view_compute_centered_position(view, NULL, - center.width, center.height, ¢er.x, ¢er.y); + struct wlr_box center = *geom; + if (!view_compute_centered_position(view, NULL, center.width, + center.height, ¢er.x, ¢er.y)) { + return false; + } + struct border margin = ssd_get_margin(view->ssd); center.x -= margin.left; center.y -= margin.top; @@ -1059,7 +1062,9 @@ view_cascade(struct view *view) } } - view_move(view, candidate.x + margin.left, candidate.y + margin.top); + geom->x = candidate.x + margin.left; + geom->y = candidate.y + margin.top; + return true; } void @@ -1086,8 +1091,11 @@ view_place_by_policy(struct view *view, bool allow_cursor, return; } } else if (policy == LAB_PLACE_CASCADE) { - view_cascade(view); - return; + struct wlr_box geometry = view->pending; + if (view_compute_cascaded_position(view, &geometry)) { + view_move(view, geometry.x, geometry.y); + return; + } } view_center(view, NULL);