From: tokyo4j Date: Sat, 2 Aug 2025 12:16:40 +0000 (+0900) Subject: view: refactor view_edge_parse() X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=4b0ac0234ce93d797bbea575774f2f0686c1b7d5;p=proto%2Flabwc.git view: refactor view_edge_parse() --- diff --git a/include/view.h b/include/view.h index a7aa1af0..6b2ccdb6 100644 --- a/include/view.h +++ b/include/view.h @@ -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 */ diff --git a/src/action.c b/src/action.c index 7441c81b..8d5eb5ac 100644 --- a/src/action.c +++ b/src/action.c @@ -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 { diff --git a/src/config/rcxml.c b/src/config/rcxml.c index f545a9ef..9c8e3e67 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -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")) { diff --git a/src/view.c b/src/view.c index 99a597cc..f1ffa85c 100644 --- a/src/view.c +++ b/src/view.c @@ -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