]> git.mdlowis.com Git - proto/labwc.git/commitdiff
action: support arguments of int type
authorJohan Malm <jgm323@gmail.com>
Sun, 25 Jun 2023 19:20:52 +0000 (20:20 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 26 Jun 2023 05:04:07 +0000 (06:04 +0100)
src/action.c

index 3699a39f538bfc42f1e04f7a5b329129d16eea8b..12b878dcd269310b1096d0827e7e319605b57e10 100644 (file)
@@ -23,6 +23,7 @@
 enum action_arg_type {
        LAB_ACTION_ARG_STR = 0,
        LAB_ACTION_ARG_BOOL,
+       LAB_ACTION_ARG_INT,
 };
 
 struct action_arg {
@@ -42,6 +43,11 @@ struct action_arg_bool {
        bool value;
 };
 
+struct action_arg_int {
+       struct action_arg base;
+       int value;
+};
+
 enum action_type {
        ACTION_TYPE_INVALID = 0,
        ACTION_TYPE_NONE,
@@ -134,6 +140,18 @@ action_arg_add_bool(struct action *action, char *key, bool value)
        wl_list_append(&action->args, &arg->base.link);
 }
 
+static void
+action_arg_add_int(struct action *action, char *key, int value)
+{
+       struct action_arg_int *arg = znew(*arg);
+       arg->base.type = LAB_ACTION_ARG_INT;
+       if (key) {
+               arg->base.key = xstrdup(key);
+       }
+       arg->value = value;
+       wl_list_append(&action->args, &arg->base.link);
+}
+
 void
 action_arg_from_xml_node(struct action *action, char *nodename, char *content)
 {
@@ -247,6 +265,23 @@ get_arg_value_bool(struct action *action, const char *key, bool default_value)
        return default_value;
 }
 
+static int
+get_arg_value_int(struct action *action, const char *key, int default_value)
+{
+       assert(key);
+       struct action_arg *arg;
+       wl_list_for_each(arg, &action->args, link) {
+               if (!arg->key) {
+                       continue;
+               }
+               if (!strcasecmp(key, arg->key)) {
+                       assert(arg->type == LAB_ACTION_ARG_INT);
+                       return ((struct action_arg_int *)arg)->value;
+               }
+       }
+       return default_value;
+}
+
 static struct action_arg *
 action_get_first_arg(struct action *action)
 {