diff --git a/src/placement.c b/src/placement.c index 560b5e54..0f964706 100644 --- a/src/placement.c +++ b/src/placement.c @@ -418,18 +418,26 @@ placement_find_best(struct view *view, struct wlr_box *geometry) return false; } - /* Default placement is just the upper-left corner of the output */ + /* Default placement is upper-left corner, respecting gaps */ struct wlr_box usable = output_usable_area_in_layout_coords(output); - geometry->x = usable.x + margin.left; - geometry->y = usable.y + margin.top; + geometry->x = usable.x + margin.left + rc.gap; + geometry->y = usable.y + margin.top + rc.gap; /* Build the placement grid and overlap bitmap */ struct overlap_bitmap bmp = { 0 }; build_grid(&bmp, view); build_overlap(&bmp, view); - int height = geometry->height + margin.top + margin.bottom; - int width = geometry->width + margin.left + margin.right; + /* Dimensions include gap along all edges to ensure proper separation */ + int height = geometry->height + margin.top + margin.bottom + 2 * rc.gap; + int width = geometry->width + margin.left + margin.right + 2 * rc.gap; + + /* + * Overlap search identifies corners of the target region; view + * coordinates must by set in by the SSD margin and user gaps. + */ + int offset_x = margin.left + rc.gap; + int offset_y = margin.top + rc.gap; int min_overlap = INT_MAX; @@ -488,18 +496,20 @@ placement_find_best(struct view *view, struct wlr_box *geometry) if (rt) { /* Extend window right from left edge */ - geometry->x = bmp.cols[j] + margin.left; + geometry->x = bmp.cols[j] + offset_x; } else { /* Extend window left from right edge */ - geometry->x = bmp.cols[j + 1] - width + margin.left; + geometry->x = + bmp.cols[j + 1] - width + offset_x; } if (dn) { /* Extend window down from top edge */ - geometry->y = bmp.rows[i] + margin.top; + geometry->y = bmp.rows[i] + offset_y; } else { /* Extend window up from bottom edge */ - geometry->y = bmp.rows[i + 1] - height + margin.top; + geometry->y = + bmp.rows[i + 1] - height + offset_y; } /* If there is no overlap, the search is done. */