ignore BadMatch error for XConfigureWindow() calls
[awesome.git] / common / configopts.c
blob1c32c8eee3a7ace5ec93c96c83ecfedec88bbe04
1 /*
2 * configopts.c - configuration options
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
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 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <confuse.h>
24 #include "rules.h"
25 #include "common/configopts.h"
27 #define AWESOME_CONFIG_FILE ".awesomerc"
29 #define CFG_AWESOME_END() \
30 CFG_FUNC((char *) "include", cfg_include), \
31 CFG_END()
33 cfg_opt_t general_opts[] =
35 CFG_INT((char *) "border", 1, CFGF_NONE),
36 CFG_INT((char *) "snap", 8, CFGF_NONE),
37 CFG_BOOL((char *) "resize_hints", cfg_true, CFGF_NONE),
38 CFG_BOOL((char *) "sloppy_focus", cfg_true, CFGF_NONE),
39 CFG_BOOL((char *) "sloppy_focus_raise", cfg_false, CFGF_NONE),
40 CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE),
41 CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE),
42 CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE),
43 CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
44 CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE),
45 CFG_AWESOME_END()
47 cfg_opt_t colors_opts[] =
49 CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE),
50 CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE),
51 CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE),
52 CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE),
53 CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE),
54 CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE),
55 CFG_STR((char *) "urgent_bg", (char *) "#ff0000", CFGF_NONE),
56 CFG_STR((char *) "urgent_fg", (char *) "#ffffff", CFGF_NONE),
57 CFG_STR((char *) "tab_border", (char *) "#ff0000", CFGF_NONE),
58 CFG_AWESOME_END()
60 cfg_opt_t mouse_taglist_opts[] =
62 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE),
63 CFG_STR((char *) "button", (char *) "None", CFGF_NONE),
64 CFG_STR((char *) "command", (char *) "", CFGF_NONE),
65 CFG_AWESOME_END()
67 cfg_opt_t mouse_generic_opts[] =
69 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE),
70 CFG_STR((char *) "button", (char *) "None", CFGF_NONE),
71 CFG_STR((char *) "command", (char *) "", CFGF_NONE),
72 CFG_STR((char *) "arg", NULL, CFGF_NONE),
73 CFG_AWESOME_END()
75 cfg_opt_t widget_opts[] =
77 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
78 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
79 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
80 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
81 CFG_AWESOME_END()
83 cfg_opt_t widget_taglist_opts[] =
85 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
86 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
87 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
88 CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
89 CFG_AWESOME_END()
91 cfg_opt_t widget_iconbox_opts[] =
93 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
94 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
95 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
96 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
97 CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
98 CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE),
99 CFG_AWESOME_END()
101 cfg_opt_t widget_textbox_opts[] =
103 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
104 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
105 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
106 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
107 CFG_INT((char *) "width", 0, CFGF_NONE),
108 CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
109 CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
110 CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
111 CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
112 CFG_STR((char *) "text_align", (char *) "center", CFGF_NONE),
113 CFG_AWESOME_END()
115 cfg_opt_t widget_tasklist_opts[] =
117 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
118 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
119 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
120 CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
121 CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
122 CFG_STR((char *) "focus_fg", (char *) NULL, CFGF_NONE),
123 CFG_STR((char *) "focus_bg", (char *) NULL, CFGF_NONE),
124 CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
125 CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE),
126 CFG_STR((char *) "show", (char *) "tags", CFGF_NONE),
127 CFG_BOOL((char *) "show_icons", cfg_true, CFGF_NONE),
128 CFG_AWESOME_END()
130 cfg_opt_t widget_graph_data_opts[] =
132 CFG_FLOAT((char *) "max", 100.0f, CFGF_NONE),
133 CFG_BOOL((char *) "scale", cfg_false, CFGF_NONE),
134 CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
135 CFG_STR((char *) "fg_center", (char *) NULL, CFGF_NONE),
136 CFG_STR((char *) "fg_end", (char *) NULL, CFGF_NONE),
137 CFG_STR((char *) "style", (char *) "bottom", CFGF_NONE),
138 CFG_AWESOME_END()
140 cfg_opt_t widget_graph_opts[] =
142 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
143 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
144 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
145 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
146 CFG_SEC((char *) "data", widget_graph_data_opts, CFGF_MULTI),
147 CFG_INT((char *) "width", 100, CFGF_NONE),
148 CFG_INT((char *) "padding_left", 0, CFGF_NONE),
149 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE),
150 CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
151 CFG_STR((char *) "bordercolor", (char *) NULL, CFGF_NONE),
152 CFG_AWESOME_END()
154 cfg_opt_t widget_progressbar_bar_opts[] =
156 CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
157 CFG_STR((char *) "fg_center", (char *) NULL, CFGF_NONE),
158 CFG_STR((char *) "fg_end", (char *) NULL, CFGF_NONE),
159 CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
160 CFG_STR((char *) "bordercolor", (char *) NULL, CFGF_NONE),
161 CFG_AWESOME_END()
163 cfg_opt_t widget_progressbar_opts[] =
165 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
166 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
167 CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
168 CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
169 CFG_SEC((char *) "bar", widget_progressbar_bar_opts, CFGF_MULTI),
170 CFG_INT((char *) "width", 100, CFGF_NONE),
171 CFG_INT((char *) "gap", 2, CFGF_NONE),
172 CFG_INT((char *) "padding", 0, CFGF_NONE),
173 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE),
174 CFG_AWESOME_END()
176 cfg_opt_t statusbar_opts[] =
178 CFG_STR((char *) "position", (char *) "top", CFGF_NONE),
179 CFG_INT((char *) "height", 0, CFGF_NONE),
180 CFG_INT((char *) "width", 0, CFGF_NONE),
181 CFG_SEC((char *) "textbox", widget_textbox_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
182 CFG_SEC((char *) "taglist", widget_taglist_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
183 CFG_SEC((char *) "layoutinfo", widget_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
184 CFG_SEC((char *) "iconbox", widget_iconbox_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
185 CFG_SEC((char *) "focusicon", widget_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
186 CFG_SEC((char *) "progressbar", widget_progressbar_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
187 CFG_SEC((char *) "graph", widget_graph_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
188 CFG_SEC((char *) "tasklist", widget_tasklist_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
189 CFG_AWESOME_END()
191 cfg_opt_t tag_opts[] =
193 CFG_STR((char *) "layout", (char *) "tile", CFGF_NONE),
194 CFG_FLOAT((char *) "mwfact", 0.5, CFGF_NONE),
195 CFG_INT((char *) "nmaster", 1, CFGF_NONE),
196 CFG_INT((char *) "ncol", 1, CFGF_NONE),
197 CFG_AWESOME_END()
199 cfg_opt_t tags_opts[] =
201 CFG_SEC((char *) "tag", tag_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
202 CFG_AWESOME_END()
204 cfg_opt_t layout_opts[] =
206 CFG_STR((char *) "image", NULL, CFGF_NONE),
207 CFG_AWESOME_END()
209 cfg_opt_t layouts_opts[] =
211 CFG_SEC((char *) "layout", layout_opts, CFGF_TITLE | CFGF_MULTI),
212 CFG_AWESOME_END()
214 cfg_opt_t padding_opts[] =
216 CFG_INT((char *) "top", 0, CFGF_NONE),
217 CFG_INT((char *) "bottom", 0, CFGF_NONE),
218 CFG_INT((char *) "right", 0, CFGF_NONE),
219 CFG_INT((char *) "left", 0, CFGF_NONE),
220 CFG_AWESOME_END()
222 cfg_opt_t screen_opts[] =
224 CFG_SEC((char *) "general", general_opts, CFGF_NONE),
225 CFG_SEC((char *) "statusbar", statusbar_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
226 CFG_SEC((char *) "tags", tags_opts, CFGF_NONE),
227 CFG_SEC((char *) "colors", colors_opts, CFGF_NONE),
228 CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE),
229 CFG_SEC((char *) "padding", padding_opts, CFGF_NONE),
230 CFG_AWESOME_END()
232 cfg_opt_t rule_opts[] =
234 CFG_STR((char *) "xproperty_name", NULL, CFGF_NONE),
235 CFG_STR((char *) "xproperty_value", NULL, CFGF_NONE),
236 CFG_STR((char *) "name", NULL, CFGF_NONE),
237 CFG_STR((char *) "tags", NULL, CFGF_NONE),
238 CFG_STR((char *) "icon", NULL, CFGF_NONE),
239 CFG_STR((char *) "float", (char *) "auto", CFGF_NONE),
240 CFG_STR((char *) "master", (char *) "auto", CFGF_NONE),
241 CFG_INT((char *) "screen", RULE_NOSCREEN, CFGF_NONE),
242 CFG_FLOAT((char *) "opacity", -1.0f, CFGF_NONE),
243 CFG_AWESOME_END()
245 cfg_opt_t rules_opts[] =
247 CFG_SEC((char *) "rule", rule_opts, CFGF_MULTI),
248 CFG_AWESOME_END()
250 cfg_opt_t key_opts[] =
252 CFG_STR_LIST((char *) "modkey", (char *) "", CFGF_NONE),
253 CFG_STR((char *) "key", (char *) "None", CFGF_NONE),
254 CFG_STR((char *) "command", (char *) "", CFGF_NONE),
255 CFG_STR((char *) "arg", NULL, CFGF_NONE),
256 CFG_AWESOME_END()
258 cfg_opt_t keylist_opts[] =
260 CFG_STR_LIST((char *) "modkey", (char *) "", CFGF_NONE),
261 CFG_STR_LIST((char *) "keylist", (char *) NULL, CFGF_NONE),
262 CFG_STR((char *) "command", (char *) "", CFGF_NONE),
263 CFG_STR_LIST((char *) "arglist", NULL, CFGF_NONE),
264 CFG_AWESOME_END()
266 cfg_opt_t keys_opts[] =
268 CFG_SEC((char *) "key", key_opts, CFGF_MULTI),
269 CFG_SEC((char *) "keylist", keylist_opts, CFGF_MULTI),
270 CFG_AWESOME_END()
272 cfg_opt_t mouse_opts[] =
274 CFG_SEC((char *) "root", mouse_generic_opts, CFGF_MULTI),
275 CFG_SEC((char *) "client", mouse_generic_opts, CFGF_MULTI),
276 CFG_AWESOME_END()
278 cfg_opt_t awesome_opts[] =
280 CFG_SEC((char *) "screen", screen_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
281 CFG_SEC((char *) "rules", rules_opts, CFGF_NONE),
282 CFG_SEC((char *) "keys", keys_opts, CFGF_NONE),
283 CFG_SEC((char *) "mouse", mouse_opts, CFGF_NONE),
284 CFG_AWESOME_END()
287 /** Return default configuration file path
288 * \return path to the default configuration file
290 char *
291 config_file(void)
293 const char *homedir;
294 char * confpath;
295 ssize_t confpath_len;
297 homedir = getenv("HOME");
298 confpath_len = a_strlen(homedir) + a_strlen(AWESOME_CONFIG_FILE) + 2;
299 confpath = p_new(char, confpath_len);
300 a_strcpy(confpath, confpath_len, homedir);
301 a_strcat(confpath, confpath_len, "/");
302 a_strcat(confpath, confpath_len, AWESOME_CONFIG_FILE);
304 return confpath;
307 /** Check configuration file syntax in regard of libconfuse parsing
308 * \param path to config file
309 * \return status returned by cfg_parse()
312 config_check(const char *confpatharg)
314 cfg_t *cfg;
315 int ret;
316 char *confpath;
318 cfg = cfg_init(awesome_opts, CFGF_NONE);
320 if(confpatharg)
321 confpath = a_strdup(confpatharg);
322 else
323 confpath = config_file();
325 switch((ret = cfg_parse(cfg, confpath)))
327 case CFG_FILE_ERROR:
328 perror("awesome: parsing configuration file failed");
329 break;
330 case CFG_PARSE_ERROR:
331 cfg_error(cfg, "awesome: parsing configuration file %s failed.\n", confpath);
332 break;
333 case CFG_SUCCESS:
334 printf("Configuration file OK.\n");
335 break;
338 p_delete(&confpath);
340 return ret;
343 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80