1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 actions_value.c for the Openbox window manager
4 Copyright (c) 2011 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
19 #include "actions_value.h"
20 #include "actions_list.h"
25 struct _ObActionsValue {
35 ObActionsList *actions;
39 ObActionsValue* actions_value_new_string(const gchar *s)
41 return actions_value_new_string_steal(g_strdup(s));
44 ObActionsValue* actions_value_new_string_steal(gchar *s)
46 ObActionsValue *v = g_slice_new(ObActionsValue);
48 v->type = OB_AV_STRING;
53 ObActionsValue* actions_value_new_actions_list(ObActionsList *al)
55 ObActionsValue *v = g_slice_new(ObActionsValue);
57 v->type = OB_AV_ACTIONSLIST;
63 void actions_value_ref(ObActionsValue *v)
68 void actions_value_unref(ObActionsValue *v)
70 if (v && --v->ref < 1) {
75 case OB_AV_ACTIONSLIST:
76 actions_list_unref(v->v.actions);
79 g_slice_free(ObActionsValue, v);
83 gboolean actions_value_is_string(ObActionsValue *v)
85 return v->type == OB_AV_STRING;
88 gboolean actions_value_is_actions_list(ObActionsValue *v)
90 return v->type == OB_AV_ACTIONSLIST;
93 const gchar* actions_value_string(ObActionsValue *v)
95 g_return_val_if_fail(v->type == OB_AV_STRING, NULL);
99 gboolean actions_value_bool(ObActionsValue *v)
101 g_return_val_if_fail(v->type == OB_AV_STRING, FALSE);
102 if (g_strcasecmp(v->v.string, "true") == 0 ||
103 g_strcasecmp(v->v.string, "yes") == 0)
109 gint actions_value_int(ObActionsValue *v)
113 g_return_val_if_fail(v->type == OB_AV_STRING, 0);
115 return strtol(s, &s, 10);
118 void actions_value_fraction(ObActionsValue *v, gint *numer, gint *denom)
124 g_return_if_fail(v->type == OB_AV_STRING);
127 *numer = strtol(s, &s, 10);
134 void actions_value_gravity_coord(ObActionsValue *v, GravityCoord *c)
142 g_return_if_fail(v->type == OB_AV_STRING);
145 if (!g_ascii_strcasecmp(s, "center"))
150 if (s[0] == '-' || s[0] == '+')
153 c->pos = strtol(s, &s, 10);
158 c->denom = atoi(s+1);
162 ObActionsList* actions_value_actions_list(ObActionsValue *v)
164 g_return_val_if_fail(v->type == OB_AV_ACTIONSLIST, NULL);