view: refactor view_edge_parse()

This commit is contained in:
tokyo4j 2025-08-02 21:16:40 +09:00 committed by Johan Malm
parent 03004cf44b
commit 4b0ac0234c
4 changed files with 25 additions and 16 deletions

View file

@ -668,7 +668,7 @@ void view_init(struct view *view);
void view_destroy(struct view *view); void view_destroy(struct view *view);
enum view_axis view_axis_parse(const char *direction); 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); enum view_placement_policy view_placement_parse(const char *policy);
/* xdg.c */ /* xdg.c */

View 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_GROW_TO_EDGE:
case ACTION_TYPE_SHRINK_TO_EDGE: case ACTION_TYPE_SHRINK_TO_EDGE:
if (!strcmp(argument, "direction")) { if (!strcmp(argument, "direction")) {
enum view_edge edge = view_edge_parse(content); bool tiled = (action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE
bool allow_center = action->type == ACTION_TYPE_TOGGLE_SNAP_TO_EDGE || action->type == ACTION_TYPE_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_CENTER && !allow_center) if (edge == VIEW_EDGE_INVALID) {
|| edge == VIEW_EDGE_INVALID || edge == VIEW_EDGE_ALL) {
wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)", wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
action_names[action->type], argument, content); action_names[action->type], argument, content);
} else { } else {
@ -453,8 +452,9 @@ action_arg_from_xml_node(struct action *action, const char *nodename, const char
goto cleanup; goto cleanup;
} }
if (!strcmp(argument, "direction")) { if (!strcmp(argument, "direction")) {
enum view_edge edge = view_edge_parse(content); enum view_edge edge = view_edge_parse(content,
if (edge == VIEW_EDGE_CENTER || edge == VIEW_EDGE_ALL) { /*tiled*/ false, /*any*/ false);
if (edge == VIEW_EDGE_INVALID) {
wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)", wlr_log(WLR_ERROR, "Invalid argument for action %s: '%s' (%s)",
action_names[action->type], argument, content); action_names[action->type], argument, content);
} else { } else {

View file

@ -445,7 +445,8 @@ fill_action_query(struct action *action, xmlNode *node, struct view_query *query
} else if (!strcasecmp(key, "omnipresent")) { } else if (!strcasecmp(key, "omnipresent")) {
query->omnipresent = parse_three_state(content); query->omnipresent = parse_three_state(content);
} else if (!strcasecmp(key, "tiled")) { } 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")) { } else if (!strcasecmp(key, "tiled_region")) {
xstrdup_replace(query->tiled_region, content); xstrdup_replace(query->tiled_region, content);
} else if (!strcasecmp(key, "desktop")) { } else if (!strcasecmp(key, "desktop")) {

View file

@ -2119,7 +2119,7 @@ view_axis_parse(const char *direction)
} }
enum view_edge enum view_edge
view_edge_parse(const char *direction) view_edge_parse(const char *direction, bool tiled, bool any)
{ {
if (!direction) { if (!direction) {
return VIEW_EDGE_INVALID; return VIEW_EDGE_INVALID;
@ -2132,13 +2132,21 @@ view_edge_parse(const char *direction)
return VIEW_EDGE_RIGHT; return VIEW_EDGE_RIGHT;
} else if (!strcasecmp(direction, "down")) { } else if (!strcasecmp(direction, "down")) {
return VIEW_EDGE_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 enum view_placement_policy