1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 action_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 "action_value.h"
20 #include "action_list.h"
25 struct _ObActionValue {
35 ObActionList *actions;
39 ObActionValue* action_value_new_string(const gchar *s)
41 return action_value_new_string_steal(g_strdup(s));
44 ObActionValue* action_value_new_string_steal(gchar *s)
46 ObActionValue *v = g_slice_new(ObActionValue);
48 v->type = OB_AV_STRING;
53 ObActionValue* action_value_new_action_list(ObActionList *al)
55 ObActionValue *v = g_slice_new(ObActionValue);
57 v->type = OB_AV_ACTIONLIST;
63 void action_value_ref(ObActionValue *v)
68 void action_value_unref(ObActionValue *v)
70 if (v && --v->ref < 1) {
75 case OB_AV_ACTIONLIST:
76 action_list_unref(v->v.actions);
79 g_slice_free(ObActionValue, v);
83 gboolean action_value_is_string(ObActionValue *v)
85 return v->type == OB_AV_STRING;
88 gboolean action_value_is_action_list(ObActionValue *v)
90 return v->type == OB_AV_ACTIONLIST;
93 const gchar* action_value_string(ObActionValue *v)
95 g_return_val_if_fail(v->type == OB_AV_STRING, NULL);
99 gboolean action_value_bool(ObActionValue *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 action_value_int(ObActionValue *v)
113 g_return_val_if_fail(v->type == OB_AV_STRING, 0);
115 return strtol(s, &s, 10);
118 void action_value_fraction(ObActionValue *v, gint *numer, gint *denom)
124 g_return_if_fail(v->type == OB_AV_STRING);
127 *numer = strtol(s, &s, 10);
134 void action_value_gravity_coord(ObActionValue *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 ObActionList* action_value_action_list(ObActionValue *v)
164 g_return_val_if_fail(v->type == OB_AV_ACTIONLIST, NULL);