]> git.mdlowis.com Git - proto/labwc.git/commitdiff
overlay: take into account <core><gap> for edge overlay
authortokyo4j <hrak1529@gmail.com>
Sat, 5 Jul 2025 07:06:38 +0000 (16:06 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 2 Aug 2025 11:31:16 +0000 (12:31 +0100)
This also deduplicates get_edge_snap_box() in interactive.c and
view_get_edge_snap_box() in view.c.

include/labwc.h
include/view.h
src/interactive.c
src/overlay.c
src/view.c

index feae372ef32b2f1e94aabca8efdfed8e8ef4bcd3..0cfdce19d2d951911a613b0a0583ae21f2fcf017 100644 (file)
@@ -429,7 +429,6 @@ void interactive_anchor_to_cursor(struct server *server, struct wlr_box *geo);
 void interactive_begin(struct view *view, enum input_mode mode, uint32_t edges);
 void interactive_finish(struct view *view);
 void interactive_cancel(struct view *view);
-/* Possibly returns VIEW_EDGE_CENTER if <topMaximize> is yes */
 enum view_edge edge_from_cursor(struct seat *seat, struct output **dest_output);
 
 void handle_tearing_new_object(struct wl_listener *listener, void *data);
index 5e1c5baf0e483bfa57c4a74786672ef37b7ea15d..04ed7d64ad7b973999a620af81ce32d6fcf6e969 100644 (file)
@@ -501,6 +501,10 @@ bool view_contains_window_type(struct view *view, enum window_type window_type);
  */
 enum view_edge view_edge_invert(enum view_edge edge);
 
+/* If view is NULL, the size of SSD is not considered */
+struct wlr_box view_get_edge_snap_box(struct view *view, struct output *output,
+       enum view_edge edge);
+
 /**
  * view_is_focusable() - Check whether or not a view can be focused
  * @view: view to be checked
index f6fd5450e26314bcf628a7794098e8d2a4501d7d..15b4323d61da0e6c855206b5a4033db6999e617e 100644 (file)
@@ -195,11 +195,7 @@ edge_from_cursor(struct seat *seat, struct output **dest_output)
        } else if (cursor_x >= area->x + area->width - snap_range) {
                return VIEW_EDGE_RIGHT;
        } else if (cursor_y <= area->y + snap_range) {
-               if (rc.snap_top_maximize) {
-                       return VIEW_EDGE_CENTER;
-               } else {
-                       return VIEW_EDGE_UP;
-               }
+               return VIEW_EDGE_UP;
        } else if (cursor_y >= area->y + area->height - snap_range) {
                return VIEW_EDGE_DOWN;
        } else {
@@ -223,7 +219,7 @@ snap_to_edge(struct view *view)
         * Don't store natural geometry here (it was
         * stored already in interactive_begin())
         */
-       if (edge == VIEW_EDGE_CENTER) {
+       if (edge == VIEW_EDGE_UP && rc.snap_top_maximize) {
                /* <topMaximize> */
                view_maximize(view, VIEW_AXIS_BOTH,
                        /*store_natural_geometry*/ false);
index 4b1c33cd6ed7cbd6531e37043b0b3fed2e520153..3424f160bb1f45c2022ee4f52b7b35320f879d80 100644 (file)
@@ -114,31 +114,13 @@ show_region_overlay(struct seat *seat, struct region *region)
        show_overlay(seat, &seat->overlay.region_rect, &region->geo);
 }
 
-/* TODO: share logic with view_get_edge_snap_box() */
 static struct wlr_box get_edge_snap_box(enum view_edge edge, struct output *output)
 {
-       struct wlr_box box = output_usable_area_in_layout_coords(output);
-       switch (edge) {
-       case VIEW_EDGE_RIGHT:
-               box.x += box.width / 2;
-               /* fallthrough */
-       case VIEW_EDGE_LEFT:
-               box.width /= 2;
-               break;
-       case VIEW_EDGE_DOWN:
-               box.y += box.height / 2;
-               /* fallthrough */
-       case VIEW_EDGE_UP:
-               box.height /= 2;
-               break;
-       case VIEW_EDGE_CENTER:
-               /* <topMaximize> */
-               break;
-       default:
-               /* not reached */
-               assert(false);
+       if (edge == VIEW_EDGE_UP && rc.snap_top_maximize) {
+               return output_usable_area_in_layout_coords(output);
+       } else {
+               return view_get_edge_snap_box(NULL, output, edge);
        }
-       return box;
 }
 
 static int
index d6ac89b9c87d2312dc6b7f00ca2470587e735a0d..2f6e62771da53b4e79082b8a9191a52ec85e7562 100644 (file)
@@ -440,7 +440,7 @@ view_edge_invert(enum view_edge edge)
        }
 }
 
-static struct wlr_box
+struct wlr_box
 view_get_edge_snap_box(struct view *view, struct output *output,
                enum view_edge edge)
 {
@@ -469,14 +469,21 @@ view_get_edge_snap_box(struct view *view, struct output *output,
                break;
        }
 
-       struct border margin = ssd_get_margin(view->ssd);
        struct wlr_box dst = {
-               .x = x_offset + usable.x + margin.left,
-               .y = y_offset + usable.y + margin.top,
-               .width = base_width - margin.left - margin.right,
-               .height = base_height - margin.top - margin.bottom,
+               .x = x_offset + usable.x,
+               .y = y_offset + usable.y,
+               .width = base_width,
+               .height = base_height,
        };
 
+       if (view) {
+               struct border margin = ssd_get_margin(view->ssd);
+               dst.x += margin.left;
+               dst.y += margin.top;
+               dst.width -= margin.left + margin.right;
+               dst.height -= margin.top + margin.bottom;
+       }
+
        return dst;
 }