2 * config.c - configuration management
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.
23 * @defgroup ui_callback User Interface Callbacks
26 #include <X11/keysym.h>
28 #include "statusbar.h"
36 #include "defconfig.h"
37 #include "layouts/tile.h"
39 #define AWESOME_CONFIG_FILE ".awesomerc"
41 /* Permit to use mouse with many more buttons */
49 extern AwesomeConf globalconf
;
51 /** Link a name to a key symbol */
58 /** Link a name to a mouse button symbol */
65 extern const name_func_link_t UicbList
[];
66 extern const name_func_link_t WidgetList
[];
67 extern const name_func_link_t LayoutList
[];
69 /** Lookup for a key mask from its name
70 * \param keyname Key name
71 * \return Key mask or 0 if not found
74 key_mask_lookup(const char *keyname
)
76 /** List of keyname and corresponding X11 mask codes */
77 static const KeyMod KeyModList
[] =
81 {"Control", ControlMask
},
92 for(i
= 0; KeyModList
[i
].name
; i
++)
93 if(!a_strcmp(keyname
, KeyModList
[i
].name
))
94 return KeyModList
[i
].keysym
;
99 /** Lookup for a mouse button from its name
100 * \param button Mouse button name
101 * \return Mouse button or 0 if not found
104 mouse_button_lookup(const char *button
)
106 /** List of button name and corresponding X11 mask codes */
107 static const MouseButton MouseButtonList
[] =
121 for(i
= 0; MouseButtonList
[i
].name
; i
++)
122 if(!a_strcmp(button
, MouseButtonList
[i
].name
))
123 return MouseButtonList
[i
].button
;
129 parse_mouse_bindings(cfg_t
* cfg
, const char *secname
, Bool handle_arg
)
133 Button
*b
= NULL
, *head
= NULL
;
135 /* Mouse: layout click bindings */
136 for(i
= cfg_size(cfg
, secname
) - 1; i
>= 0; i
--)
138 b
= p_new(Button
, 1);
140 cfgsectmp
= cfg_getnsec(cfg
, secname
, i
);
141 for(j
= cfg_size(cfgsectmp
, "modkey") - 1; j
>= 0; j
--)
142 b
->mod
|= key_mask_lookup(cfg_getnstr(cfgsectmp
, "modkey", j
));
143 b
->button
= mouse_button_lookup(cfg_getstr(cfgsectmp
, "button"));
144 b
->func
= name_func_lookup(cfg_getstr(cfgsectmp
, "command"), UicbList
);
146 warn("unknown command %s\n", cfg_getstr(cfgsectmp
, "command"));
148 b
->arg
= a_strdup(cfg_getstr(cfgsectmp
, "arg"));
152 button_list_push(&head
, b
);
160 set_key_info(Key
*key
, cfg_t
*cfg
)
164 for(j
= 0; j
< cfg_size(cfg
, "modkey"); j
++)
165 key
->mod
|= key_mask_lookup(cfg_getnstr(cfg
, "modkey", j
));
166 key
->func
= name_func_lookup(cfg_getstr(cfg
, "command"), UicbList
);
168 warn("unknown command %s\n", cfg_getstr(cfg
, "command"));
173 section_keys(cfg_t
*cfg_keys
)
175 Key
*key
= NULL
, *head
= NULL
;
179 for(i
= cfg_size(cfg_keys
, "key") - 1; i
>= 0; i
--)
182 cfgkeytmp
= cfg_getnsec(cfg_keys
, "key", i
);
183 set_key_info(key
, cfgkeytmp
);
184 key
->keysym
= XStringToKeysym(cfg_getstr(cfgkeytmp
, "key"));
185 key
->arg
= a_strdup(cfg_getstr(cfgkeytmp
, "arg"));
186 key_list_push(&head
, key
);
189 for(i
= cfg_size(cfg_keys
, "keylist") - 1; i
>= 0; i
--)
191 cfgkeytmp
= cfg_getnsec(cfg_keys
, "keylist", i
);
192 numkeys
= cfg_size(cfgkeytmp
, "keylist");
193 if(numkeys
!= (int) cfg_size(cfgkeytmp
, "arglist"))
195 warn("number of keys != number of args in keylist");
199 for(j
= 0; j
< numkeys
; j
++)
202 set_key_info(key
, cfgkeytmp
);
203 key
->keysym
= XStringToKeysym(cfg_getnstr(cfgkeytmp
, "keylist", j
));
204 key
->arg
= a_strdup(cfg_getnstr(cfgkeytmp
, "arglist", j
));
205 key_list_push(&head
, key
);
214 cmp_widget_cfg(const void *a
, const void *b
)
216 if (((cfg_t
*)a
)->line
< ((cfg_t
*)b
)->line
)
219 if (((cfg_t
*)a
)->line
> ((cfg_t
*)b
)->line
)
226 create_widgets(cfg_t
* cfg_statusbar
, Statusbar
*statusbar
)
228 cfg_t
* widgets
, *wptr
;
229 Widget
*widget
= NULL
;
230 unsigned int i
, j
, numwidgets
= 0;
231 WidgetConstructor
*widget_new
;
233 for(i
= 0; WidgetList
[i
].name
; i
++)
234 numwidgets
+= cfg_size(cfg_statusbar
, WidgetList
[i
].name
);
236 widgets
= p_new(cfg_t
, numwidgets
);
239 for(i
= 0; WidgetList
[i
].name
; i
++)
240 for (j
= 0; j
< cfg_size(cfg_statusbar
, WidgetList
[i
].name
); j
++)
243 cfg_getnsec(cfg_statusbar
, WidgetList
[i
].name
, j
),
248 qsort(widgets
, numwidgets
, sizeof(cfg_t
), cmp_widget_cfg
);
250 for(i
= 0; i
< numwidgets
; i
++)
253 widget_new
= name_func_lookup(cfg_name(wptr
), WidgetList
);
256 widget
= widget_new(statusbar
, wptr
);
257 widget_list_append(&statusbar
->widgets
, widget
);
258 widget
->buttons
= parse_mouse_bindings(wptr
, "mouse", a_strcmp(cfg_name(wptr
), "taglist"));
261 warn("Ignoring unknown widget: %s.\n", cfg_name(widgets
+ i
));
266 config_parse_screen(cfg_t
*cfg
, int screen
)
270 Layout
*layout
= NULL
;
272 Statusbar
*statusbar
= NULL
;
273 cfg_t
*cfg_general
, *cfg_colors
, *cfg_screen
, *cfg_tags
,
274 *cfg_layouts
, *cfg_padding
, *cfgsectmp
;
275 VirtScreen
*virtscreen
= &globalconf
.screens
[screen
];
276 int i
, phys_screen
= get_phys_screen(screen
);
278 snprintf(buf
, sizeof(buf
), "%d", screen
);
279 cfg_screen
= cfg_gettsec(cfg
, "screen", buf
);
281 cfg_screen
= cfg_getsec(cfg
, "screen");
285 warn("parsing configuration file failed, no screen section found\n");
286 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
287 cfg_screen
= cfg_getsec(cfg
, "screen");
290 /* get screen specific sections */
291 cfg_tags
= cfg_getsec(cfg_screen
, "tags");
292 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
293 cfg_general
= cfg_getsec(cfg_screen
, "general");
294 cfg_layouts
= cfg_getsec(cfg_screen
, "layouts");
295 cfg_padding
= cfg_getsec(cfg_screen
, "padding");
298 /* General section */
299 virtscreen
->borderpx
= cfg_getint(cfg_general
, "border");
300 virtscreen
->snap
= cfg_getint(cfg_general
, "snap");
301 virtscreen
->resize_hints
= cfg_getbool(cfg_general
, "resize_hints");
302 virtscreen
->opacity_unfocused
= cfg_getint(cfg_general
, "opacity_unfocused");
303 virtscreen
->focus_move_pointer
= cfg_getbool(cfg_general
, "focus_move_pointer");
304 virtscreen
->allow_lower_floats
= cfg_getbool(cfg_general
, "allow_lower_floats");
305 virtscreen
->sloppy_focus
= cfg_getbool(cfg_general
, "sloppy_focus");
306 virtscreen
->new_become_master
= cfg_getbool(cfg_general
, "new_become_master");
307 virtscreen
->new_get_focus
= cfg_getbool(cfg_general
, "new_get_focus");
308 virtscreen
->font
= XftFontOpenName(globalconf
.display
,
310 cfg_getstr(cfg_general
, "font"));
311 if(!virtscreen
->font
)
312 eprint("awesome: cannot init font\n");
315 virtscreen
->colors_normal
[ColBorder
] = initxcolor(globalconf
.display
, phys_screen
,
316 cfg_getstr(cfg_colors
, "normal_border"));
317 virtscreen
->colors_normal
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
318 cfg_getstr(cfg_colors
, "normal_bg"));
319 virtscreen
->colors_normal
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
320 cfg_getstr(cfg_colors
, "normal_fg"));
321 virtscreen
->colors_selected
[ColBorder
] = initxcolor(globalconf
.display
, phys_screen
,
322 cfg_getstr(cfg_colors
, "focus_border"));
323 virtscreen
->colors_selected
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
324 cfg_getstr(cfg_colors
, "focus_bg"));
325 virtscreen
->colors_selected
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
326 cfg_getstr(cfg_colors
, "focus_fg"));
327 virtscreen
->colors_urgent
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
328 cfg_getstr(cfg_colors
, "urgent_bg"));
329 virtscreen
->colors_urgent
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
330 cfg_getstr(cfg_colors
, "urgent_fg"));
334 statusbar_list_init(&virtscreen
->statusbar
);
335 for(i
= cfg_size(cfg_screen
, "statusbar") - 1; i
>= 0; i
--)
337 statusbar
= p_new(Statusbar
, 1);
338 cfgsectmp
= cfg_getnsec(cfg_screen
, "statusbar", i
);
339 statusbar
->position
= statusbar
->dposition
=
340 statusbar_get_position_from_str(cfg_getstr(cfgsectmp
, "position"));
341 statusbar
->height
= cfg_getint(cfgsectmp
, "height");
342 statusbar
->width
= cfg_getint(cfgsectmp
, "width");
343 statusbar
->name
= a_strdup(cfg_title(cfgsectmp
));
344 statusbar
->screen
= screen
;
345 create_widgets(cfgsectmp
, statusbar
);
346 statusbar_preinit(statusbar
);
347 statusbar_list_push(&virtscreen
->statusbar
, statusbar
);
351 layout_list_init(&virtscreen
->layouts
);
352 if((i
= cfg_size(cfg_layouts
, "layout")))
353 for(--i
; i
>= 0; i
--)
355 layout
= p_new(Layout
, 1);
356 cfgsectmp
= cfg_getnsec(cfg_layouts
, "layout", i
);
357 layout
->arrange
= name_func_lookup(cfg_title(cfgsectmp
), LayoutList
);
360 warn("unknown layout %s in configuration file\n", cfg_title(cfgsectmp
));
361 layout
->image
= NULL
;
364 layout
->image
= a_strdup(cfg_getstr(cfgsectmp
, "image"));
366 layout_list_push(&virtscreen
->layouts
, layout
);
370 warn("no default layout available\n");
371 layout
->arrange
= layout_tile
;
375 tag_list_init(&virtscreen
->tags
);
376 if((i
= cfg_size(cfg_tags
, "tag")))
377 for(--i
; i
>= 0; i
--)
379 cfgsectmp
= cfg_getnsec(cfg_tags
, "tag", i
);
381 tmp
= cfg_getstr(cfgsectmp
, "layout");
382 for(layout
= virtscreen
->layouts
;
383 layout
&& layout
->arrange
!= name_func_lookup(tmp
, LayoutList
);
384 layout
= layout
->next
);
386 layout
= virtscreen
->layouts
;
388 tag
= tag_new(cfg_title(cfgsectmp
),
390 cfg_getfloat(cfgsectmp
, "mwfact"),
391 cfg_getint(cfgsectmp
, "nmaster"),
392 cfg_getint(cfgsectmp
, "ncol"));
394 tag_push_to_screen(tag
, screen
);
398 warn("fatal: no tags found in configuration file\n");
399 tag
->name
= a_strdup("default");
400 tag
->layout
= virtscreen
->layouts
;
406 ewmh_update_net_numbers_of_desktop(phys_screen
);
407 ewmh_update_net_current_desktop(phys_screen
);
408 ewmh_update_net_desktop_names(phys_screen
);
410 /* select first tag by default */
411 virtscreen
->tags
[0].selected
= True
;
412 virtscreen
->tags
[0].was_selected
= True
;
415 virtscreen
->padding
.top
= cfg_getint(cfg_padding
, "top");
416 virtscreen
->padding
.bottom
= cfg_getint(cfg_padding
, "bottom");
417 virtscreen
->padding
.left
= cfg_getint(cfg_padding
, "left");
418 virtscreen
->padding
.right
= cfg_getint(cfg_padding
, "right");
421 /** Parse configuration file and initialize some stuff
422 * \param confpatharg Path to configuration file
425 config_parse(const char *confpatharg
)
427 static cfg_opt_t general_opts
[] =
429 CFG_INT((char *) "border", 1, CFGF_NONE
),
430 CFG_INT((char *) "snap", 8, CFGF_NONE
),
431 CFG_BOOL((char *) "resize_hints", cfg_true
, CFGF_NONE
),
432 CFG_INT((char *) "opacity_unfocused", 100, CFGF_NONE
),
433 CFG_BOOL((char *) "focus_move_pointer", cfg_false
, CFGF_NONE
),
434 CFG_BOOL((char *) "allow_lower_floats", cfg_false
, CFGF_NONE
),
435 CFG_BOOL((char *) "sloppy_focus", cfg_true
, CFGF_NONE
),
436 CFG_BOOL((char *) "new_become_master", cfg_true
, CFGF_NONE
),
437 CFG_BOOL((char *) "new_get_focus", cfg_true
, CFGF_NONE
),
438 CFG_STR((char *) "font", (char *) "mono-12", CFGF_NONE
),
441 static cfg_opt_t colors_opts
[] =
443 CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE
),
444 CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE
),
445 CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE
),
446 CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE
),
447 CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE
),
448 CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE
),
449 CFG_STR((char *) "urgent_bg", (char *) "#ff0000", CFGF_NONE
),
450 CFG_STR((char *) "urgent_fg", (char *) "#ffffff", CFGF_NONE
),
451 CFG_STR((char *) "tab_border", (char *) "#ff0000", CFGF_NONE
),
454 static cfg_opt_t mouse_taglist_opts
[] =
456 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
457 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
458 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
461 static cfg_opt_t mouse_generic_opts
[] =
463 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
464 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
465 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
466 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
469 static cfg_opt_t widget_opts
[] =
471 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
472 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
473 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
476 static cfg_opt_t widget_taglist_opts
[] =
478 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
479 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
480 CFG_SEC((char *) "mouse", mouse_taglist_opts
, CFGF_MULTI
),
483 static cfg_opt_t widget_iconbox_opts
[] =
485 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
486 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
487 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
488 CFG_STR((char *) "image", (char *) NULL
, CFGF_NONE
),
489 CFG_BOOL((char *) "resize", cfg_true
, CFGF_NONE
),
492 static cfg_opt_t widget_textbox_opts
[] =
494 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
495 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
496 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
497 CFG_INT((char *) "width", 0, CFGF_NONE
),
498 CFG_STR((char *) "text", (char *) NULL
, CFGF_NONE
),
499 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
500 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
501 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
502 CFG_STR((char *) "align", (char *) "center", CFGF_NONE
),
505 static cfg_opt_t widget_focustitle_opts
[] =
507 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
508 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
509 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
510 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
511 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
512 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
513 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
516 static cfg_opt_t widget_tasklist_opts
[] =
518 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
519 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
520 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
521 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
522 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
523 CFG_STR((char *) "focus_fg", (char *) NULL
, CFGF_NONE
),
524 CFG_STR((char *) "focus_bg", (char *) NULL
, CFGF_NONE
),
525 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
526 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
527 CFG_BOOL((char *) "show_icons", cfg_true
, CFGF_NONE
),
528 CFG_BOOL((char *) "show_all", cfg_false
, CFGF_NONE
),
531 static cfg_opt_t widget_graph_opts
[] =
533 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
534 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
535 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
536 CFG_INT((char *) "width", 100, CFGF_NONE
),
537 CFG_INT((char *) "padding_left", 0, CFGF_NONE
),
538 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
539 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
540 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
541 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
542 CFG_BOOL((char *) "scale", cfg_false
, CFGF_NONE
),
543 CFG_FLOAT((char *) "max", 100.0f
, CFGF_NONE
),
546 static cfg_opt_t widget_progressbar_bar_opts
[] =
548 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
549 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
550 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
553 static cfg_opt_t widget_progressbar_opts
[] =
555 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
556 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
557 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
558 CFG_SEC((char *) "bar", widget_progressbar_bar_opts
, CFGF_MULTI
),
559 CFG_INT((char *) "width", 100, CFGF_NONE
),
560 CFG_INT((char *) "gap", 2, CFGF_NONE
),
561 CFG_INT((char *) "padding_left", 0, CFGF_NONE
),
562 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
565 static cfg_opt_t statusbar_opts
[] =
567 CFG_STR((char *) "position", (char *) "top", CFGF_NONE
),
568 CFG_INT((char *) "height", 0, CFGF_NONE
),
569 CFG_INT((char *) "width", 0, CFGF_NONE
),
570 CFG_SEC((char *) "textbox", widget_textbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
571 CFG_SEC((char *) "taglist", widget_taglist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
572 CFG_SEC((char *) "focustitle", widget_focustitle_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
573 CFG_SEC((char *) "layoutinfo", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
574 CFG_SEC((char *) "iconbox", widget_iconbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
575 CFG_SEC((char *) "netwmicon", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
576 CFG_SEC((char *) "progressbar", widget_progressbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
577 CFG_SEC((char *) "graph", widget_graph_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
578 CFG_SEC((char *) "tasklist", widget_tasklist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
581 static cfg_opt_t tag_opts
[] =
583 CFG_STR((char *) "layout", (char *) "tile", CFGF_NONE
),
584 CFG_FLOAT((char *) "mwfact", 0.5, CFGF_NONE
),
585 CFG_INT((char *) "nmaster", 1, CFGF_NONE
),
586 CFG_INT((char *) "ncol", 1, CFGF_NONE
),
589 static cfg_opt_t tags_opts
[] =
591 CFG_SEC((char *) "tag", tag_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
594 static cfg_opt_t layout_opts
[] =
596 CFG_STR((char *) "image", NULL
, CFGF_NONE
),
599 static cfg_opt_t layouts_opts
[] =
601 CFG_SEC((char *) "layout", layout_opts
, CFGF_TITLE
| CFGF_MULTI
),
604 static cfg_opt_t padding_opts
[] =
606 CFG_INT((char *) "top", 0, CFGF_NONE
),
607 CFG_INT((char *) "bottom", 0, CFGF_NONE
),
608 CFG_INT((char *) "right", 0, CFGF_NONE
),
609 CFG_INT((char *) "left", 0, CFGF_NONE
),
612 static cfg_opt_t screen_opts
[] =
614 CFG_SEC((char *) "general", general_opts
, CFGF_NONE
),
615 CFG_SEC((char *) "statusbar", statusbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
616 CFG_SEC((char *) "tags", tags_opts
, CFGF_NONE
),
617 CFG_SEC((char *) "colors", colors_opts
, CFGF_NONE
),
618 CFG_SEC((char *) "layouts", layouts_opts
, CFGF_NONE
),
619 CFG_SEC((char *) "padding", padding_opts
, CFGF_NONE
),
622 static cfg_opt_t rule_opts
[] =
624 CFG_STR((char *) "xproperty_name", NULL
, CFGF_NONE
),
625 CFG_STR((char *) "xproperty_value", NULL
, CFGF_NONE
),
626 CFG_STR((char *) "name", NULL
, CFGF_NONE
),
627 CFG_STR((char *) "tags", NULL
, CFGF_NONE
),
628 CFG_STR((char *) "icon", NULL
, CFGF_NONE
),
629 CFG_STR((char *) "float", (char *) "auto", CFGF_NONE
),
630 CFG_INT((char *) "screen", RULE_NOSCREEN
, CFGF_NONE
),
631 CFG_BOOL((char *) "not_master", cfg_false
, CFGF_NONE
),
634 static cfg_opt_t rules_opts
[] =
636 CFG_SEC((char *) "rule", rule_opts
, CFGF_MULTI
),
639 static cfg_opt_t key_opts
[] =
641 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
642 CFG_STR((char *) "key", (char *) "None", CFGF_NONE
),
643 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
644 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
647 static cfg_opt_t keylist_opts
[] =
649 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
650 CFG_STR_LIST((char *) "keylist", (char *) NULL
, CFGF_NONE
),
651 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
652 CFG_STR_LIST((char *) "arglist", NULL
, CFGF_NONE
),
655 static cfg_opt_t keys_opts
[] =
657 CFG_SEC((char *) "key", key_opts
, CFGF_MULTI
),
658 CFG_SEC((char *) "keylist", keylist_opts
, CFGF_MULTI
),
661 static cfg_opt_t mouse_opts
[] =
663 CFG_SEC((char *) "root", mouse_generic_opts
, CFGF_MULTI
),
664 CFG_SEC((char *) "client", mouse_generic_opts
, CFGF_MULTI
),
667 static cfg_opt_t opts
[] =
669 CFG_SEC((char *) "screen", screen_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
670 CFG_SEC((char *) "rules", rules_opts
, CFGF_NONE
),
671 CFG_SEC((char *) "keys", keys_opts
, CFGF_NONE
),
672 CFG_SEC((char *) "mouse", mouse_opts
, CFGF_NONE
),
675 cfg_t
*cfg
, *cfg_rules
, *cfg_keys
, *cfg_mouse
, *cfgsectmp
;
679 ssize_t confpath_len
;
681 FILE *defconfig
= NULL
;
684 confpath
= a_strdup(confpatharg
);
687 homedir
= getenv("HOME");
688 confpath_len
= a_strlen(homedir
) + a_strlen(AWESOME_CONFIG_FILE
) + 2;
689 confpath
= p_new(char, confpath_len
);
690 a_strcpy(confpath
, confpath_len
, homedir
);
691 a_strcat(confpath
, confpath_len
, "/");
692 a_strcat(confpath
, confpath_len
, AWESOME_CONFIG_FILE
);
695 globalconf
.configpath
= a_strdup(confpath
);
697 cfg
= cfg_init(opts
, CFGF_NONE
);
699 ret
= cfg_parse(cfg
, confpath
);
700 if(ret
== CFG_FILE_ERROR
)
702 perror("awesome: parsing configuration file failed");
703 if(!(defconfig
= fopen(confpath
, "w")))
704 perror("awesome: unable to create default configuration file");
706 else if(ret
== CFG_PARSE_ERROR
)
707 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
708 if(ret
!= CFG_SUCCESS
) {
709 fprintf(stderr
, "Using default compile-time configuration\n");
711 cfg
= cfg_init(opts
, CFGF_NONE
);
712 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
715 /* get the right screen section */
716 for(screen
= 0; screen
< globalconf
.nscreens
; screen
++)
717 config_parse_screen(cfg
, screen
);
719 /* get general sections */
720 cfg_rules
= cfg_getsec(cfg
, "rules");
721 cfg_keys
= cfg_getsec(cfg
, "keys");
722 cfg_mouse
= cfg_getsec(cfg
, "mouse");
725 rule_list_init(&globalconf
.rules
);
726 for(i
= cfg_size(cfg_rules
, "rule") - 1; i
>= 0; i
--)
728 rule
= p_new(Rule
, 1);
729 cfgsectmp
= cfg_getnsec(cfg_rules
, "rule", i
);
730 rule
->prop_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "name"));
731 rule
->tags_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "tags"));
732 rule
->xprop
= a_strdup(cfg_getstr(cfgsectmp
, "xproperty_name"));
733 rule
->xpropval_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "xproperty_value"));
734 rule
->icon
= a_strdup(cfg_getstr(cfgsectmp
, "icon"));
735 rule
->isfloating
= rules_get_float_from_str(cfg_getstr(cfgsectmp
, "float"));
736 rule
->screen
= cfg_getint(cfgsectmp
, "screen");
737 rule
->not_master
= cfg_getbool(cfgsectmp
, "not_master");
738 if(rule
->screen
>= globalconf
.nscreens
)
741 rule_list_push(&globalconf
.rules
, rule
);
744 /* Mouse: root window click bindings */
745 globalconf
.buttons
.root
= parse_mouse_bindings(cfg_mouse
, "root", True
);
747 /* Mouse: client windows click bindings */
748 globalconf
.buttons
.client
= parse_mouse_bindings(cfg_mouse
, "client", True
);
751 globalconf
.numlockmask
= get_numlockmask(globalconf
.display
);
753 globalconf
.keys
= section_keys(cfg_keys
);
757 cfg_print(cfg
, defconfig
);
761 /* Free! Like a river! */
766 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80