From 6e7c4a181e094575fbe81ea3b544182345647346 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 | 72 ++++++++++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 33 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,33 +1195,10 @@ view_apply_natural_geometry(struct view *view) view_move_resize(view, geometry); } -static void -view_apply_region_geometry(struct view *view) +struct wlr_box +view_get_region_snap_box(struct view *view, struct region *region) { - assert(view); - assert(view->tiled_region || view->tiled_region_evacuate); - struct output *output = view->output; - assert(output_is_usable(output)); - - if (view->tiled_region_evacuate) { - /* View was evacuated from a destroying output */ - /* Get new output local region, may be NULL */ - view->tiled_region = regions_from_name( - view->tiled_region_evacuate, output); - - /* Get rid of the evacuate instruction */ - zfree(view->tiled_region_evacuate); - - if (!view->tiled_region) { - /* Existing region name doesn't exist in rc.xml anymore */ - view_set_untiled(view); - view_apply_natural_geometry(view); - return; - } - } - - /* Create a copy of the original region geometry */ - struct wlr_box geo = view->tiled_region->geo; + struct wlr_box geo = region->geo; /* Adjust for rc.gap */ if (rc.gap) { @@ -1233,7 +1210,7 @@ view_apply_region_geometry(struct view *view) .height = -rc.gap }; struct wlr_box usable = - output_usable_area_in_layout_coords(output); + output_usable_area_in_layout_coords(region->output); if (geo.x == usable.x) { offset.x += half_gap; offset.width -= half_gap; @@ -1255,12 +1232,43 @@ view_apply_region_geometry(struct view *view) } /* 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; + 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) +{ + assert(view); + assert(view->tiled_region || view->tiled_region_evacuate); + struct output *output = view->output; + assert(output_is_usable(output)); + + if (view->tiled_region_evacuate) { + /* View was evacuated from a destroying output */ + /* Get new output local region, may be NULL */ + view->tiled_region = regions_from_name( + view->tiled_region_evacuate, output); + + /* Get rid of the evacuate instruction */ + zfree(view->tiled_region_evacuate); + + if (!view->tiled_region) { + /* Existing region name doesn't exist in rc.xml anymore */ + view_set_untiled(view); + view_apply_natural_geometry(view); + return; + } + } + struct wlr_box geo = view_get_region_snap_box(view, view->tiled_region); view_move_resize(view, geo); } -- 2.52.0