mirror of
https://github.com/labwc/labwc.git
synced 2026-02-17 22:05:30 -05:00
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:
parent
4d1be7eada
commit
ef766d16f0
26 changed files with 294 additions and 320 deletions
|
|
@ -1,11 +0,0 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#ifndef LABWC_DIRECTION_H
|
||||
#define LABWC_DIRECTION_H
|
||||
|
||||
#include <wlr/types/wlr_output_layout.h>
|
||||
#include "common/edge.h"
|
||||
|
||||
bool direction_from_edge(enum lab_edge edge, enum wlr_direction *direction);
|
||||
enum wlr_direction direction_get_opposite(enum wlr_direction direction);
|
||||
|
||||
#endif /* LABWC_DIRECTION_H */
|
||||
|
|
@ -2,34 +2,77 @@
|
|||
#ifndef LABWC_EDGE_H
|
||||
#define LABWC_EDGE_H
|
||||
|
||||
#include <wayland-server-core.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Represents an edge or direction (e.g. window tiling, window motion)
|
||||
* Unified/overloaded enum representing edges, corners, and directions.
|
||||
* Used in many different contexts (moving, resizing, tiling) and with
|
||||
* somewhat different semantics depending on context.
|
||||
*
|
||||
* Examples:
|
||||
* - LAB_EDGE_TOP can also mean "up" or "north".
|
||||
* - LAB_EDGES_TOP_LEFT can mean "top left corner" or "northwest".
|
||||
*
|
||||
* The enum is designed to be used as a bitset, and combinations of
|
||||
* edges typically mean what you'd expect from the context. For example,
|
||||
* LAB_EDGES_TOP_LEFT is used when resizing a view from its top-left
|
||||
* corner, or when tiling a view in the top-left corner of an output.
|
||||
*
|
||||
* All 16 possible combinations of TOP/BOTTOM/LEFT/RIGHT are listed for
|
||||
* completeness. Not all combinations make sense in all contexts.
|
||||
*
|
||||
* LAB_EDGE_NONE is sometimes used to mean "invalid".
|
||||
*
|
||||
* LAB_EDGE_ANY means "any edge or combination of edges (except NONE)"
|
||||
* and is distinct from LAB_EDGE_ALL (which means all 4 edges).
|
||||
*
|
||||
* LAB_EDGE_TOP/BOTTOM/LEFT/RIGHT match the corresponding values of
|
||||
* enum wlr_edges and enum wlr_direction, so that conversion between
|
||||
* enums can be done with a simple cast.
|
||||
*/
|
||||
enum lab_edge {
|
||||
LAB_EDGE_INVALID = 0,
|
||||
LAB_EDGE_NONE = 0,
|
||||
|
||||
LAB_EDGE_LEFT = (1 << 0),
|
||||
LAB_EDGE_RIGHT = (1 << 1),
|
||||
LAB_EDGE_UP = (1 << 2),
|
||||
LAB_EDGE_DOWN = (1 << 3),
|
||||
LAB_EDGE_TOP = (1 << 0), /* or UP */
|
||||
LAB_EDGE_BOTTOM = (1 << 1), /* or DOWN */
|
||||
LAB_EDGE_LEFT = (1 << 2),
|
||||
LAB_EDGE_RIGHT = (1 << 3),
|
||||
LAB_EDGE_CENTER = (1 << 4), /* for window tiling */
|
||||
LAB_EDGE_ANY = (1 << 5), /* for window rules */
|
||||
|
||||
/* for window tiling */
|
||||
LAB_EDGE_UPLEFT = (LAB_EDGE_UP | LAB_EDGE_LEFT),
|
||||
LAB_EDGE_UPRIGHT = (LAB_EDGE_UP | LAB_EDGE_RIGHT),
|
||||
LAB_EDGE_DOWNLEFT = (LAB_EDGE_DOWN | LAB_EDGE_LEFT),
|
||||
LAB_EDGE_DOWNRIGHT = (LAB_EDGE_DOWN | LAB_EDGE_RIGHT),
|
||||
/* corners or ordinal directions (NW/NE/SW/SE) */
|
||||
LAB_EDGES_TOP_LEFT = (LAB_EDGE_TOP | LAB_EDGE_LEFT),
|
||||
LAB_EDGES_TOP_RIGHT = (LAB_EDGE_TOP | LAB_EDGE_RIGHT),
|
||||
LAB_EDGES_BOTTOM_LEFT = (LAB_EDGE_BOTTOM | LAB_EDGE_LEFT),
|
||||
LAB_EDGES_BOTTOM_RIGHT = (LAB_EDGE_BOTTOM | LAB_EDGE_RIGHT),
|
||||
|
||||
/* opposite edges */
|
||||
LAB_EDGES_TOP_BOTTOM = (LAB_EDGE_TOP | LAB_EDGE_BOTTOM),
|
||||
LAB_EDGES_LEFT_RIGHT = (LAB_EDGE_LEFT | LAB_EDGE_RIGHT),
|
||||
|
||||
/* all 4 edges */
|
||||
LAB_EDGES_ALL = (LAB_EDGE_TOP | LAB_EDGE_BOTTOM |
|
||||
LAB_EDGE_LEFT | LAB_EDGE_RIGHT),
|
||||
|
||||
/* 3-edge combinations (for completeness) */
|
||||
LAB_EDGES_EXCEPT_TOP = (LAB_EDGES_ALL ^ LAB_EDGE_TOP),
|
||||
LAB_EDGES_EXCEPT_BOTTOM = (LAB_EDGES_ALL ^ LAB_EDGE_BOTTOM),
|
||||
LAB_EDGES_EXCEPT_LEFT = (LAB_EDGES_ALL ^ LAB_EDGE_LEFT),
|
||||
LAB_EDGES_EXCEPT_RIGHT = (LAB_EDGES_ALL ^ LAB_EDGE_RIGHT),
|
||||
};
|
||||
|
||||
enum lab_edge lab_edge_parse(const char *direction, bool tiled, bool any);
|
||||
|
||||
/**
|
||||
* Returns true if edge is TOP, BOTTOM, LEFT, or RIGHT
|
||||
* (i.e. one of the four cardinal directions N/S/W/E)
|
||||
*/
|
||||
bool lab_edge_is_cardinal(enum lab_edge edge);
|
||||
|
||||
/**
|
||||
* lab_edge_invert() - select the opposite of a provided edge
|
||||
*
|
||||
* Returns LAB_EDGE_INVALID for edges other than UP/DOWN/LEFT/RIGHT.
|
||||
* Returns LAB_EDGE_NONE for edges other than TOP/BOTTOM/LEFT/RIGHT.
|
||||
*
|
||||
* @edge: edge to be inverted
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue