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

@ -23,7 +23,6 @@
#include <wlr/types/wlr_scene.h>
#include <wlr/util/region.h>
#include <wlr/util/log.h>
#include "common/direction.h"
#include "common/macros.h"
#include "common/mem.h"
#include "common/scene-helpers.h"
@ -986,8 +985,8 @@ output_get_adjacent(struct output *output, enum lab_edge edge, bool wrap)
return NULL;
}
enum wlr_direction direction;
if (!direction_from_edge(edge, &direction)) {
/* Allow only up/down/left/right */
if (!lab_edge_is_cardinal(edge)) {
return NULL;
}
@ -999,16 +998,18 @@ output_get_adjacent(struct output *output, enum lab_edge edge, bool wrap)
struct wlr_output *new_output = NULL;
struct wlr_output *current_output = output->wlr_output;
struct wlr_output_layout *layout = output->server->output_layout;
new_output = wlr_output_layout_adjacent_output(layout, direction,
current_output, lx, ly);
/* Cast from enum lab_edge to enum wlr_direction is safe */
new_output = wlr_output_layout_adjacent_output(layout,
(enum wlr_direction)edge, current_output, lx, ly);
/*
* Optionally wrap around from top-to-bottom or left-to-right, and vice
* versa.
*/
if (wrap && !new_output) {
enum lab_edge opposite = lab_edge_invert(edge);
new_output = wlr_output_layout_farthest_output(layout,
direction_get_opposite(direction), current_output, lx, ly);
(enum wlr_direction)opposite, current_output, lx, ly);
}
/*