]> git.mdlowis.com Git - proto/labwc.git/commitdiff
placement: consider gaps when placing new windows
authorAndrew J. Hesford <ajh@sideband.org>
Tue, 23 Jan 2024 17:19:42 +0000 (12:19 -0500)
committerAndrew J. Hesford <ajh@sideband.org>
Tue, 30 Jan 2024 18:35:33 +0000 (13:35 -0500)
src/placement.c

index 560b5e5455dd08a0e7bd937ca26f9fe8b519643e..0f964706b34fc4d159872a5ad8f7c7e00309983e 100644 (file)
@@ -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. */