]>
Dogcows Code - chaz/openbox/blob - openbox/config.c
7 static void config_free_entry(ConfigEntry
*entry
);
8 static void config_set_entry(char *name
, ConfigValueType type
,
10 static void config_def_free(ConfigDefEntry
*entry
);
12 static GData
*config
= NULL
;
13 static GData
*config_def
= NULL
;
15 /* provided by cparse.l */
16 void cparse_go(char *filename
, FILE *);
23 /* set up options exported by the kernel */
24 config_def_set(config_def_new("engine", Config_String
,
26 "The name of the theming engine to be used "
27 "to decorate windows."));
28 config_def_set(config_def_new("theme", Config_String
,
30 "The name of the theme to load with the "
32 config_def_set(config_def_new("font", Config_String
,
34 "The fontstring specifying the font to "
35 "be used in window titlebars."));
36 config_def_set(config_def_new("font.shadow", Config_Bool
,
37 "Titlebar Font Shadow",
38 "Whether or not the text in the window "
39 "titlebars gets a drop shadow."));
40 config_def_set(config_def_new("font.shadow.offset", Config_Integer
,
41 "Titlebar Font Shadow Offset",
42 "The offset of the drop shadow for text "
43 "in the window titlebars."));
44 config_def_set(config_def_new("titlebar.layout", Config_String
,
46 "The ordering of the elements in the "
47 "window titlebars."));
49 config_def_set(config_def_new("focusNew", Config_Bool
,
51 "Focus windows when they first appear."));
53 config_set("focusNew", Config_Bool
, val
);
55 config_def_set(config_def_new("focusFollowsMouse", Config_Bool
,
56 "Focus Follows Mouse",
57 "Focus windows when the mouse pointer "
60 config_set("focusFollowsMouse", Config_Bool
, val
);
63 void config_shutdown()
65 g_datalist_clear(&config
);
66 g_datalist_clear(&config_def
);
73 gboolean load
= FALSE
;
75 /* load the user rc */
76 path
= g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL
);
77 if ((file
= fopen(path
, "r")) != NULL
) {
78 cparse_go(path
, file
);
85 /* load the system wide rc */
86 path
= g_build_filename(RCDIR
, "rc3", NULL
);
87 if ((file
= fopen(path
, "r")) != NULL
) {
88 /*cparse_go(path, file);*/
95 gboolean
config_set(char *name
, ConfigValueType type
, ConfigValue value
)
100 name
= g_ascii_strdown(name
, -1);
102 def
= g_datalist_get_data(&config_def
, name
);
105 g_warning("Invalid config option '%s'", name
);
108 gboolean found
= FALSE
;
112 g_assert(it
!= NULL
);
114 if (g_ascii_strcasecmp(it
->data
, value
.string
) == 0) {
118 } while ((it
= it
->next
));
121 g_warning("Invalid value '%s' for config option '%s'",
125 } else if (type
!= def
->type
) {
126 g_warning("Incorrect type of value for config option '%s'", name
);
133 config_set_entry(name
, type
, value
);
140 gboolean
config_get(char *name
, ConfigValueType type
, ConfigValue
*value
)
143 gboolean ret
= FALSE
;
145 name
= g_ascii_strdown(name
, -1);
146 entry
= g_datalist_get_data(&config
, name
);
147 if (entry
!= NULL
&& entry
->type
== type
) {
148 *value
= entry
->value
;
155 static void config_set_entry(char *name
, ConfigValueType type
,
158 ConfigEntry
*entry
= NULL
;
160 entry
= g_new(ConfigEntry
, 1);
163 if (type
== Config_String
)
164 entry
->value
.string
= g_strdup(value
.string
);
166 entry
->value
= value
;
168 g_datalist_set_data_full(&config
, name
, entry
,
169 (GDestroyNotify
)config_free_entry
);
172 static void config_free_entry(ConfigEntry
*entry
)
176 if(entry
->type
== Config_String
) {
177 g_free(entry
->value
.string
);
178 entry
->value
.string
= NULL
;
183 ConfigDefEntry
*config_def_new(char *name
, ConfigValueType type
,
184 char *descriptive_name
, char *long_description
)
186 ConfigDefEntry
*entry
;
188 entry
= g_new(ConfigDefEntry
, 1);
189 entry
->name
= g_ascii_strdown(name
, -1);
190 entry
->descriptive_name
= g_strdup(descriptive_name
);
191 entry
->long_description
= g_strdup(long_description
);
192 entry
->hasList
= FALSE
;
194 entry
->values
= NULL
;
198 static void config_def_free(ConfigDefEntry
*entry
)
203 g_free(entry
->descriptive_name
);
204 g_free(entry
->long_description
);
205 if (entry
->hasList
) {
206 for (it
= entry
->values
; it
!= NULL
; it
= it
->next
)
208 g_slist_free(entry
->values
);
213 gboolean
config_def_add_value(ConfigDefEntry
*entry
, char *value
)
215 if (entry
->type
!= Config_String
) {
216 g_warning("Tried adding value to non-string config definition");
220 entry
->hasList
= TRUE
;
221 entry
->values
= g_slist_append(entry
->values
, g_ascii_strdown(value
, -1));
225 gboolean
config_def_set(ConfigDefEntry
*entry
)
227 gboolean ret
= FALSE
;
230 if ((def
= g_datalist_get_data(&config_def
, entry
->name
))) {
231 g_assert(def
!= entry
); /* adding it twice!? */
232 g_warning("Definition already set for config option '%s'. ",
234 config_def_free(entry
);
236 g_datalist_set_data_full(&config_def
, entry
->name
, entry
,
237 (GDestroyNotify
)config_def_free
);
This page took 0.049826 seconds and 4 git commands to generate.