common: flesh out enum lab_edge and prefer over wlr_edges/wlr_direction

I like the new common/edge.h. I don't like how inconsistently we use it.

Current situation:

 - enum wlr_edges and wlr_direction are designed to be used as bitset,
   and are defined compatibly

 - enum lab_edge is *also* designed to be used as bitset, but
   incompatible with the others (LEFT/RIGHT come before UP/DOWN)

 - we use an inconsistent mix of all three *AND* uint32_t (usually with
   the WLR_EDGE constants rather than the LAB_EDGE constants), and
   convert between them on an ad-hoc basis, sometimes implicitly

Let's clean this up:

 - reorder enum lab_edge to be compatible with the two wlr enums
   (check this by static_assert)

 - use TOP/BOTTOM naming rather than UP/DOWN (matches wlr_edges)

 - add constants for the remaining possible combinations of the 4 edges

 - use lab_edge for all internal edge/direction fields, consistently

 - add lab_edge_is_cardinal() as a sanity check before casting to
   enum wlr_direction, and then eliminate all of direction.c/h

Instead of "enum wlr_edges direction", we now have
"enum lab_edge direction" which is not that much better. At least we
are now clear that we're overloading one enum with two meanings.
This commit is contained in:
John Lindgren 2025-08-26 20:27:34 -04:00
parent 4d1be7eada
commit ef766d16f0
26 changed files with 294 additions and 320 deletions

View file

@ -93,13 +93,13 @@ snap_move_to_edge(struct view *view, enum lab_edge direction,
return;
}
break;
case LAB_EDGE_UP:
case LAB_EDGE_TOP:
target.y = usable.y + ssd.top + rc.gap;
if (target.y >= view->pending.y) {
return;
}
break;
case LAB_EDGE_DOWN:
case LAB_EDGE_BOTTOM:
target.y = usable.y + usable.height - rc.gap - ssd.bottom
- view_effective_height(view, /* use_pending */ true);
if (target.y <= view->pending.y) {
@ -149,29 +149,29 @@ snap_grow_to_next_edge(struct view *view,
struct border ssd = ssd_thickness(view);
struct wlr_box usable = output_usable_area_in_layout_coords(output);
uint32_t resize_edges;
enum lab_edge resize_edges;
/* First try to grow the view to the relevant edge of its output. */
switch (direction) {
case LAB_EDGE_LEFT:
geo->x = usable.x + ssd.left + rc.gap;
geo->width = view->pending.x + view->pending.width - geo->x;
resize_edges = WLR_EDGE_LEFT;
resize_edges = LAB_EDGE_LEFT;
break;
case LAB_EDGE_RIGHT:
geo->width = usable.x + usable.width
- rc.gap - ssd.right - view->pending.x;
resize_edges = WLR_EDGE_RIGHT;
resize_edges = LAB_EDGE_RIGHT;
break;
case LAB_EDGE_UP:
case LAB_EDGE_TOP:
geo->y = usable.y + ssd.top + rc.gap;
geo->height = view->pending.y + view->pending.height - geo->y;
resize_edges = WLR_EDGE_TOP;
resize_edges = LAB_EDGE_TOP;
break;
case LAB_EDGE_DOWN:
case LAB_EDGE_BOTTOM:
geo->height = usable.y + usable.height
- rc.gap - ssd.bottom - view->pending.y;
resize_edges = WLR_EDGE_BOTTOM;
resize_edges = LAB_EDGE_BOTTOM;
break;
default:
return;
@ -220,7 +220,7 @@ snap_shrink_to_next_edge(struct view *view,
assert(!view->shaded);
*geo = view->pending;
uint32_t resize_edges;
enum lab_edge resize_edges;
int min_width = view_get_min_width();
/*
@ -232,20 +232,20 @@ snap_shrink_to_next_edge(struct view *view,
case LAB_EDGE_RIGHT:
geo->width = MAX(geo->width / 2, min_width);
geo->x = view->pending.x + view->pending.width - geo->width;
resize_edges = WLR_EDGE_LEFT;
resize_edges = LAB_EDGE_LEFT;
break;
case LAB_EDGE_LEFT:
geo->width = MAX(geo->width / 2, min_width);
resize_edges = WLR_EDGE_RIGHT;
resize_edges = LAB_EDGE_RIGHT;
break;
case LAB_EDGE_DOWN:
case LAB_EDGE_BOTTOM:
geo->height = MAX(geo->height / 2, LAB_MIN_VIEW_HEIGHT);
geo->y = view->pending.y + view->pending.height - geo->height;
resize_edges = WLR_EDGE_TOP;
resize_edges = LAB_EDGE_TOP;
break;
case LAB_EDGE_UP:
case LAB_EDGE_TOP:
geo->height = MAX(geo->height / 2, LAB_MIN_VIEW_HEIGHT);
resize_edges = WLR_EDGE_BOTTOM;
resize_edges = LAB_EDGE_BOTTOM;
break;
default:
return;