]> icculus.org git repositories - dana/openbox.git/blob - openbox/config_value.h
wip: Add config_parser.c which will provide a nice means to specify config variables...
[dana/openbox.git] / openbox / config_value.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    config_value.h for the Openbox window manager
4    Copyright (c) 2011        Dana Jansens
5
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.
10
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.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include <glib.h>
20
21 struct _GravityCoord;
22 struct _ObActionList;
23
24 typedef struct _ObConfigValue ObConfigValue;
25 typedef struct _ObConfigValueEnum ObConfigValueEnum;
26
27 struct _ObConfigValueEnum {
28     const gchar *name;
29     guint value;
30 };
31
32 typedef enum {
33     OB_CONFIG_VALUE_STRING,
34     OB_CONFIG_VALUE_BOOLEAN,
35     OB_CONFIG_VALUE_ENUM,
36     OB_CONFIG_VALUE_INTEGER,
37     OB_CONFIG_VALUE_FRACTION,
38     OB_CONFIG_VALUE_GRAVITY_COORD,
39     OB_CONFIG_VALUE_KEY,
40     OB_CONFIG_VALUE_BUTTON,
41     OB_CONFIG_VALUE_STRING_LIST,
42     OB_CONFIG_VALUE_LIST,
43     OB_CONFIG_VALUE_ACTIONLIST,
44     NUM_OB_CONFIG_VALUE_TYPES
45 } ObConfigValueDataType;
46
47 /*! This holds a pointer to one of the possible types in ObConfigValueType. */
48 typedef union _ObConfigValueDataPtr {
49     const gpointer *pointer; /*!< Generic pointer */
50     const gchar **string;
51     gboolean *boolean;
52     guint *integer;
53     guint *enumeration;
54     struct {
55         guint numer;
56         guint denom;
57     } *fraction;
58     struct _GravityCoord *coord;
59     struct _ObKeyboardKey *key;
60     struct _ObMouseButton *button;
61     const gchar *const**list;
62     struct _ObActionList **actions;
63 } ObConfigValueDataPtr;
64
65 void config_value_ref(ObConfigValue *v);
66 void config_value_unref(ObConfigValue *v);
67
68 /*! Creates a new value by making a copy of the given string. */
69 ObConfigValue* config_value_new_string(const gchar *s);
70 /*! Creates a new value from a string, and steals ownership of the string. It
71   will be freed when then value is destroyed. */
72 ObConfigValue* config_value_new_string_steal(gchar *s);
73
74 /*! Creates a config value which holds a list of other values
75   This function copies the list and adds a refcount to the values within. */
76 ObConfigValue* config_value_new_string_list(gchar **list);
77 /*! Creates a config value which holds a list of other values.
78   This function steals ownership the list and the values within. */
79 ObConfigValue* config_value_new_string_list_steal(gchar **list);
80
81 ObConfigValue* config_value_new_action_list(struct _ObActionList *al);
82
83 gboolean config_value_is_string(const ObConfigValue *v);
84 gboolean config_value_is_string_list(const ObConfigValue *v);
85 gboolean config_value_is_action_list(const ObConfigValue *v);
86
87 /*! Copies the data inside @v to the destination that the pointer @p is
88   pointing to. */
89 gboolean config_value_copy_ptr(ObConfigValue *v,
90                                ObConfigValueDataType type,
91                                ObConfigValueDataPtr p,
92                                const ObConfigValueEnum e[]);
93
94 /* These ones are valid on a string value */
95
96 const gchar* config_value_string(ObConfigValue *v);
97 gboolean config_value_bool(ObConfigValue *v);
98 guint config_value_int(ObConfigValue *v);
99 /*! returns FALSE if the value isn't in the enumeration */
100 gboolean config_value_enum(ObConfigValue *v, const ObConfigValueEnum e[],
101                            guint *out);
102 void config_value_fraction(ObConfigValue *v, gint *numer, gint *denom);
103 void config_value_gravity_coord(ObConfigValue *v, struct _GravityCoord *c);
104 /*! returns FALSE if the key string isn't valid */
105 gboolean config_value_key(ObConfigValue *v, struct _ObKeyboardKey *k);
106 /*! returns FALSE if the button string isn't valid */
107 gboolean config_value_button(ObConfigValue *v, struct _ObMouseButton *b);
108
109 /* These ones are valid on a string list value */
110
111 gchar const*const* config_value_string_list(ObConfigValue *v);
112
113 /* These ones are value on a action list value */
114
115 struct _ObActionList* config_value_action_list(ObConfigValue *v);