]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common: flesh out enum lab_edge and prefer over wlr_edges/wlr_direction
authorJohn Lindgren <john@jlindgren.net>
Wed, 27 Aug 2025 00:27:34 +0000 (20:27 -0400)
committerJohn Lindgren <john@jlindgren.net>
Wed, 27 Aug 2025 00:36:43 +0000 (20:36 -0400)
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.

26 files changed:
include/common/direction.h [deleted file]
include/common/edge.h
include/edges.h
include/input/cursor.h
include/labwc.h
include/snap-constraints.h
include/ssd.h
include/view.h
src/action.c
src/common/direction.c [deleted file]
src/common/edge.c
src/common/meson.build
src/edges.c
src/input/cursor.c
src/interactive.c
src/output.c
src/overlay.c
src/resistance.c
src/snap-constraints.c
src/snap.c
src/ssd/ssd.c
src/theme.c
src/view-impl-common.c
src/view.c
src/xdg.c
src/xwayland.c

diff --git a/include/common/direction.h b/include/common/direction.h
deleted file mode 100644 (file)
index a1e6530..0000000
+++ /dev/null
@@ -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 */
index 23b5fdde3bffa3933823e62588114d653f4f8e89..07d517f500e2158e3213d3cb3456a3f7411e14ad 100644 (file)
@@ -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
  */
index 38aeb897ef5bbb9c81233ec91a81fb171e069573..439b5a34a660e19fa66a1d2ea0926b857c1c92d4 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <limits.h>
 #include <stdbool.h>
-#include <stdint.h>
+#include "common/edge.h"
 #include "common/macros.h"
 
 struct border;
@@ -113,9 +113,10 @@ void edges_adjust_move_coords(struct view *view, struct border edges,
        int *x, int *y, bool use_pending);
 
 void edges_adjust_resize_geom(struct view *view, struct border edges,
-       uint32_t resize_edges, struct wlr_box *geom, bool use_pending);
+       enum lab_edge resize_edges, struct wlr_box *geom, bool use_pending);
 
 bool edges_traverse_edge(struct edge current, struct edge target, struct edge edge);
 
 void edges_calculate_visibility(struct server *server, struct view *ignored_view);
+
 #endif /* LABWC_EDGES_H */
index c49606e2356395e5e804d7d578c24b986afb5130..094bc04f76f66f66efdb812cf908b770bc8ab2c4 100644 (file)
@@ -3,7 +3,7 @@
 #define LABWC_CURSOR_H
 
 #include <wlr/types/wlr_cursor.h>
-#include <wlr/util/edges.h>
+#include "common/edge.h"
 #include "ssd.h"
 
 struct view;
@@ -11,7 +11,6 @@ struct seat;
 struct server;
 struct wlr_surface;
 struct wlr_scene_node;
-enum wl_pointer_button_state;
 
 /* Cursors used internally by labwc */
 enum lab_cursors {
@@ -85,20 +84,19 @@ void cursor_set_visible(struct seat *seat, bool visible);
  * This is mostly important when either resizing a window using a
  * keyboard modifier or when using the Resize action from a keybind.
  */
-uint32_t cursor_get_resize_edges(struct wlr_cursor *cursor,
+enum lab_edge cursor_get_resize_edges(struct wlr_cursor *cursor,
        struct cursor_context *ctx);
 
 /**
- * cursor_get_from_edge - translate wlroots edge enum to lab_cursor enum
- * @resize_edges - WLR_EDGE_ combination like WLR_EDGE_TOP | WLR_EDGE_RIGHT
+ * cursor_get_from_edge - translate lab_edge enum to lab_cursor enum
+ * @resize_edges - edge(s) being resized
  *
- * Returns LAB_CURSOR_DEFAULT on WLR_EDGE_NONE
  * Returns the appropriate lab_cursors enum if @resize_edges
  * is one of the 4 corners or one of the 4 edges.
  *
- * Asserts on invalid edge combinations like WLR_EDGE_LEFT | WLR_EDGE_RIGHT
+ * Returns LAB_CURSOR_DEFAULT on any other value.
  */
-enum lab_cursors cursor_get_from_edge(uint32_t resize_edges);
+enum lab_cursors cursor_get_from_edge(enum lab_edge resize_edges);
 
 /**
  * cursor_update_focus - update cursor focus, may update the cursor icon
index a4971e45c00e564091f51de1a4c4a9b45038ad12..0629a8b8cf3f1ce43e051b865e17a9d3acfa51e2 100644 (file)
@@ -209,7 +209,7 @@ struct server {
        double grab_x, grab_y;
        /* View geometry when interactive move/resize is requested */
        struct wlr_box grab_box;
-       uint32_t resize_edges;
+       enum lab_edge resize_edges;
 
        /*
         * 'active_view' is generally the view with keyboard-focus, updated with
@@ -426,7 +426,8 @@ void seat_focus_override_end(struct seat *seat);
  */
 void interactive_anchor_to_cursor(struct server *server, struct wlr_box *geo);
 
-void interactive_begin(struct view *view, enum input_mode mode, uint32_t edges);
+void interactive_begin(struct view *view, enum input_mode mode,
+       enum lab_edge edges);
 void interactive_finish(struct view *view);
 void interactive_cancel(struct view *view);
 
@@ -434,7 +435,7 @@ void interactive_cancel(struct view *view);
  * Returns the edge to snap a window to.
  * For example, if the output-relative cursor position (x,y) fulfills
  * x <= (<snapping><cornerRange>) and y <= (<snapping><range>),
- * then edge1=LAB_EDGE_UP and edge2=LAB_EDGE_LEFT.
+ * then edge1=LAB_EDGE_TOP and edge2=LAB_EDGE_LEFT.
  * The value of (edge1|edge2) can be passed to view_snap_to_edge().
  */
 bool edge_from_cursor(struct seat *seat, struct output **dest_output,
index 8ad32a1b5c6fe9e9d05a4258e7bb84ec0f5ac838..c7ed7f8a1bae49bf48f8bfbed50b75801378dcd3 100644 (file)
@@ -2,21 +2,19 @@
 #ifndef LABWC_SNAP_CONSTRAINTS_H
 #define LABWC_SNAP_CONSTRAINTS_H
 
-#include <wlr/util/edges.h>
-
-#include "common/border.h"
-#include "view.h"
+#include "common/edge.h"
 
+struct view;
 struct wlr_box;
 
-void snap_constraints_set(struct view *view,
-       enum wlr_edges direction, struct wlr_box geom);
+void snap_constraints_set(struct view *view, enum lab_edge direction,
+       struct wlr_box geom);
 
 void snap_constraints_invalidate(struct view *view);
 
 void snap_constraints_update(struct view *view);
 
 struct wlr_box snap_constraints_effective(struct view *view,
-       enum wlr_edges direction, bool use_pending);
+       enum lab_edge direction, bool use_pending);
 
 #endif /* LABWC_SNAP_CONSTRAINTS_H */
index 5b7de1d547153d7c96bd9f87ac4308ac18097072..cf0d3e24d677bc6908e05d14cd05f5134657cb1b 100644 (file)
@@ -2,8 +2,9 @@
 #ifndef LABWC_SSD_H
 #define LABWC_SSD_H
 
-#include <wayland-server-core.h>
 #include "common/border.h"
+#include "common/edge.h"
+#include "config/types.h"
 
 struct wlr_cursor;
 
@@ -101,7 +102,7 @@ struct view *ssd_button_get_view(const struct ssd_button *button);
 /* Public SSD helpers */
 enum ssd_part_type ssd_get_part_type(const struct ssd *ssd,
        struct wlr_scene_node *node, struct wlr_cursor *cursor);
-uint32_t ssd_resize_edges(enum ssd_part_type type);
+enum lab_edge ssd_resize_edges(enum ssd_part_type type);
 bool ssd_part_contains(enum ssd_part_type whole, enum ssd_part_type candidate);
 enum lab_ssd_mode ssd_mode_parse(const char *mode);
 
index e7dce886ec79ed5b4739f51fefead63d72ec52f9..2767f9808f67a9a450ad7864efd6ae0270b8d02c 100644 (file)
@@ -180,7 +180,7 @@ struct view {
        enum lab_tristate force_tearing;
        bool visible_on_all_workspaces;
        enum lab_edge tiled;
-       uint32_t edges_visible;  /* enum wlr_edges bitset */
+       enum lab_edge edges_visible;
        bool inhibits_keybinds; /* also inhibits mousebinds */
        xkb_layout_index_t keyboard_layout;
 
index 6f75537e376769952f2a6bd35f17c2c459ce63e8..eda9138cee3909e6c963de4024286a8c90ecdb56 100644 (file)
@@ -348,7 +348,7 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                        bool tiled = (action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE
                                        || action->type == ACTION_TYPE_SNAP_TO_EDGE);
                        enum lab_edge edge = lab_edge_parse(content, tiled, /*any*/ false);
-                       if (edge == LAB_EDGE_INVALID) {
+                       if (edge == LAB_EDGE_NONE) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
                                        action_names[action->type], argument, content);
                        } else {
@@ -462,7 +462,7 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                if (!strcmp(argument, "direction")) {
                        enum lab_edge edge = lab_edge_parse(content,
                                /*tiled*/ false, /*any*/ false);
-                       if (edge == LAB_EDGE_INVALID) {
+                       if (edge == LAB_EDGE_NONE) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
                                        action_names[action->type], argument, content);
                        } else {
@@ -921,7 +921,7 @@ get_target_output(struct output *output, struct server *server,
                target = output_from_name(server, output_name);
        } else {
                enum lab_edge edge =
-                       action_get_int(action, "direction", LAB_EDGE_INVALID);
+                       action_get_int(action, "direction", LAB_EDGE_NONE);
                bool wrap = action_get_bool(action, "wrap", false);
                target = output_get_adjacent(output, edge, wrap);
        }
@@ -1144,7 +1144,8 @@ run_action(struct view *view, struct server *server, struct action *action,
                break;
        case ACTION_TYPE_MOVE:
                if (view) {
-                       interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
+                       interactive_begin(view, LAB_INPUT_STATE_MOVE,
+                               LAB_EDGE_NONE);
                }
                break;
        case ACTION_TYPE_RAISE:
@@ -1159,7 +1160,7 @@ run_action(struct view *view, struct server *server, struct action *action,
                break;
        case ACTION_TYPE_RESIZE:
                if (view) {
-                       uint32_t resize_edges = cursor_get_resize_edges(
+                       enum lab_edge resize_edges = cursor_get_resize_edges(
                                server->seat.cursor, ctx);
                        interactive_begin(view, LAB_INPUT_STATE_RESIZE,
                                resize_edges);
diff --git a/src/common/direction.c b/src/common/direction.c
deleted file mode 100644 (file)
index df1c929..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-#include "common/direction.h"
-#include <assert.h>
-#include <wlr/types/wlr_output_layout.h>
-#include "view.h"
-
-bool
-direction_from_edge(enum lab_edge edge, enum wlr_direction *direction)
-{
-       switch (edge) {
-       case LAB_EDGE_LEFT:
-               *direction = WLR_DIRECTION_LEFT;
-               return true;
-       case LAB_EDGE_RIGHT:
-               *direction = WLR_DIRECTION_RIGHT;
-               return true;
-       case LAB_EDGE_UP:
-               *direction = WLR_DIRECTION_UP;
-               return true;
-       case LAB_EDGE_DOWN:
-               *direction = WLR_DIRECTION_DOWN;
-               return true;
-       default:
-               return false;
-       }
-}
-
-enum wlr_direction
-direction_get_opposite(enum wlr_direction direction)
-{
-       switch (direction) {
-       case WLR_DIRECTION_RIGHT:
-               return WLR_DIRECTION_LEFT;
-       case WLR_DIRECTION_LEFT:
-               return WLR_DIRECTION_RIGHT;
-       case WLR_DIRECTION_DOWN:
-               return WLR_DIRECTION_UP;
-       case WLR_DIRECTION_UP:
-               return WLR_DIRECTION_DOWN;
-       default:
-               assert(0); /* Unreachable */
-               return WLR_DIRECTION_UP;
-       }
-}
index 20b8eb9c264ffeb8df13b53bcf8306ef8f184319..c241396bd09c88fa00e40e77c3fdde65f6654ecf 100644 (file)
@@ -1,21 +1,36 @@
 // SPDX-License-Identifier: GPL-2.0-only
 #include "common/edge.h"
+#include <assert.h>
 #include <strings.h>
+#include <wlr/util/edges.h>
+#include <wlr/types/wlr_output_layout.h>
+
+static_assert((int)LAB_EDGE_TOP == (int)WLR_EDGE_TOP
+               && (int)LAB_EDGE_BOTTOM == (int)WLR_EDGE_BOTTOM
+               && (int)LAB_EDGE_LEFT == (int)WLR_EDGE_LEFT
+               && (int)LAB_EDGE_RIGHT == (int)WLR_EDGE_RIGHT,
+       "enum lab_edge does not match enum wlr_edges");
+
+static_assert((int)LAB_EDGE_TOP == (int)WLR_DIRECTION_UP
+               && (int)LAB_EDGE_BOTTOM == (int)WLR_DIRECTION_DOWN
+               && (int)LAB_EDGE_LEFT == (int)WLR_DIRECTION_LEFT
+               && (int)LAB_EDGE_RIGHT == (int)WLR_DIRECTION_RIGHT,
+       "enum lab_edge does not match enum wlr_direction");
 
 enum lab_edge
 lab_edge_parse(const char *direction, bool tiled, bool any)
 {
        if (!direction) {
-               return LAB_EDGE_INVALID;
+               return LAB_EDGE_NONE;
        }
        if (!strcasecmp(direction, "left")) {
                return LAB_EDGE_LEFT;
        } else if (!strcasecmp(direction, "up")) {
-               return LAB_EDGE_UP;
+               return LAB_EDGE_TOP;
        } else if (!strcasecmp(direction, "right")) {
                return LAB_EDGE_RIGHT;
        } else if (!strcasecmp(direction, "down")) {
-               return LAB_EDGE_DOWN;
+               return LAB_EDGE_BOTTOM;
        }
 
        if (any) {
@@ -28,17 +43,31 @@ lab_edge_parse(const char *direction, bool tiled, bool any)
                if (!strcasecmp(direction, "center")) {
                        return LAB_EDGE_CENTER;
                } else if (!strcasecmp(direction, "up-left")) {
-                       return LAB_EDGE_UPLEFT;
+                       return LAB_EDGES_TOP_LEFT;
                } else if (!strcasecmp(direction, "up-right")) {
-                       return LAB_EDGE_UPRIGHT;
+                       return LAB_EDGES_TOP_RIGHT;
                } else if (!strcasecmp(direction, "down-left")) {
-                       return LAB_EDGE_DOWNLEFT;
+                       return LAB_EDGES_BOTTOM_LEFT;
                } else if (!strcasecmp(direction, "down-right")) {
-                       return LAB_EDGE_DOWNRIGHT;
+                       return LAB_EDGES_BOTTOM_RIGHT;
                }
        }
 
-       return LAB_EDGE_INVALID;
+       return LAB_EDGE_NONE;
+}
+
+bool
+lab_edge_is_cardinal(enum lab_edge edge)
+{
+       switch (edge) {
+       case LAB_EDGE_TOP:
+       case LAB_EDGE_BOTTOM:
+       case LAB_EDGE_LEFT:
+       case LAB_EDGE_RIGHT:
+               return true;
+       default:
+               return false;
+       }
 }
 
 enum lab_edge
@@ -49,11 +78,11 @@ lab_edge_invert(enum lab_edge edge)
                return LAB_EDGE_RIGHT;
        case LAB_EDGE_RIGHT:
                return LAB_EDGE_LEFT;
-       case LAB_EDGE_UP:
-               return LAB_EDGE_DOWN;
-       case LAB_EDGE_DOWN:
-               return LAB_EDGE_UP;
+       case LAB_EDGE_TOP:
+               return LAB_EDGE_BOTTOM;
+       case LAB_EDGE_BOTTOM:
+               return LAB_EDGE_TOP;
        default:
-               return LAB_EDGE_INVALID;
+               return LAB_EDGE_NONE;
        }
 }
index e0b903360dfa4ee0ac1b9fb98cb4016b811d8001..306a2ba77a8503afc042e0f8cb15981e833e3c54 100644 (file)
@@ -1,5 +1,4 @@
 labwc_sources += files(
-  'direction.c',
   'box.c',
   'buf.c',
   'dir.c',
index 94c541b593ea373fd7639e102d487b090a064ab5..2e3224331d5cd672ef74d1b0166c3372100b11f2 100644 (file)
@@ -40,32 +40,32 @@ edges_initialize(struct border *edges)
 }
 
 static inline struct edge
-build_edge(struct border region, enum wlr_edges direction, int pad)
+build_edge(struct border region, enum lab_edge direction, int pad)
 {
        struct edge edge = { 0 };
 
        switch (direction) {
-       case WLR_EDGE_LEFT:
+       case LAB_EDGE_LEFT:
                edge.offset = clipped_sub(region.left, pad);
                edge.min = region.top;
                edge.max = region.bottom;
                break;
-       case WLR_EDGE_RIGHT:
+       case LAB_EDGE_RIGHT:
                edge.offset = clipped_add(region.right, pad);
                edge.min = region.top;
                edge.max = region.bottom;
                break;
-       case WLR_EDGE_TOP:
+       case LAB_EDGE_TOP:
                edge.offset = clipped_sub(region.top, pad);
                edge.min = region.left;
                edge.max = region.right;
                break;
-       case WLR_EDGE_BOTTOM:
+       case LAB_EDGE_BOTTOM:
                edge.offset = clipped_add(region.bottom, pad);
                edge.min = region.left;
                edge.max = region.right;
                break;
-       case WLR_EDGE_NONE:
+       default:
                /* Should never be reached */
                wlr_log(WLR_ERROR, "invalid direction");
                abort();
@@ -75,14 +75,14 @@ build_edge(struct border region, enum wlr_edges direction, int pad)
 }
 
 static inline bool
-is_lesser(enum wlr_edges direction)
+is_lesser(enum lab_edge direction)
 {
-       return direction == WLR_EDGE_LEFT || direction == WLR_EDGE_TOP;
+       return direction == LAB_EDGE_LEFT || direction == LAB_EDGE_TOP;
 }
 
 static inline struct edge
-build_visible_edge(struct border region, enum wlr_edges direction,
-               int pad, uint32_t edges_visible)
+build_visible_edge(struct border region, enum lab_edge direction,
+               int pad, enum lab_edge edges_visible)
 {
        struct edge edge = build_edge(region, direction, pad);
 
@@ -97,7 +97,7 @@ static void
 validate_single_region_edge(int *valid_edge,
                struct border view, struct border target,
                struct border region, edge_validator_t validator,
-               enum wlr_edges direction, uint32_t edges_visible)
+               enum lab_edge direction, enum lab_edge edges_visible)
 {
        /*
         * When a view snaps to another while moving to its target, it can do
@@ -115,26 +115,8 @@ validate_single_region_edge(int *valid_edge,
         * the region borders for aligned edges only.
         */
 
-       enum wlr_edges opposing = WLR_EDGE_NONE;
-
-       switch (direction) {
-       case WLR_EDGE_TOP:
-               opposing = WLR_EDGE_BOTTOM;
-               break;
-       case WLR_EDGE_BOTTOM:
-               opposing = WLR_EDGE_TOP;
-               break;
-       case WLR_EDGE_LEFT:
-               opposing = WLR_EDGE_RIGHT;
-               break;
-       case WLR_EDGE_RIGHT:
-               opposing = WLR_EDGE_LEFT;
-               break;
-       case WLR_EDGE_NONE:
-               /* Should never be reached */
-               assert(false);
-               return;
-       }
+       enum lab_edge opposing = lab_edge_invert(direction);
+       assert(opposing != LAB_EDGE_NONE);
 
        validator(valid_edge,
                build_edge(view, direction, 0),
@@ -147,31 +129,31 @@ validate_single_region_edge(int *valid_edge,
 static void
 validate_edges(struct border *valid_edges,
                struct border view, struct border target,
-               struct border region, uint32_t edges_visible,
+               struct border region, enum lab_edge edges_visible,
                edge_validator_t validator)
 {
        /* Check for edges encountered during movement of left edge */
        validate_single_region_edge(&valid_edges->left,
-               view, target, region, validator, WLR_EDGE_LEFT, edges_visible);
+               view, target, region, validator, LAB_EDGE_LEFT, edges_visible);
 
        /* Check for edges encountered during movement of right edge */
        validate_single_region_edge(&valid_edges->right,
-               view, target, region, validator, WLR_EDGE_RIGHT, edges_visible);
+               view, target, region, validator, LAB_EDGE_RIGHT, edges_visible);
 
        /* Check for edges encountered during movement of top edge */
        validate_single_region_edge(&valid_edges->top,
-               view, target, region, validator, WLR_EDGE_TOP, edges_visible);
+               view, target, region, validator, LAB_EDGE_TOP, edges_visible);
 
        /* Check for edges encountered during movement of bottom edge */
        validate_single_region_edge(&valid_edges->bottom,
-               view, target, region, validator, WLR_EDGE_BOTTOM, edges_visible);
+               view, target, region, validator, LAB_EDGE_BOTTOM, edges_visible);
 }
 
 static void
 validate_single_output_edge(int *valid_edge,
                struct border view, struct border target,
                struct border region, edge_validator_t validator,
-               enum wlr_edges direction)
+               enum lab_edge direction)
 {
        static struct border unbounded = {
                .top = INT_MIN,
@@ -226,24 +208,24 @@ validate_output_edges(struct border *valid_edges,
        /* Left edge encounters a half-infinite region to the left of the output */
 
        validate_single_output_edge(&valid_edges->left,
-                       view, target, output, validator, WLR_EDGE_LEFT);
+               view, target, output, validator, LAB_EDGE_LEFT);
 
        /* Right edge encounters a half-infinite region to the right of the output */
 
        validate_single_output_edge(&valid_edges->right,
-                       view, target, output, validator, WLR_EDGE_RIGHT);
+               view, target, output, validator, LAB_EDGE_RIGHT);
 
        /* Top edge encounters a half-infinite region above the output */
 
        validate_single_output_edge(&valid_edges->top,
-                       view, target, output, validator, WLR_EDGE_TOP);
+               view, target, output, validator, LAB_EDGE_TOP);
 
        /* Bottom edge encounters a half-infinite region below the output */
        validate_single_output_edge(&valid_edges->bottom,
-                       view, target, output, validator, WLR_EDGE_BOTTOM);
+               view, target, output, validator, LAB_EDGE_BOTTOM);
 }
 
-static uint32_t
+static enum lab_edge
 compute_edges_visible(const struct wlr_box *view_size,
                const pixman_box32_t *view_rect,
                const pixman_region32_t *available)
@@ -258,19 +240,19 @@ compute_edges_visible(const struct wlr_box *view_size,
        const pixman_box32_t *rects =
                pixman_region32_rectangles(&intersection, &nrects);
 
-       uint32_t edges_visible = 0;
+       enum lab_edge edges_visible = LAB_EDGE_NONE;
        for (int i = 0; i < nrects; i++) {
                if (rects[i].x1 == view_rect->x1) {
-                       edges_visible |= WLR_EDGE_LEFT;
+                       edges_visible |= LAB_EDGE_LEFT;
                }
                if (rects[i].y1 == view_rect->y1) {
-                       edges_visible |= WLR_EDGE_TOP;
+                       edges_visible |= LAB_EDGE_TOP;
                }
                if (rects[i].x2 == view_rect->x2) {
-                       edges_visible |= WLR_EDGE_RIGHT;
+                       edges_visible |= LAB_EDGE_RIGHT;
                }
                if (rects[i].y2 == view_rect->y2) {
-                       edges_visible |= WLR_EDGE_BOTTOM;
+                       edges_visible |= LAB_EDGE_BOTTOM;
                }
        }
        pixman_region32_fini(&intersection);
@@ -294,11 +276,10 @@ subtract_view_from_space(struct view *view, pixman_region32_t *available)
 
        switch (overlap) {
        case PIXMAN_REGION_IN:
-               view->edges_visible = WLR_EDGE_TOP | WLR_EDGE_RIGHT
-                       | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
+               view->edges_visible = LAB_EDGES_ALL;
                break;
        case PIXMAN_REGION_OUT:
-               view->edges_visible = 0;
+               view->edges_visible = LAB_EDGE_NONE;
                return;
        case PIXMAN_REGION_PART:
                view->edges_visible = compute_edges_visible(
@@ -411,11 +392,10 @@ edges_find_neighbors(struct border *nearest_edges, struct view *view,
                        continue;
                }
 
-               uint32_t edges_visible = ignore_hidden ? v->edges_visible :
-                       WLR_EDGE_TOP | WLR_EDGE_LEFT
-                               | WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
+               enum lab_edge edges_visible =
+                       ignore_hidden ? v->edges_visible : LAB_EDGES_ALL;
 
-               if (edges_visible == 0) {
+               if (edges_visible == LAB_EDGE_NONE) {
                        continue;
                }
 
@@ -543,7 +523,8 @@ edges_adjust_move_coords(struct view *view, struct border edges,
 
 void
 edges_adjust_resize_geom(struct view *view, struct border edges,
-               uint32_t resize_edges, struct wlr_box *geom, bool use_pending)
+               enum lab_edge resize_edges, struct wlr_box *geom,
+               bool use_pending)
 {
        assert(view);
 
@@ -556,24 +537,24 @@ edges_adjust_resize_geom(struct view *view, struct border edges,
         * any valid nearest edge in the corresponding direction.
         */
 
-       if (resize_edges & WLR_EDGE_LEFT) {
+       if (resize_edges & LAB_EDGE_LEFT) {
                if (BOUNDED_INT(edges.left)) {
                        geom->x = edges.left + border.left + rc.gap;
                        geom->width = view_geom->width + view_geom->x - geom->x;
                }
-       } else if (resize_edges & WLR_EDGE_RIGHT) {
+       } else if (resize_edges & LAB_EDGE_RIGHT) {
                if (BOUNDED_INT(edges.right)) {
                        geom->width = edges.right
                                - view_geom->x - border.right - rc.gap;
                }
        }
 
-       if (resize_edges & WLR_EDGE_TOP) {
+       if (resize_edges & LAB_EDGE_TOP) {
                if (BOUNDED_INT(edges.top)) {
                        geom->y = edges.top + border.top + rc.gap;
                        geom->height = view_geom->height + view_geom->y - geom->y;
                }
-       } else if (resize_edges & WLR_EDGE_BOTTOM) {
+       } else if (resize_edges & LAB_EDGE_BOTTOM) {
                if (BOUNDED_INT(edges.bottom)) {
                        geom->height = edges.bottom
                                - view_geom->y - border.bottom - rc.gap;
index 22d0e384cabc057fddfea3650ed43a639b049370..cd7b5f34cba378419d5e81892fe4afc01b18b119 100644 (file)
@@ -88,40 +88,34 @@ static_assert(
        "X11 cursor names are out of sync");
 
 enum lab_cursors
-cursor_get_from_edge(uint32_t resize_edges)
+cursor_get_from_edge(enum lab_edge resize_edges)
 {
        switch (resize_edges) {
-       case WLR_EDGE_NONE:
-               return LAB_CURSOR_DEFAULT;
-       case WLR_EDGE_TOP | WLR_EDGE_LEFT:
+       case LAB_EDGES_TOP_LEFT:
                return LAB_CURSOR_RESIZE_NW;
-       case WLR_EDGE_TOP:
+       case LAB_EDGE_TOP:
                return LAB_CURSOR_RESIZE_N;
-       case WLR_EDGE_TOP | WLR_EDGE_RIGHT:
+       case LAB_EDGES_TOP_RIGHT:
                return LAB_CURSOR_RESIZE_NE;
-       case WLR_EDGE_RIGHT:
+       case LAB_EDGE_RIGHT:
                return LAB_CURSOR_RESIZE_E;
-       case WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT:
+       case LAB_EDGES_BOTTOM_RIGHT:
                return LAB_CURSOR_RESIZE_SE;
-       case WLR_EDGE_BOTTOM:
+       case LAB_EDGE_BOTTOM:
                return LAB_CURSOR_RESIZE_S;
-       case WLR_EDGE_BOTTOM | WLR_EDGE_LEFT:
+       case LAB_EDGES_BOTTOM_LEFT:
                return LAB_CURSOR_RESIZE_SW;
-       case WLR_EDGE_LEFT:
+       case LAB_EDGE_LEFT:
                return LAB_CURSOR_RESIZE_W;
        default:
-               wlr_log(WLR_ERROR,
-                       "Failed to resolve wlroots edge %u to cursor name", resize_edges);
-               assert(false);
+               return LAB_CURSOR_DEFAULT;
        }
-
-       return LAB_CURSOR_DEFAULT;
 }
 
 static enum lab_cursors
 cursor_get_from_ssd(enum ssd_part_type view_area)
 {
-       uint32_t resize_edges = ssd_resize_edges(view_area);
+       enum lab_edge resize_edges = ssd_resize_edges(view_area);
        return cursor_get_from_edge(resize_edges);
 }
 
@@ -342,32 +336,32 @@ process_cursor_resize(struct server *server, uint32_t time)
        struct view *view = server->grabbed_view;
        struct wlr_box new_view_geo = view->current;
 
-       if (server->resize_edges & WLR_EDGE_TOP) {
+       if (server->resize_edges & LAB_EDGE_TOP) {
                /* Shift y to anchor bottom edge when resizing top */
                new_view_geo.y = server->grab_box.y + dy;
                new_view_geo.height = server->grab_box.height - dy;
-       } else if (server->resize_edges & WLR_EDGE_BOTTOM) {
+       } else if (server->resize_edges & LAB_EDGE_BOTTOM) {
                new_view_geo.height = server->grab_box.height + dy;
        }
 
-       if (server->resize_edges & WLR_EDGE_LEFT) {
+       if (server->resize_edges & LAB_EDGE_LEFT) {
                /* Shift x to anchor right edge when resizing left */
                new_view_geo.x = server->grab_box.x + dx;
                new_view_geo.width = server->grab_box.width - dx;
-       } else if (server->resize_edges & WLR_EDGE_RIGHT) {
+       } else if (server->resize_edges & LAB_EDGE_RIGHT) {
                new_view_geo.width = server->grab_box.width + dx;
        }
 
        resistance_resize_apply(view, &new_view_geo);
        view_adjust_size(view, &new_view_geo.width, &new_view_geo.height);
 
-       if (server->resize_edges & WLR_EDGE_TOP) {
+       if (server->resize_edges & LAB_EDGE_TOP) {
                /* After size adjustments, make sure to anchor bottom edge */
                new_view_geo.y = server->grab_box.y +
                        server->grab_box.height - new_view_geo.height;
        }
 
-       if (server->resize_edges & WLR_EDGE_LEFT) {
+       if (server->resize_edges & LAB_EDGE_LEFT) {
                /* After size adjustments, make sure to anchor bottom right */
                new_view_geo.x = server->grab_box.x +
                        server->grab_box.width - new_view_geo.width;
@@ -582,18 +576,18 @@ cursor_update_common(struct server *server, struct cursor_context *ctx,
        return false;
 }
 
-uint32_t
+enum lab_edge
 cursor_get_resize_edges(struct wlr_cursor *cursor, struct cursor_context *ctx)
 {
-       uint32_t resize_edges = ssd_resize_edges(ctx->type);
+       enum lab_edge resize_edges = ssd_resize_edges(ctx->type);
        if (ctx->view && !resize_edges) {
                struct wlr_box box = ctx->view->current;
                resize_edges |=
                        (int)cursor->x < box.x + box.width / 2 ?
-                               WLR_EDGE_LEFT : WLR_EDGE_RIGHT;
+                               LAB_EDGE_LEFT : LAB_EDGE_RIGHT;
                resize_edges |=
                        (int)cursor->y < box.y + box.height / 2 ?
-                               WLR_EDGE_TOP : WLR_EDGE_BOTTOM;
+                               LAB_EDGE_TOP : LAB_EDGE_BOTTOM;
        }
        return resize_edges;
 }
index 8a8903da356b829d4ae95c7138f87ff7bd6e21d3..517b898e6a669a172faf66fdf895c7085f77eb38 100644 (file)
@@ -55,7 +55,7 @@ interactive_anchor_to_cursor(struct server *server, struct wlr_box *geo)
 }
 
 void
-interactive_begin(struct view *view, enum input_mode mode, uint32_t edges)
+interactive_begin(struct view *view, enum input_mode mode, enum lab_edge edges)
 {
        /*
         * This function sets up an interactive move or resize operation, where
@@ -170,8 +170,8 @@ edge_from_cursor(struct seat *seat, struct output **dest_output,
                enum lab_edge *edge1, enum lab_edge *edge2)
 {
        *dest_output = NULL;
-       *edge1 = LAB_EDGE_INVALID;
-       *edge2 = LAB_EDGE_INVALID;
+       *edge1 = LAB_EDGE_NONE;
+       *edge2 = LAB_EDGE_NONE;
 
        if (!view_is_floating(seat->server->grabbed_view)) {
                return false;
@@ -202,9 +202,9 @@ edge_from_cursor(struct seat *seat, struct output **dest_output,
        int right = area->x + area->width - cursor_x;
 
        if (top < rc.snap_edge_range) {
-               *edge1 = LAB_EDGE_UP;
+               *edge1 = LAB_EDGE_TOP;
        } else if (bottom < rc.snap_edge_range) {
-               *edge1 = LAB_EDGE_DOWN;
+               *edge1 = LAB_EDGE_BOTTOM;
        } else if (left < rc.snap_edge_range) {
                *edge1 = LAB_EDGE_LEFT;
        } else if (right < rc.snap_edge_range) {
@@ -213,7 +213,7 @@ edge_from_cursor(struct seat *seat, struct output **dest_output,
                return false;
        }
 
-       if (*edge1 == LAB_EDGE_UP || *edge1 == LAB_EDGE_DOWN) {
+       if (*edge1 == LAB_EDGE_TOP || *edge1 == LAB_EDGE_BOTTOM) {
                if (left < rc.snap_edge_corner_range) {
                        *edge2 = LAB_EDGE_LEFT;
                } else if (right < rc.snap_edge_corner_range) {
@@ -221,9 +221,9 @@ edge_from_cursor(struct seat *seat, struct output **dest_output,
                }
        } else if (*edge1  == LAB_EDGE_LEFT || *edge1 == LAB_EDGE_RIGHT) {
                if (top < rc.snap_edge_corner_range) {
-                       *edge2 = LAB_EDGE_UP;
+                       *edge2 = LAB_EDGE_TOP;
                } else if (bottom < rc.snap_edge_corner_range) {
-                       *edge2 = LAB_EDGE_DOWN;
+                       *edge2 = LAB_EDGE_BOTTOM;
                }
        }
 
@@ -246,7 +246,7 @@ snap_to_edge(struct view *view)
         * Don't store natural geometry here (it was
         * stored already in interactive_begin())
         */
-       if (edge == LAB_EDGE_UP && rc.snap_top_maximize) {
+       if (edge == LAB_EDGE_TOP && rc.snap_top_maximize) {
                /* <topMaximize> */
                view_maximize(view, VIEW_AXIS_BOTH,
                        /*store_natural_geometry*/ false);
index 6633df2df4e99fe5107b82ff05909899241c228e..f683c2dec6a40c1191f665136d5647549a31f51b 100644 (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);
        }
 
        /*
index c0c47d0e702fb65dcabc493da1999bdf5fd2801c..0c2235d356d5c30dcc24cccd7b58a9fa213469bc 100644 (file)
@@ -2,7 +2,6 @@
 #include "overlay.h"
 #include <assert.h>
 #include <wlr/types/wlr_scene.h>
-#include "common/direction.h"
 #include "common/lab-scene-rect.h"
 #include "config/rcxml.h"
 #include "labwc.h"
@@ -97,7 +96,7 @@ inactivate_overlay(struct overlay *overlay)
                        &overlay->edge_rect.tree->node, false);
        }
        overlay->active.region = NULL;
-       overlay->active.edge = LAB_EDGE_INVALID;
+       overlay->active.edge = LAB_EDGE_NONE;
        overlay->active.output = NULL;
        if (overlay->timer) {
                wl_event_source_timer_update(overlay->timer, 0);
@@ -120,7 +119,7 @@ show_region_overlay(struct seat *seat, struct region *region)
 static struct wlr_box
 get_edge_snap_box(enum lab_edge edge, struct output *output)
 {
-       if (edge == LAB_EDGE_UP && rc.snap_top_maximize) {
+       if (edge == LAB_EDGE_TOP && rc.snap_top_maximize) {
                return output_usable_area_in_layout_coords(output);
        } else {
                return view_get_edge_snap_box(NULL, output, edge);
@@ -131,7 +130,7 @@ static int
 handle_edge_overlay_timeout(void *data)
 {
        struct seat *seat = data;
-       assert(seat->overlay.active.edge != LAB_EDGE_INVALID
+       assert(seat->overlay.active.edge != LAB_EDGE_NONE
                && seat->overlay.active.output);
        struct wlr_box box = get_edge_snap_box(seat->overlay.active.edge,
                seat->overlay.active.output);
@@ -143,12 +142,13 @@ static bool
 edge_has_adjacent_output_from_cursor(struct seat *seat, struct output *output,
                enum lab_edge edge)
 {
-       enum wlr_direction dir;
-       if (!direction_from_edge(edge, &dir)) {
+       /* Allow only up/down/left/right */
+       if (!lab_edge_is_cardinal(edge)) {
                return false;
        }
+       /* Cast from enum lab_edge to enum wlr_direction is safe */
        return wlr_output_layout_adjacent_output(
-               seat->server->output_layout, dir,
+               seat->server->output_layout, (enum wlr_direction)edge,
                output->wlr_output, seat->cursor->x, seat->cursor->y);
 }
 
@@ -159,7 +159,7 @@ show_edge_overlay(struct seat *seat, enum lab_edge edge1, enum lab_edge edge2,
        if (!rc.snap_overlay_enabled) {
                return;
        }
-       uint32_t edge = edge1 | edge2;
+       enum lab_edge edge = edge1 | edge2;
        if (seat->overlay.active.edge == edge
                        && seat->overlay.active.output == output) {
                return;
index 2f09c0e9e8ce298231c25b8b8468c9c7db5a75e1..4566c5d0f7f352adc3334b8a847f248af3875e6d 100644 (file)
@@ -167,7 +167,7 @@ resistance_resize_apply(struct view *view, struct wlr_box *new_geom)
        edges_initialize(&next_edges);
 
        /* Use a constrained, effective geometry for snapping if appropriate */
-       enum wlr_edges resize_edges = view->server->resize_edges;
+       enum lab_edge resize_edges = view->server->resize_edges;
        struct wlr_box origin =
                snap_constraints_effective(view, resize_edges, /* use_pending */ false);
 
index 04eed5f7b82c51d3c3a964907bcb4b48389ed56c..d579a38758adccea110cf64779a1b2e37cad2597 100644 (file)
@@ -39,7 +39,7 @@ static struct {
        bool pending;
        int vertical_offset;
        int horizontal_offset;
-       enum wlr_edges resize_edges;
+       enum lab_edge resize_edges;
        struct wlr_box geom;
 } last_snap_hit;
 
@@ -50,12 +50,12 @@ snap_constraints_reset(void)
        last_snap_hit.pending = false;
        last_snap_hit.horizontal_offset = INT_MIN;
        last_snap_hit.vertical_offset = INT_MIN;
-       last_snap_hit.resize_edges = WLR_EDGE_NONE;
+       last_snap_hit.resize_edges = LAB_EDGE_NONE;
        memset(&last_snap_hit.geom, 0, sizeof(last_snap_hit.geom));
 }
 
 static bool
-snap_constraints_are_valid(struct view *view, enum wlr_edges resize_edges)
+snap_constraints_are_valid(struct view *view, enum lab_edge resize_edges)
 {
        assert(view);
 
@@ -70,20 +70,20 @@ snap_constraints_are_valid(struct view *view, enum wlr_edges resize_edges)
        }
 
        /* Cache is not valid if edge offsets are invalid */
-       if (resize_edges & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) {
+       if (resize_edges & LAB_EDGES_LEFT_RIGHT) {
                if (!BOUNDED_INT(last_snap_hit.horizontal_offset)) {
                        return false;
                }
 
-               if ((resize_edges & WLR_EDGE_LEFT) && (resize_edges & WLR_EDGE_RIGHT)) {
+               if ((resize_edges & LAB_EDGE_LEFT) && (resize_edges & LAB_EDGE_RIGHT)) {
                        return false;
                }
-       } else if (resize_edges & (WLR_EDGE_TOP | WLR_EDGE_BOTTOM)) {
+       } else if (resize_edges & LAB_EDGES_TOP_BOTTOM) {
                if (!BOUNDED_INT(last_snap_hit.vertical_offset)) {
                        return false;
                }
 
-               if ((resize_edges & WLR_EDGE_TOP) && (resize_edges & WLR_EDGE_BOTTOM)) {
+               if ((resize_edges & LAB_EDGE_TOP) && (resize_edges & LAB_EDGE_BOTTOM)) {
                        return false;
                }
        } else {
@@ -95,24 +95,24 @@ snap_constraints_are_valid(struct view *view, enum wlr_edges resize_edges)
 }
 
 void
-snap_constraints_set(struct view *view,
-               enum wlr_edges resize_edges, struct wlr_box geom)
+snap_constraints_set(struct view *view, enum lab_edge resize_edges,
+               struct wlr_box geom)
 {
        assert(view);
 
        /* Set horizontal offset when resizing horizontal edges */
        last_snap_hit.horizontal_offset = INT_MIN;
-       if (resize_edges & WLR_EDGE_LEFT) {
+       if (resize_edges & LAB_EDGE_LEFT) {
                last_snap_hit.horizontal_offset = geom.x;
-       } else if (resize_edges & WLR_EDGE_RIGHT) {
+       } else if (resize_edges & LAB_EDGE_RIGHT) {
                last_snap_hit.horizontal_offset = geom.x + geom.width;
        }
 
        /* Set vertical offset when resizing vertical edges */
        last_snap_hit.vertical_offset = INT_MIN;
-       if (resize_edges & WLR_EDGE_TOP) {
+       if (resize_edges & LAB_EDGE_TOP) {
                last_snap_hit.vertical_offset = geom.y;
-       } else if (resize_edges & WLR_EDGE_BOTTOM) {
+       } else if (resize_edges & LAB_EDGE_BOTTOM) {
                last_snap_hit.vertical_offset = geom.y + geom.height;
        }
 
@@ -166,8 +166,8 @@ snap_constraints_update(struct view *view)
 }
 
 struct wlr_box
-snap_constraints_effective(struct view *view,
-               enum wlr_edges resize_edges, bool use_pending)
+snap_constraints_effective(struct view *view, enum lab_edge resize_edges,
+               bool use_pending)
 {
        assert(view);
 
@@ -181,15 +181,15 @@ snap_constraints_effective(struct view *view,
        /* Override changing edge with constrained value */
        struct wlr_box geom = real_geom;
 
-       if (resize_edges & WLR_EDGE_LEFT) {
+       if (resize_edges & LAB_EDGE_LEFT) {
                geom.x = last_snap_hit.horizontal_offset;
-       } else if (resize_edges & WLR_EDGE_RIGHT) {
+       } else if (resize_edges & LAB_EDGE_RIGHT) {
                geom.width = last_snap_hit.horizontal_offset - geom.x;
        }
 
-       if (resize_edges & WLR_EDGE_TOP) {
+       if (resize_edges & LAB_EDGE_TOP) {
                geom.y = last_snap_hit.vertical_offset;
-       } else if (resize_edges & WLR_EDGE_BOTTOM) {
+       } else if (resize_edges & LAB_EDGE_BOTTOM) {
                geom.height = last_snap_hit.vertical_offset - geom.y;
        }
 
index ea9d5d46b6df11dd0bd846f63e981a7a46175082..fcb8f335dd98bc3c5c6877dce0acb0c37f42a1bd 100644 (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;
index 3d0dd7a07b0a37c6c3122107b6ac69436e04cedf..7a45f37ef45adbb2907458c0194b073a785eebc7 100644 (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;
        }
 }
 
index 2d5ac12b9e883bdfe40078ec609abb35777725a4..e16325e8da6d02db929eeb177c0abef3a1704c8d 100644 (file)
@@ -43,10 +43,9 @@ struct button {
        uint8_t state_set;
 };
 
-enum corner {
-       LAB_CORNER_UNKNOWN = 0,
-       LAB_CORNER_TOP_LEFT,
-       LAB_CORNER_TOP_RIGHT,
+enum rounded_corner {
+       ROUNDED_CORNER_TOP_LEFT,
+       ROUNDED_CORNER_TOP_RIGHT
 };
 
 struct rounded_corner_ctx {
@@ -55,7 +54,7 @@ struct rounded_corner_ctx {
        double line_width;
        cairo_pattern_t *fill_pattern;
        float *border_color;
-       enum corner corner;
+       enum rounded_corner corner;
 };
 
 #define zero_array(arr) memset(arr, 0, sizeof(arr))
@@ -1110,10 +1109,6 @@ theme_read(struct theme *theme, struct wl_list *paths)
 static struct lab_data_buffer *
 rounded_rect(struct rounded_corner_ctx *ctx)
 {
-       if (ctx->corner == LAB_CORNER_UNKNOWN) {
-               return NULL;
-       }
-
        double w = ctx->box->width;
        double h = ctx->box->height;
        double r = ctx->radius;
@@ -1147,20 +1142,18 @@ rounded_rect(struct rounded_corner_ctx *ctx)
        cairo_set_line_width(cairo, 0.0);
        cairo_new_sub_path(cairo);
        switch (ctx->corner) {
-       case LAB_CORNER_TOP_LEFT:
+       case ROUNDED_CORNER_TOP_LEFT:
                cairo_arc(cairo, r, r, r, 180 * deg, 270 * deg);
                cairo_line_to(cairo, w, 0);
                cairo_line_to(cairo, w, h);
                cairo_line_to(cairo, 0, h);
                break;
-       case LAB_CORNER_TOP_RIGHT:
+       case ROUNDED_CORNER_TOP_RIGHT:
                cairo_arc(cairo, w - r, r, r, -90 * deg, 0 * deg);
                cairo_line_to(cairo, w, h);
                cairo_line_to(cairo, 0, h);
                cairo_line_to(cairo, 0, 0);
                break;
-       default:
-               wlr_log(WLR_ERROR, "unknown corner type");
        }
        cairo_close_path(cairo);
        cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
@@ -1203,20 +1196,18 @@ rounded_rect(struct rounded_corner_ctx *ctx)
        cairo_set_line_width(cairo, ctx->line_width);
        double half_line_width = ctx->line_width / 2.0;
        switch (ctx->corner) {
-       case LAB_CORNER_TOP_LEFT:
+       case ROUNDED_CORNER_TOP_LEFT:
                cairo_move_to(cairo, half_line_width, h);
                cairo_line_to(cairo, half_line_width, r);
                cairo_move_to(cairo, r, half_line_width);
                cairo_line_to(cairo, w, half_line_width);
                break;
-       case LAB_CORNER_TOP_RIGHT:
+       case ROUNDED_CORNER_TOP_RIGHT:
                cairo_move_to(cairo, 0, half_line_width);
                cairo_line_to(cairo, w - r, half_line_width);
                cairo_move_to(cairo, w - half_line_width, r);
                cairo_line_to(cairo, w - half_line_width, h);
                break;
-       default:
-               wlr_log(WLR_ERROR, "unknown corner type");
        }
        cairo_stroke(cairo);
 
@@ -1264,16 +1255,14 @@ rounded_rect(struct rounded_corner_ctx *ctx)
        cairo_set_line_width(cairo, line_width);
        half_line_width = line_width / 2.0;
        switch (ctx->corner) {
-       case LAB_CORNER_TOP_LEFT:
+       case ROUNDED_CORNER_TOP_LEFT:
                cairo_move_to(cairo, half_line_width, r);
                cairo_arc(cairo, r, r, r - half_line_width, 180 * deg, 270 * deg);
                break;
-       case LAB_CORNER_TOP_RIGHT:
+       case ROUNDED_CORNER_TOP_RIGHT:
                cairo_move_to(cairo, w - r, half_line_width);
                cairo_arc(cairo, w - r, r, r - half_line_width, -90 * deg, 0 * deg);
                break;
-       default:
-               break;
        }
        cairo_stroke(cairo);
 
@@ -1374,10 +1363,10 @@ create_corners(struct theme *theme)
                        .line_width = theme->border_width,
                        .fill_pattern = theme->window[active].titlebar_pattern,
                        .border_color = theme->window[active].border_color,
-                       .corner = LAB_CORNER_TOP_LEFT,
+                       .corner = ROUNDED_CORNER_TOP_LEFT,
                };
                theme->window[active].corner_top_left_normal = rounded_rect(&ctx);
-               ctx.corner = LAB_CORNER_TOP_RIGHT;
+               ctx.corner = ROUNDED_CORNER_TOP_RIGHT;
                theme->window[active].corner_top_right_normal = rounded_rect(&ctx);
        }
 }
index 8e67d0c5beb80b952dae91aa552aee16e82c6ba9..377d8c7678899bf3962efc7bc3bfe71962767e70 100644 (file)
@@ -59,7 +59,7 @@ view_impl_unmap(struct view *view)
 }
 
 static bool
-resizing_edge(struct view *view, uint32_t edge)
+resizing_edge(struct view *view, enum lab_edge edge)
 {
        struct server *server = view->server;
        return server->input_mode == LAB_INPUT_STATE_RESIZE
@@ -86,7 +86,7 @@ view_impl_apply_geometry(struct view *view, int w, int h)
         * reliable on its own. The combination of the two methods
         * should catch 99% of resize cases that we care about.
         */
-       bool resizing_left_edge = resizing_edge(view, WLR_EDGE_LEFT);
+       bool resizing_left_edge = resizing_edge(view, LAB_EDGE_LEFT);
        if (resizing_left_edge || (current->x != pending->x
                        && current->x + current->width ==
                        pending->x + pending->width)) {
@@ -96,7 +96,7 @@ view_impl_apply_geometry(struct view *view, int w, int h)
        }
 
        /* Anchor bottom edge if resizing via top edge */
-       bool resizing_top_edge = resizing_edge(view, WLR_EDGE_TOP);
+       bool resizing_top_edge = resizing_edge(view, LAB_EDGE_TOP);
        if (resizing_top_edge || (current->y != pending->y
                        && current->y + current->height ==
                        pending->y + pending->height)) {
index 8c697daf2f91c3dd76b1820102586b29ce5e0f82..67457d56d8227db73bcf5cb3ad384d45c3937ef5 100644 (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;
index e38038e54d1a1a23df2533973d928b5e48138995..00c4e22611c0d900a8f61b4dfc8993691ce9f944 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -399,7 +399,7 @@ handle_request_move(struct wl_listener *listener, void *data)
         */
        struct view *view = wl_container_of(listener, view, request_move);
        if (view == view->server->seat.pressed.view) {
-               interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
+               interactive_begin(view, LAB_INPUT_STATE_MOVE, LAB_EDGE_NONE);
        }
 }
 
@@ -653,7 +653,7 @@ xdg_toplevel_view_notify_tiled(struct view *view)
                return;
        }
 
-       enum wlr_edges edge = WLR_EDGE_NONE;
+       enum lab_edge edge = LAB_EDGE_NONE;
 
        bool want_edge = rc.snap_tiling_events_mode & LAB_TILING_EVENTS_EDGE;
        bool want_region = rc.snap_tiling_events_mode & LAB_TILING_EVENTS_REGION;
@@ -665,39 +665,32 @@ xdg_toplevel_view_notify_tiled(struct view *view)
        if (want_edge) {
                switch (view->tiled) {
                case LAB_EDGE_LEFT:
-                       edge = WLR_EDGE_LEFT | WLR_EDGE_TOP | WLR_EDGE_BOTTOM;
+                       edge = LAB_EDGES_EXCEPT_RIGHT;
                        break;
                case LAB_EDGE_RIGHT:
-                       edge = WLR_EDGE_RIGHT | WLR_EDGE_TOP | WLR_EDGE_BOTTOM;
+                       edge = LAB_EDGES_EXCEPT_LEFT;
                        break;
-               case LAB_EDGE_UP:
-                       edge = WLR_EDGE_TOP | WLR_EDGE_LEFT | WLR_EDGE_RIGHT;
+               case LAB_EDGE_TOP:
+                       edge = LAB_EDGES_EXCEPT_BOTTOM;
                        break;
-               case LAB_EDGE_DOWN:
-                       edge = WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | WLR_EDGE_RIGHT;
+               case LAB_EDGE_BOTTOM:
+                       edge = LAB_EDGES_EXCEPT_TOP;
                        break;
-               case LAB_EDGE_UPLEFT:
-                       edge = WLR_EDGE_TOP | WLR_EDGE_LEFT;
-                       break;
-               case LAB_EDGE_UPRIGHT:
-                       edge = WLR_EDGE_TOP | WLR_EDGE_RIGHT;
-                       break;
-               case LAB_EDGE_DOWNLEFT:
-                       edge = WLR_EDGE_BOTTOM | WLR_EDGE_LEFT;
-                       break;
-               case LAB_EDGE_DOWNRIGHT:
-                       edge = WLR_EDGE_BOTTOM | WLR_EDGE_RIGHT;
+               case LAB_EDGES_TOP_LEFT:
+               case LAB_EDGES_TOP_RIGHT:
+               case LAB_EDGES_BOTTOM_LEFT:
+               case LAB_EDGES_BOTTOM_RIGHT:
+                       edge = view->tiled;
                        break;
                /* TODO: LAB_EDGE_CENTER? */
                default:
-                       edge = WLR_EDGE_NONE;
+                       edge = LAB_EDGE_NONE;
                }
        }
 
        if (want_region && view->tiled_region) {
                /* Region-snapped views are considered tiled on all edges */
-               edge = WLR_EDGE_LEFT | WLR_EDGE_RIGHT |
-                       WLR_EDGE_TOP | WLR_EDGE_BOTTOM;
+               edge = LAB_EDGES_ALL;
        }
 
        uint32_t serial =
index 557305dc7a8c57933e5ab4f31c595aad4cd2b633..9f311e865c311efb7cc8b8f7dd15f5357934976f 100644 (file)
@@ -280,7 +280,7 @@ handle_request_move(struct wl_listener *listener, void *data)
         */
        struct view *view = wl_container_of(listener, view, request_move);
        if (view == view->server->seat.pressed.view) {
-               interactive_begin(view, LAB_INPUT_STATE_MOVE, 0);
+               interactive_begin(view, LAB_INPUT_STATE_MOVE, LAB_EDGE_NONE);
        }
 }