config/rcxml.c: fix parsing of three-state query parameters

This commit is contained in:
Andrew J. Hesford 2024-10-30 21:05:23 -04:00
parent 96da82c085
commit 2b877d2293
3 changed files with 35 additions and 15 deletions

View file

@ -3,31 +3,41 @@
#include <wlr/util/log.h>
#include "common/parse-bool.h"
int
parse_bool(const char *str, int default_value)
enum three_state
parse_three_state(const char *str)
{
if (!str) {
goto error_not_a_boolean;
} else if (!strcasecmp(str, "yes")) {
return true;
return LAB_STATE_ENABLED;
} else if (!strcasecmp(str, "true")) {
return true;
return LAB_STATE_ENABLED;
} else if (!strcasecmp(str, "on")) {
return true;
return LAB_STATE_ENABLED;
} else if (!strcmp(str, "1")) {
return true;
return LAB_STATE_ENABLED;
} else if (!strcasecmp(str, "no")) {
return false;
return LAB_STATE_DISABLED;
} else if (!strcasecmp(str, "false")) {
return false;
return LAB_STATE_DISABLED;
} else if (!strcasecmp(str, "off")) {
return false;
return LAB_STATE_DISABLED;
} else if (!strcmp(str, "0")) {
return false;
return LAB_STATE_DISABLED;
}
error_not_a_boolean:
wlr_log(WLR_ERROR, "(%s) is not a boolean value", str);
return default_value;
return LAB_STATE_UNSPECIFIED;
}
int
parse_bool(const char *str, int default_value)
{
enum three_state val = parse_three_state(str);
if (val == LAB_STATE_UNSPECIFIED) {
return default_value;
}
return (val == LAB_STATE_ENABLED) ? 1 : 0;
}
void

View file

@ -474,15 +474,15 @@ fill_action_query(char *nodename, char *content, struct action *action)
} else if (!strcasecmp(nodename, "sandboxAppId")) {
current_view_query->sandbox_app_id = xstrdup(content);
} else if (!strcasecmp(nodename, "shaded")) {
current_view_query->shaded = parse_bool(content, -1);
current_view_query->shaded = parse_three_state(content);
} else if (!strcasecmp(nodename, "maximized")) {
current_view_query->maximized = view_axis_parse(content);
} else if (!strcasecmp(nodename, "iconified")) {
current_view_query->iconified = parse_bool(content, -1);
current_view_query->iconified = parse_three_state(content);
} else if (!strcasecmp(nodename, "focused")) {
current_view_query->focused = parse_bool(content, -1);
current_view_query->focused = parse_three_state(content);
} else if (!strcasecmp(nodename, "omnipresent")) {
current_view_query->omnipresent = parse_bool(content, -1);
current_view_query->omnipresent = parse_three_state(content);
} else if (!strcasecmp(nodename, "tiled")) {
current_view_query->tiled = view_edge_parse(content);
} else if (!strcasecmp(nodename, "tiled_region")) {