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

@ -205,28 +205,28 @@ ssd_get_part_type(const struct ssd *ssd, struct wlr_scene_node *node,
return resizing_type != LAB_SSD_NONE ? resizing_type : part_type;
}
uint32_t
enum lab_edge
ssd_resize_edges(enum ssd_part_type type)
{
switch (type) {
case LAB_SSD_PART_TOP:
return WLR_EDGE_TOP;
return LAB_EDGE_TOP;
case LAB_SSD_PART_RIGHT:
return WLR_EDGE_RIGHT;
return LAB_EDGE_RIGHT;
case LAB_SSD_PART_BOTTOM:
return WLR_EDGE_BOTTOM;
return LAB_EDGE_BOTTOM;
case LAB_SSD_PART_LEFT:
return WLR_EDGE_LEFT;
return LAB_EDGE_LEFT;
case LAB_SSD_PART_CORNER_TOP_LEFT:
return WLR_EDGE_TOP | WLR_EDGE_LEFT;
return LAB_EDGES_TOP_LEFT;
case LAB_SSD_PART_CORNER_TOP_RIGHT:
return WLR_EDGE_RIGHT | WLR_EDGE_TOP;
return LAB_EDGES_TOP_RIGHT;
case LAB_SSD_PART_CORNER_BOTTOM_RIGHT:
return WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
return LAB_EDGES_BOTTOM_RIGHT;
case LAB_SSD_PART_CORNER_BOTTOM_LEFT:
return WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
return LAB_EDGES_BOTTOM_LEFT;
default:
return WLR_EDGE_NONE;
return LAB_EDGE_NONE;
}
}