From e8876b26b918672ec1472149b16c51945bdbbe5f Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Sat, 5 Jul 2025 16:07:04 +0900 Subject: [PATCH] overlay: take into account for region overlay --- include/view.h | 1 + src/overlay.c | 3 +- src/view.c | 90 +++++++++++++++++++++++++++----------------------- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/include/view.h b/include/view.h index 04ed7d64..a7aa1af0 100644 --- a/include/view.h +++ b/include/view.h @@ -504,6 +504,7 @@ 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); +struct wlr_box view_get_region_snap_box(struct view *view, struct region *region); /** * view_is_focusable() - Check whether or not a view can be focused diff --git a/src/overlay.c b/src/overlay.c index 3424f160..2aecf007 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -111,7 +111,8 @@ show_region_overlay(struct seat *seat, struct region *region) inactivate_overlay(&seat->overlay); seat->overlay.active.region = region; - show_overlay(seat, &seat->overlay.region_rect, ®ion->geo); + struct wlr_box geo = view_get_region_snap_box(NULL, region); + show_overlay(seat, &seat->overlay.region_rect, &geo); } static struct wlr_box get_edge_snap_box(enum view_edge edge, struct output *output) diff --git a/src/view.c b/src/view.c index 2f6e6277..99a597cc 100644 --- a/src/view.c +++ b/src/view.c @@ -1195,6 +1195,54 @@ view_apply_natural_geometry(struct view *view) view_move_resize(view, geometry); } +struct wlr_box +view_get_region_snap_box(struct view *view, struct region *region) +{ + struct wlr_box geo = region->geo; + + /* Adjust for rc.gap */ + if (rc.gap) { + double half_gap = rc.gap / 2.0; + struct wlr_fbox offset = { + .x = half_gap, + .y = half_gap, + .width = -rc.gap, + .height = -rc.gap + }; + struct wlr_box usable = + output_usable_area_in_layout_coords(region->output); + if (geo.x == usable.x) { + offset.x += half_gap; + offset.width -= half_gap; + } + if (geo.y == usable.y) { + offset.y += half_gap; + offset.height -= half_gap; + } + if (geo.x + geo.width == usable.x + usable.width) { + offset.width -= half_gap; + } + if (geo.y + geo.height == usable.y + usable.height) { + offset.height -= half_gap; + } + geo.x += offset.x; + geo.y += offset.y; + geo.width += offset.width; + geo.height += offset.height; + } + + /* And adjust for current view */ + if (view) { + struct border margin = ssd_get_margin(view->ssd); + geo.x += margin.left; + geo.y += margin.top; + geo.width -= margin.left + margin.right; + geo.height -= margin.top + margin.bottom; + } + + return geo; +} + static void view_apply_region_geometry(struct view *view) { @@ -1220,47 +1268,7 @@ view_apply_region_geometry(struct view *view) } } - /* Create a copy of the original region geometry */ - struct wlr_box geo = view->tiled_region->geo; - - /* Adjust for rc.gap */ - if (rc.gap) { - double half_gap = rc.gap / 2.0; - struct wlr_fbox offset = { - .x = half_gap, - .y = half_gap, - .width = -rc.gap, - .height = -rc.gap - }; - struct wlr_box usable = - output_usable_area_in_layout_coords(output); - if (geo.x == usable.x) { - offset.x += half_gap; - offset.width -= half_gap; - } - if (geo.y == usable.y) { - offset.y += half_gap; - offset.height -= half_gap; - } - if (geo.x + geo.width == usable.x + usable.width) { - offset.width -= half_gap; - } - if (geo.y + geo.height == usable.y + usable.height) { - offset.height -= half_gap; - } - geo.x += offset.x; - geo.y += offset.y; - geo.width += offset.width; - geo.height += offset.height; - } - - /* And adjust for current view */ - struct border margin = ssd_get_margin(view->ssd); - geo.x += margin.left; - geo.y += margin.top; - geo.width -= margin.left + margin.right; - geo.height -= margin.top + margin.bottom; - + struct wlr_box geo = view_get_region_snap_box(view, view->tiled_region); view_move_resize(view, geo); }