mirror of
https://github.com/labwc/labwc.git
synced 2025-10-29 05:40:24 -04:00
view: refactor view_edge_parse()
This commit is contained in:
parent
03004cf44b
commit
4b0ac0234c
4 changed files with 25 additions and 16 deletions
14
src/action.c
14
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 {
|
||||
|
|
|
|||
|
|
@ -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")) {
|
||||
|
|
|
|||
22
src/view.c
22
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue