]> git.mdlowis.com Git - proto/labwc.git/commitdiff
view: refactor view_edge_parse()
authortokyo4j <hrak1529@gmail.com>
Sat, 2 Aug 2025 12:16:40 +0000 (21:16 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 4 Aug 2025 20:24:12 +0000 (21:24 +0100)
include/view.h
src/action.c
src/config/rcxml.c
src/view.c

index a7aa1af057f4aaaa259b3a724081ba7a6ea4b8f6..6b2ccdb654e1e81c2c8f20fbbd7bf92fa11077e3 100644 (file)
@@ -668,7 +668,7 @@ void view_init(struct view *view);
 void view_destroy(struct view *view);
 
 enum view_axis view_axis_parse(const char *direction);
-enum view_edge view_edge_parse(const char *direction);
+enum view_edge view_edge_parse(const char *direction, bool tiled, bool any);
 enum view_placement_policy view_placement_parse(const char *policy);
 
 /* xdg.c */
index 7441c81bf1b7ff7660e3153b55d5d0211e0e2df5..8d5eb5ac2e2659c028c169faa032f9f7de216bc6 100644 (file)
@@ -342,11 +342,10 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
        case ACTION_TYPE_GROW_TO_EDGE:
        case ACTION_TYPE_SHRINK_TO_EDGE:
                if (!strcmp(argument, "direction")) {
-                       enum view_edge edge = view_edge_parse(content);
-                       bool allow_center = action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE
-                               || action->type == ACTION_TYPE_SNAP_TO_EDGE;
-                       if ((edge == VIEW_EDGE_CENTER && !allow_center)
-                                       || edge == VIEW_EDGE_INVALID || edge == VIEW_EDGE_ALL) {
+                       bool tiled = (action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE
+                                       || action->type == ACTION_TYPE_SNAP_TO_EDGE);
+                       enum view_edge edge = view_edge_parse(content, tiled, /*any*/ false);
+                       if (edge == VIEW_EDGE_INVALID) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
                                        action_names[action->type], argument, content);
                        } else {
@@ -453,8 +452,9 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
                        goto cleanup;
                }
                if (!strcmp(argument, "direction")) {
-                       enum view_edge edge = view_edge_parse(content);
-                       if (edge == VIEW_EDGE_CENTER || edge == VIEW_EDGE_ALL) {
+                       enum view_edge edge = view_edge_parse(content,
+                               /*tiled*/ false, /*any*/ false);
+                       if (edge == VIEW_EDGE_INVALID) {
                                wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
                                        action_names[action->type], argument, content);
                        } else {
index f545a9efa3732262a930e4d1965e856c1c277e25..9c8e3e6764197d261d954b3a28858f8d86c53b62 100644 (file)
@@ -445,7 +445,8 @@ fill_action_query(struct action *action, xmlNode *node, struct view_query *query
                } else if (!strcasecmp(key, "omnipresent")) {
                        query->omnipresent = parse_three_state(content);
                } else if (!strcasecmp(key, "tiled")) {
-                       query->tiled = view_edge_parse(content);
+                       query->tiled = view_edge_parse(content,
+                               /*tiled*/ true, /*any*/ true);
                } else if (!strcasecmp(key, "tiled_region")) {
                        xstrdup_replace(query->tiled_region, content);
                } else if (!strcasecmp(key, "desktop")) {
index 99a597ccd7d6e4d0ebd6978cb889b80d768d660a..f1ffa85c02959850c0a8e7ba70a39d29ae1de150 100644 (file)
@@ -2119,7 +2119,7 @@ view_axis_parse(const char *direction)
 }
 
 enum view_edge
-view_edge_parse(const char *direction)
+view_edge_parse(const char *direction, bool tiled, bool any)
 {
        if (!direction) {
                return VIEW_EDGE_INVALID;
@@ -2132,13 +2132,21 @@ view_edge_parse(const char *direction)
                return VIEW_EDGE_RIGHT;
        } else if (!strcasecmp(direction, "down")) {
                return VIEW_EDGE_DOWN;
-       } else if (!strcasecmp(direction, "center")) {
-               return VIEW_EDGE_CENTER;
-       } else if (!strcasecmp(direction, "any")) {
-               return VIEW_EDGE_ALL;
-       } else {
-               return VIEW_EDGE_INVALID;
        }
+
+       if (any) {
+               if (!strcasecmp(direction, "any")) {
+                       return VIEW_EDGE_ALL;
+               }
+       }
+
+       if (tiled) {
+               if (!strcasecmp(direction, "center")) {
+                       return VIEW_EDGE_CENTER;
+               }
+       }
+
+       return VIEW_EDGE_INVALID;
 }
 
 enum view_placement_policy