]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config/rcxml.c: fix parsing of three-state query parameters
authorAndrew J. Hesford <ajh@sideband.org>
Thu, 31 Oct 2024 01:05:23 +0000 (21:05 -0400)
committerAndrew J. Hesford <ajh@sideband.org>
Thu, 31 Oct 2024 01:53:23 +0000 (21:53 -0400)
include/common/parse-bool.h
src/common/parse-bool.c
src/config/rcxml.c

index 65fff3840cc0054634dcc2879c515e543601a9b5..2d26c4b8e15376a51f2169c06fb4c107260fa966 100644 (file)
@@ -2,6 +2,16 @@
 #ifndef LABWC_PARSE_BOOL_H
 #define LABWC_PARSE_BOOL_H
 #include <stdbool.h>
+#include "view.h"
+
+/**
+ * parse_three_state() - Parse boolean value of string as a three-state enum.
+ * @string: String to interpret. This check is case-insensitive.
+ *
+ * Return: LAB_STATE_DISABLED for false; LAB_STATE_ENABLED for true;
+ * LAB_STATE_UNSPECIFIED for non-boolean
+ */
+enum three_state parse_three_state(const char *str);
 
 /**
  * parse_bool() - Parse boolean value of string.
index edef698ad5b7406feffe8be7c71a2d350dabd60e..dc6780f5ebd5a2539172fb29fc6d300547816d22 100644 (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
index 198fe38b9b79d5fab70357b37d4fc2f3d75e5735..e4f6426ed7316bb2b5b14211fb30abfb17b20863 100644 (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")) {