overlay: take into account <core><gap> for edge overlay

This also deduplicates get_edge_snap_box() in interactive.c and
view_get_edge_snap_box() in view.c.
This commit is contained in:
tokyo4j 2025-07-05 16:06:38 +09:00 committed by Johan Malm
parent ca8d98e80f
commit 38e57891b5
5 changed files with 23 additions and 35 deletions

View 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);

View 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

View 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);

View 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

View 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;
}