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

@ -177,7 +177,7 @@ view_matches_query(struct view *view, struct view_query *query)
if (!view->tiled) {
return false;
}
} else if (query->tiled != LAB_EDGE_INVALID) {
} else if (query->tiled != LAB_EDGE_NONE) {
if (query->tiled != view->tiled) {
return false;
}
@ -447,10 +447,10 @@ view_get_edge_snap_box(struct view *view, struct output *output,
if (edge & LAB_EDGE_LEFT) {
x2 = (usable.width - rc.gap) / 2;
}
if (edge & LAB_EDGE_DOWN) {
if (edge & LAB_EDGE_BOTTOM) {
y1 = (usable.height + rc.gap) / 2;
}
if (edge & LAB_EDGE_UP) {
if (edge & LAB_EDGE_TOP) {
y2 = (usable.height - rc.gap) / 2;
}
@ -1453,7 +1453,7 @@ void
view_set_untiled(struct view *view)
{
assert(view);
view->tiled = LAB_EDGE_INVALID;
view->tiled = LAB_EDGE_NONE;
view->tiled_region = NULL;
zfree(view->tiled_region_evacuate);
view_notify_tiled(view);
@ -2024,10 +2024,10 @@ view_move_to_edge(struct view *view, enum lab_edge direction, bool snap_to_windo
case LAB_EDGE_RIGHT:
destination_x = right - view->pending.width;
break;
case LAB_EDGE_UP:
case LAB_EDGE_TOP:
destination_y = top;
break;
case LAB_EDGE_DOWN:
case LAB_EDGE_BOTTOM:
destination_y = bottom
- view_effective_height(view, /* use_pending */ true);
break;