]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add common/edge.c
authortokyo4j <hrak1529@gmail.com>
Thu, 21 Aug 2025 08:57:29 +0000 (17:57 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 21 Aug 2025 20:17:52 +0000 (21:17 +0100)
include/common/direction.h
include/common/edge.h [new file with mode: 0644]
include/config/types.h
include/view.h
src/action.c
src/common/edge.c [new file with mode: 0644]
src/common/meson.build
src/config/rcxml.c
src/view.c

index be05d29c93b6b70b6d99771ed21b9704044bf301..a1e6530ea835f0a952b2ba39b5c44e3253fd37c4 100644 (file)
@@ -3,7 +3,7 @@
 #define LABWC_DIRECTION_H
 
 #include <wlr/types/wlr_output_layout.h>
-#include "config/types.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);
diff --git a/include/common/edge.h b/include/common/edge.h
new file mode 100644 (file)
index 0000000..23b5fdd
--- /dev/null
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LABWC_EDGE_H
+#define LABWC_EDGE_H
+
+#include <wayland-server-core.h>
+
+/**
+ * Represents an edge or direction (e.g. window tiling, window motion)
+ */
+enum lab_edge {
+       LAB_EDGE_INVALID = 0,
+
+       LAB_EDGE_LEFT = (1 << 0),
+       LAB_EDGE_RIGHT = (1 << 1),
+       LAB_EDGE_UP = (1 << 2),
+       LAB_EDGE_DOWN = (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),
+};
+
+enum lab_edge lab_edge_parse(const char *direction, bool tiled, bool any);
+
+/**
+ * lab_edge_invert() - select the opposite of a provided edge
+ *
+ * Returns LAB_EDGE_INVALID for edges other than UP/DOWN/LEFT/RIGHT.
+ *
+ * @edge: edge to be inverted
+ */
+enum lab_edge lab_edge_invert(enum lab_edge edge);
+
+#endif /* LABWC_EDGE_H */
index 246c75275ce34b0d72e6cee2747f1b8f7e90a787..18d08700e32f01d6f24143fe51c4cd2922559717 100644 (file)
  * For the full config struct, see config/rcxml.h.
  */
 
-/**
- * Edges to which a view can be snapped. "Any" is used as
- * a catch-all for every valid edge in order to simplify certain
- * types of conditionals, but it is only valid for a selection
- * of options in rc.xml.
- */
-enum lab_edge {
-       LAB_EDGE_INVALID = 0,
-
-       LAB_EDGE_LEFT = (1 << 0),
-       LAB_EDGE_RIGHT = (1 << 1),
-       LAB_EDGE_UP = (1 << 2),
-       LAB_EDGE_DOWN = (1 << 3),
-       LAB_EDGE_CENTER = (1 << 4),
-       LAB_EDGE_ANY = (1 << 5),
-
-       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),
-};
-
 /**
  * Indicates whether tablet tool motion events should be reported using
  * absolute or relative coordinates
index 2aa7df6769a5ef2474a491cafd0023d61e6efec5..4efb228315085c6efac7e12d214d4088201631ab 100644 (file)
@@ -7,6 +7,7 @@
 #include <wayland-util.h>
 #include <wlr/util/box.h>
 #include <xkbcommon/xkbcommon.h>
+#include "common/edge.h"
 #include "config.h"
 #include "config/types.h"
 
@@ -422,15 +423,6 @@ void view_array_append(struct server *server, struct wl_array *views,
 enum view_wants_focus view_wants_focus(struct view *view);
 bool view_contains_window_type(struct view *view, enum lab_window_type window_type);
 
-/**
- * view_edge_invert() - select the opposite of a provided edge
- *
- * LAB_EDGE_CENTER and LAB_EDGE_INVALID both map to LAB_EDGE_INVALID.
- *
- * @edge: edge to be inverted
- */
-enum lab_edge view_edge_invert(enum lab_edge edge);
-
 /* If view is NULL, the size of SSD is not considered */
 struct wlr_box view_get_edge_snap_box(struct view *view, struct output *output,
        enum lab_edge edge);
@@ -601,7 +593,6 @@ void view_init(struct view *view);
 void view_destroy(struct view *view);
 
 enum view_axis view_axis_parse(const char *direction);
-enum lab_edge view_edge_parse(const char *direction, bool tiled, bool any);
 enum lab_placement_policy view_placement_parse(const char *policy);
 
 /* xdg.c */
index 2722998f80b823228d936ca3bb8e1e637784d0cd..a65d73718e9c6ce012b3d25b9f4dced7eba5ca10 100644 (file)
@@ -347,7 +347,7 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                if (!strcmp(argument, "direction")) {
                        bool tiled = (action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE
                                        || action->type == ACTION_TYPE_SNAP_TO_EDGE);
-                       enum lab_edge edge = view_edge_parse(content, tiled, /*any*/ false);
+                       enum lab_edge edge = lab_edge_parse(content, tiled, /*any*/ false);
                        if (edge == LAB_EDGE_INVALID) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
                                        action_names[action->type], argument, content);
@@ -455,7 +455,7 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                        goto cleanup;
                }
                if (!strcmp(argument, "direction")) {
-                       enum lab_edge edge = view_edge_parse(content,
+                       enum lab_edge edge = lab_edge_parse(content,
                                /*tiled*/ false, /*any*/ false);
                        if (edge == LAB_EDGE_INVALID) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
diff --git a/src/common/edge.c b/src/common/edge.c
new file mode 100644 (file)
index 0000000..20b8eb9
--- /dev/null
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include "common/edge.h"
+#include <strings.h>
+
+enum lab_edge
+lab_edge_parse(const char *direction, bool tiled, bool any)
+{
+       if (!direction) {
+               return LAB_EDGE_INVALID;
+       }
+       if (!strcasecmp(direction, "left")) {
+               return LAB_EDGE_LEFT;
+       } else if (!strcasecmp(direction, "up")) {
+               return LAB_EDGE_UP;
+       } else if (!strcasecmp(direction, "right")) {
+               return LAB_EDGE_RIGHT;
+       } else if (!strcasecmp(direction, "down")) {
+               return LAB_EDGE_DOWN;
+       }
+
+       if (any) {
+               if (!strcasecmp(direction, "any")) {
+                       return LAB_EDGE_ANY;
+               }
+       }
+
+       if (tiled) {
+               if (!strcasecmp(direction, "center")) {
+                       return LAB_EDGE_CENTER;
+               } else if (!strcasecmp(direction, "up-left")) {
+                       return LAB_EDGE_UPLEFT;
+               } else if (!strcasecmp(direction, "up-right")) {
+                       return LAB_EDGE_UPRIGHT;
+               } else if (!strcasecmp(direction, "down-left")) {
+                       return LAB_EDGE_DOWNLEFT;
+               } else if (!strcasecmp(direction, "down-right")) {
+                       return LAB_EDGE_DOWNRIGHT;
+               }
+       }
+
+       return LAB_EDGE_INVALID;
+}
+
+enum lab_edge
+lab_edge_invert(enum lab_edge edge)
+{
+       switch (edge) {
+       case LAB_EDGE_LEFT:
+               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;
+       default:
+               return LAB_EDGE_INVALID;
+       }
+}
index aa0fc41331f46aae2806fbf885fd142eff4c7f3a..e0b903360dfa4ee0ac1b9fb98cb4016b811d8001 100644 (file)
@@ -3,6 +3,7 @@ labwc_sources += files(
   'box.c',
   'buf.c',
   'dir.c',
+  'edge.c',
   'fd-util.c',
   'file-helpers.c',
   'font.c',
index 17703e6817ba9c4443cf2c97694f8b89c65da72d..8746836bc15d8c62895a2efc6c366b19b8650dcb 100644 (file)
@@ -444,7 +444,7 @@ fill_action_query(struct action *action, xmlNode *node, struct view_query *query
                } else if (!strcasecmp(key, "omnipresent")) {
                        query->omnipresent = parse_tristate(content);
                } else if (!strcasecmp(key, "tiled")) {
-                       query->tiled = view_edge_parse(content,
+                       query->tiled = lab_edge_parse(content,
                                /*tiled*/ true, /*any*/ true);
                } else if (!strcasecmp(key, "tiled_region")) {
                        xstrdup_replace(query->tiled_region, content);
index 4088512ab57e74f7c3a4bf995f9c8c733f18ee32..ff863d3220fd8326658ba14e8d8bb8eece1a3189 100644 (file)
@@ -429,25 +429,6 @@ view_offer_focus(struct view *view)
  * They may be called repeatably during output layout changes.
  */
 
-enum lab_edge
-view_edge_invert(enum lab_edge edge)
-{
-       switch (edge) {
-       case LAB_EDGE_LEFT:
-               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_CENTER:
-       case LAB_EDGE_INVALID:
-       default:
-               return LAB_EDGE_INVALID;
-       }
-}
-
 struct wlr_box
 view_get_edge_snap_box(struct view *view, struct output *output,
                enum lab_edge edge)
@@ -2020,7 +2001,7 @@ view_move_to_edge(struct view *view, enum lab_edge direction, bool snap_to_windo
        int destination_y = view->pending.y;
 
        /* Compute the new position in the direction of motion */
-       direction = view_edge_invert(direction);
+       direction = lab_edge_invert(direction);
        switch (direction) {
        case LAB_EDGE_LEFT:
                destination_x = left;
@@ -2120,45 +2101,6 @@ view_axis_parse(const char *direction)
        }
 }
 
-enum lab_edge
-view_edge_parse(const char *direction, bool tiled, bool any)
-{
-       if (!direction) {
-               return LAB_EDGE_INVALID;
-       }
-       if (!strcasecmp(direction, "left")) {
-               return LAB_EDGE_LEFT;
-       } else if (!strcasecmp(direction, "up")) {
-               return LAB_EDGE_UP;
-       } else if (!strcasecmp(direction, "right")) {
-               return LAB_EDGE_RIGHT;
-       } else if (!strcasecmp(direction, "down")) {
-               return LAB_EDGE_DOWN;
-       }
-
-       if (any) {
-               if (!strcasecmp(direction, "any")) {
-                       return LAB_EDGE_ANY;
-               }
-       }
-
-       if (tiled) {
-               if (!strcasecmp(direction, "center")) {
-                       return LAB_EDGE_CENTER;
-               } else if (!strcasecmp(direction, "up-left")) {
-                       return LAB_EDGE_UPLEFT;
-               } else if (!strcasecmp(direction, "up-right")) {
-                       return LAB_EDGE_UPRIGHT;
-               } else if (!strcasecmp(direction, "down-left")) {
-                       return LAB_EDGE_DOWNLEFT;
-               } else if (!strcasecmp(direction, "down-right")) {
-                       return LAB_EDGE_DOWNRIGHT;
-               }
-       }
-
-       return LAB_EDGE_INVALID;
-}
-
 enum lab_placement_policy
 view_placement_parse(const char *policy)
 {
@@ -2215,7 +2157,7 @@ view_snap_to_edge(struct view *view, enum lab_edge edge,
                }
 
                /* When switching outputs, jump to the opposite edge */
-               edge = view_edge_invert(edge);
+               edge = lab_edge_invert(edge);
        }
 
        if (view->maximized != VIEW_AXIS_NONE) {