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"
35 #include "defconfig.h"
36 #include "layouts/tile.h"
37 #include "common/util.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"));
172 key_to_keysym(char *str
)
177 if(a_strncmp(str
, "#", 1))
178 return XStringToKeysym(str
);
181 memcpy(&kc
, &ikc
, sizeof(KeyCode
));
182 return XKeycodeToKeysym(globalconf
.display
, kc
, 0);
186 section_keys(cfg_t
*cfg_keys
)
188 Key
*key
= NULL
, *head
= NULL
;
192 for(i
= cfg_size(cfg_keys
, "key") - 1; i
>= 0; i
--)
195 cfgkeytmp
= cfg_getnsec(cfg_keys
, "key", i
);
196 set_key_info(key
, cfgkeytmp
);
197 key
->keysym
= key_to_keysym(cfg_getstr(cfgkeytmp
, "key"));
198 key
->arg
= a_strdup(cfg_getstr(cfgkeytmp
, "arg"));
199 key_list_push(&head
, key
);
202 for(i
= cfg_size(cfg_keys
, "keylist") - 1; i
>= 0; i
--)
204 cfgkeytmp
= cfg_getnsec(cfg_keys
, "keylist", i
);
205 numkeys
= cfg_size(cfgkeytmp
, "keylist");
206 if(numkeys
!= (int) cfg_size(cfgkeytmp
, "arglist"))
208 warn("number of keys != number of args in keylist");
212 for(j
= 0; j
< numkeys
; j
++)
215 set_key_info(key
, cfgkeytmp
);
216 key
->keysym
= key_to_keysym(cfg_getnstr(cfgkeytmp
, "keylist", j
));
217 key
->arg
= a_strdup(cfg_getnstr(cfgkeytmp
, "arglist", j
));
218 key_list_push(&head
, key
);
227 cmp_widget_cfg(const void *a
, const void *b
)
229 if (((cfg_t
*)a
)->line
< ((cfg_t
*)b
)->line
)
232 if (((cfg_t
*)a
)->line
> ((cfg_t
*)b
)->line
)
239 create_widgets(cfg_t
* cfg_statusbar
, Statusbar
*statusbar
)
241 cfg_t
* widgets
, *wptr
;
242 Widget
*widget
= NULL
;
243 unsigned int i
, j
, numwidgets
= 0;
244 WidgetConstructor
*widget_new
;
246 for(i
= 0; WidgetList
[i
].name
; i
++)
247 numwidgets
+= cfg_size(cfg_statusbar
, WidgetList
[i
].name
);
249 widgets
= p_new(cfg_t
, numwidgets
);
252 for(i
= 0; WidgetList
[i
].name
; i
++)
253 for (j
= 0; j
< cfg_size(cfg_statusbar
, WidgetList
[i
].name
); j
++)
256 cfg_getnsec(cfg_statusbar
, WidgetList
[i
].name
, j
),
261 qsort(widgets
, numwidgets
, sizeof(cfg_t
), cmp_widget_cfg
);
263 for(i
= 0; i
< numwidgets
; i
++)
266 widget_new
= name_func_lookup(cfg_name(wptr
), WidgetList
);
269 widget
= widget_new(statusbar
, wptr
);
270 widget_list_append(&statusbar
->widgets
, widget
);
271 widget
->buttons
= parse_mouse_bindings(wptr
, "mouse", a_strcmp(cfg_name(wptr
), "taglist"));
274 warn("Ignoring unknown widget: %s.\n", cfg_name(widgets
+ i
));
279 config_parse_screen(cfg_t
*cfg
, int screen
)
283 Layout
*layout
= NULL
;
285 Statusbar
*statusbar
= NULL
;
286 cfg_t
*cfg_general
, *cfg_colors
, *cfg_screen
, *cfg_tags
,
287 *cfg_layouts
, *cfg_padding
, *cfgsectmp
;
288 VirtScreen
*virtscreen
= &globalconf
.screens
[screen
];
289 int i
, phys_screen
= get_phys_screen(screen
);
291 snprintf(buf
, sizeof(buf
), "%d", screen
);
292 cfg_screen
= cfg_gettsec(cfg
, "screen", buf
);
294 cfg_screen
= cfg_getsec(cfg
, "screen");
298 warn("parsing configuration file failed, no screen section found\n");
299 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
300 cfg_screen
= cfg_getsec(cfg
, "screen");
303 /* get screen specific sections */
304 cfg_tags
= cfg_getsec(cfg_screen
, "tags");
305 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
306 cfg_general
= cfg_getsec(cfg_screen
, "general");
307 cfg_layouts
= cfg_getsec(cfg_screen
, "layouts");
308 cfg_padding
= cfg_getsec(cfg_screen
, "padding");
311 /* General section */
312 virtscreen
->borderpx
= cfg_getint(cfg_general
, "border");
313 virtscreen
->snap
= cfg_getint(cfg_general
, "snap");
314 virtscreen
->resize_hints
= cfg_getbool(cfg_general
, "resize_hints");
315 virtscreen
->sloppy_focus
= cfg_getbool(cfg_general
, "sloppy_focus");
316 virtscreen
->sloppy_focus_raise
= cfg_getbool(cfg_general
, "sloppy_focus_raise");
317 virtscreen
->new_become_master
= cfg_getbool(cfg_general
, "new_become_master");
318 virtscreen
->new_get_focus
= cfg_getbool(cfg_general
, "new_get_focus");
319 virtscreen
->font
= XftFontOpenName(globalconf
.display
,
321 cfg_getstr(cfg_general
, "font"));
322 if(!virtscreen
->font
)
323 eprint("awesome: cannot init font\n");
326 virtscreen
->colors_normal
[ColBorder
] = initxcolor(globalconf
.display
, phys_screen
,
327 cfg_getstr(cfg_colors
, "normal_border"));
328 virtscreen
->colors_normal
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
329 cfg_getstr(cfg_colors
, "normal_bg"));
330 virtscreen
->colors_normal
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
331 cfg_getstr(cfg_colors
, "normal_fg"));
332 virtscreen
->colors_selected
[ColBorder
] = initxcolor(globalconf
.display
, phys_screen
,
333 cfg_getstr(cfg_colors
, "focus_border"));
334 virtscreen
->colors_selected
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
335 cfg_getstr(cfg_colors
, "focus_bg"));
336 virtscreen
->colors_selected
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
337 cfg_getstr(cfg_colors
, "focus_fg"));
338 virtscreen
->colors_urgent
[ColBG
] = initxcolor(globalconf
.display
, phys_screen
,
339 cfg_getstr(cfg_colors
, "urgent_bg"));
340 virtscreen
->colors_urgent
[ColFG
] = initxcolor(globalconf
.display
, phys_screen
,
341 cfg_getstr(cfg_colors
, "urgent_fg"));
345 statusbar_list_init(&virtscreen
->statusbar
);
346 for(i
= cfg_size(cfg_screen
, "statusbar") - 1; i
>= 0; i
--)
348 statusbar
= p_new(Statusbar
, 1);
349 cfgsectmp
= cfg_getnsec(cfg_screen
, "statusbar", i
);
350 statusbar
->position
= statusbar
->dposition
=
351 statusbar_get_position_from_str(cfg_getstr(cfgsectmp
, "position"));
352 statusbar
->height
= cfg_getint(cfgsectmp
, "height");
353 statusbar
->width
= cfg_getint(cfgsectmp
, "width");
354 statusbar
->name
= a_strdup(cfg_title(cfgsectmp
));
355 statusbar
->screen
= screen
;
356 statusbar_preinit(statusbar
);
357 create_widgets(cfgsectmp
, statusbar
);
358 statusbar_list_push(&virtscreen
->statusbar
, statusbar
);
362 layout_list_init(&virtscreen
->layouts
);
363 if((i
= cfg_size(cfg_layouts
, "layout")))
364 for(--i
; i
>= 0; i
--)
366 layout
= p_new(Layout
, 1);
367 cfgsectmp
= cfg_getnsec(cfg_layouts
, "layout", i
);
368 layout
->arrange
= name_func_lookup(cfg_title(cfgsectmp
), LayoutList
);
371 warn("unknown layout %s in configuration file\n", cfg_title(cfgsectmp
));
372 layout
->image
= NULL
;
375 layout
->image
= a_strdup(cfg_getstr(cfgsectmp
, "image"));
377 layout_list_push(&virtscreen
->layouts
, layout
);
381 warn("no default layout available\n");
382 layout
->arrange
= layout_tile
;
386 tag_list_init(&virtscreen
->tags
);
387 if((i
= cfg_size(cfg_tags
, "tag")))
388 for(--i
; i
>= 0; i
--)
390 cfgsectmp
= cfg_getnsec(cfg_tags
, "tag", i
);
392 tmp
= cfg_getstr(cfgsectmp
, "layout");
393 for(layout
= virtscreen
->layouts
;
394 layout
&& layout
->arrange
!= name_func_lookup(tmp
, LayoutList
);
395 layout
= layout
->next
);
397 layout
= virtscreen
->layouts
;
399 tag
= tag_new(cfg_title(cfgsectmp
),
401 cfg_getfloat(cfgsectmp
, "mwfact"),
402 cfg_getint(cfgsectmp
, "nmaster"),
403 cfg_getint(cfgsectmp
, "ncol"));
405 tag_push_to_screen(tag
, screen
);
409 warn("fatal: no tags found in configuration file\n");
410 tag
->name
= a_strdup("default");
411 tag
->layout
= virtscreen
->layouts
;
417 ewmh_update_net_numbers_of_desktop(phys_screen
);
418 ewmh_update_net_current_desktop(phys_screen
);
419 ewmh_update_net_desktop_names(phys_screen
);
421 /* select first tag by default */
422 virtscreen
->tags
[0].selected
= True
;
423 virtscreen
->tags
[0].was_selected
= True
;
426 virtscreen
->padding
.top
= cfg_getint(cfg_padding
, "top");
427 virtscreen
->padding
.bottom
= cfg_getint(cfg_padding
, "bottom");
428 virtscreen
->padding
.left
= cfg_getint(cfg_padding
, "left");
429 virtscreen
->padding
.right
= cfg_getint(cfg_padding
, "right");
432 /** Parse configuration file and initialize some stuff
433 * \param confpatharg Path to configuration file
436 config_parse(const char *confpatharg
)
438 static cfg_opt_t general_opts
[] =
440 CFG_INT((char *) "border", 1, CFGF_NONE
),
441 CFG_INT((char *) "snap", 8, CFGF_NONE
),
442 CFG_BOOL((char *) "resize_hints", cfg_true
, CFGF_NONE
),
443 CFG_BOOL((char *) "sloppy_focus", cfg_true
, CFGF_NONE
),
444 CFG_BOOL((char *) "sloppy_focus_raise", cfg_false
, CFGF_NONE
),
445 CFG_BOOL((char *) "new_become_master", cfg_true
, CFGF_NONE
),
446 CFG_BOOL((char *) "new_get_focus", cfg_true
, CFGF_NONE
),
447 CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE
),
450 static cfg_opt_t colors_opts
[] =
452 CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE
),
453 CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE
),
454 CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE
),
455 CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE
),
456 CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE
),
457 CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE
),
458 CFG_STR((char *) "urgent_bg", (char *) "#ff0000", CFGF_NONE
),
459 CFG_STR((char *) "urgent_fg", (char *) "#ffffff", CFGF_NONE
),
460 CFG_STR((char *) "tab_border", (char *) "#ff0000", CFGF_NONE
),
463 static cfg_opt_t mouse_taglist_opts
[] =
465 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
466 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
467 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
470 static cfg_opt_t mouse_generic_opts
[] =
472 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
473 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
474 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
475 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
478 static cfg_opt_t widget_opts
[] =
480 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
481 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
482 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
485 static cfg_opt_t widget_taglist_opts
[] =
487 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
488 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
489 CFG_SEC((char *) "mouse", mouse_taglist_opts
, CFGF_MULTI
),
492 static cfg_opt_t widget_iconbox_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_STR((char *) "image", (char *) NULL
, CFGF_NONE
),
498 CFG_BOOL((char *) "resize", cfg_true
, CFGF_NONE
),
501 static cfg_opt_t widget_textbox_opts
[] =
503 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
504 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
505 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
506 CFG_INT((char *) "width", 0, CFGF_NONE
),
507 CFG_STR((char *) "text", (char *) NULL
, CFGF_NONE
),
508 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
509 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
510 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
511 CFG_STR((char *) "align", (char *) "center", CFGF_NONE
),
514 static cfg_opt_t widget_focustitle_opts
[] =
516 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
517 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
518 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
519 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
520 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
521 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
522 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
525 static cfg_opt_t widget_tasklist_opts
[] =
527 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
528 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
529 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
530 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
531 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
532 CFG_STR((char *) "focus_fg", (char *) NULL
, CFGF_NONE
),
533 CFG_STR((char *) "focus_bg", (char *) NULL
, CFGF_NONE
),
534 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
535 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
536 CFG_BOOL((char *) "show_icons", cfg_true
, CFGF_NONE
),
537 CFG_BOOL((char *) "show_all", cfg_false
, CFGF_NONE
),
540 static cfg_opt_t widget_graph_data_opts
[] =
542 CFG_FLOAT((char *) "max", 100.0f
, CFGF_NONE
),
543 CFG_BOOL((char *) "scale", cfg_false
, CFGF_NONE
),
544 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
545 CFG_STR((char *) "style", (char *) "bottom", CFGF_NONE
),
548 static cfg_opt_t widget_graph_opts
[] =
550 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
551 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
552 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
553 CFG_SEC((char *) "data", widget_graph_data_opts
, CFGF_MULTI
),
554 CFG_INT((char *) "width", 100, CFGF_NONE
),
555 CFG_INT((char *) "padding_left", 0, CFGF_NONE
),
556 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
557 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
558 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
561 static cfg_opt_t widget_progressbar_bar_opts
[] =
563 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
564 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
565 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
568 static cfg_opt_t widget_progressbar_opts
[] =
570 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
571 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
572 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
573 CFG_SEC((char *) "bar", widget_progressbar_bar_opts
, CFGF_MULTI
),
574 CFG_INT((char *) "width", 100, CFGF_NONE
),
575 CFG_INT((char *) "gap", 2, CFGF_NONE
),
576 CFG_INT((char *) "padding_left", 0, CFGF_NONE
),
577 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
580 static cfg_opt_t statusbar_opts
[] =
582 CFG_STR((char *) "position", (char *) "top", CFGF_NONE
),
583 CFG_INT((char *) "height", 0, CFGF_NONE
),
584 CFG_INT((char *) "width", 0, CFGF_NONE
),
585 CFG_SEC((char *) "textbox", widget_textbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
586 CFG_SEC((char *) "taglist", widget_taglist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
587 CFG_SEC((char *) "focustitle", widget_focustitle_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
588 CFG_SEC((char *) "layoutinfo", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
589 CFG_SEC((char *) "iconbox", widget_iconbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
590 CFG_SEC((char *) "netwmicon", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
591 CFG_SEC((char *) "progressbar", widget_progressbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
592 CFG_SEC((char *) "graph", widget_graph_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
593 CFG_SEC((char *) "tasklist", widget_tasklist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
596 static cfg_opt_t tag_opts
[] =
598 CFG_STR((char *) "layout", (char *) "tile", CFGF_NONE
),
599 CFG_FLOAT((char *) "mwfact", 0.5, CFGF_NONE
),
600 CFG_INT((char *) "nmaster", 1, CFGF_NONE
),
601 CFG_INT((char *) "ncol", 1, CFGF_NONE
),
604 static cfg_opt_t tags_opts
[] =
606 CFG_SEC((char *) "tag", tag_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
609 static cfg_opt_t layout_opts
[] =
611 CFG_STR((char *) "image", NULL
, CFGF_NONE
),
614 static cfg_opt_t layouts_opts
[] =
616 CFG_SEC((char *) "layout", layout_opts
, CFGF_TITLE
| CFGF_MULTI
),
619 static cfg_opt_t padding_opts
[] =
621 CFG_INT((char *) "top", 0, CFGF_NONE
),
622 CFG_INT((char *) "bottom", 0, CFGF_NONE
),
623 CFG_INT((char *) "right", 0, CFGF_NONE
),
624 CFG_INT((char *) "left", 0, CFGF_NONE
),
627 static cfg_opt_t screen_opts
[] =
629 CFG_SEC((char *) "general", general_opts
, CFGF_NONE
),
630 CFG_SEC((char *) "statusbar", statusbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
631 CFG_SEC((char *) "tags", tags_opts
, CFGF_NONE
),
632 CFG_SEC((char *) "colors", colors_opts
, CFGF_NONE
),
633 CFG_SEC((char *) "layouts", layouts_opts
, CFGF_NONE
),
634 CFG_SEC((char *) "padding", padding_opts
, CFGF_NONE
),
637 static cfg_opt_t rule_opts
[] =
639 CFG_STR((char *) "xproperty_name", NULL
, CFGF_NONE
),
640 CFG_STR((char *) "xproperty_value", NULL
, CFGF_NONE
),
641 CFG_STR((char *) "name", NULL
, CFGF_NONE
),
642 CFG_STR((char *) "tags", NULL
, CFGF_NONE
),
643 CFG_STR((char *) "icon", NULL
, CFGF_NONE
),
644 CFG_STR((char *) "float", (char *) "auto", CFGF_NONE
),
645 CFG_INT((char *) "screen", RULE_NOSCREEN
, CFGF_NONE
),
646 CFG_BOOL((char *) "not_master", cfg_false
, CFGF_NONE
),
647 CFG_FLOAT((char *) "opacity", -1.0f
, CFGF_NONE
),
650 static cfg_opt_t rules_opts
[] =
652 CFG_SEC((char *) "rule", rule_opts
, CFGF_MULTI
),
655 static cfg_opt_t key_opts
[] =
657 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
658 CFG_STR((char *) "key", (char *) "None", CFGF_NONE
),
659 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
660 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
663 static cfg_opt_t keylist_opts
[] =
665 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
666 CFG_STR_LIST((char *) "keylist", (char *) NULL
, CFGF_NONE
),
667 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
668 CFG_STR_LIST((char *) "arglist", NULL
, CFGF_NONE
),
671 static cfg_opt_t keys_opts
[] =
673 CFG_SEC((char *) "key", key_opts
, CFGF_MULTI
),
674 CFG_SEC((char *) "keylist", keylist_opts
, CFGF_MULTI
),
677 static cfg_opt_t mouse_opts
[] =
679 CFG_SEC((char *) "root", mouse_generic_opts
, CFGF_MULTI
),
680 CFG_SEC((char *) "client", mouse_generic_opts
, CFGF_MULTI
),
683 static cfg_opt_t opts
[] =
685 CFG_SEC((char *) "screen", screen_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
686 CFG_SEC((char *) "rules", rules_opts
, CFGF_NONE
),
687 CFG_SEC((char *) "keys", keys_opts
, CFGF_NONE
),
688 CFG_SEC((char *) "mouse", mouse_opts
, CFGF_NONE
),
691 cfg_t
*cfg
, *cfg_rules
, *cfg_keys
, *cfg_mouse
, *cfgsectmp
;
695 ssize_t confpath_len
;
697 FILE *defconfig
= NULL
;
700 confpath
= a_strdup(confpatharg
);
703 homedir
= getenv("HOME");
704 confpath_len
= a_strlen(homedir
) + a_strlen(AWESOME_CONFIG_FILE
) + 2;
705 confpath
= p_new(char, confpath_len
);
706 a_strcpy(confpath
, confpath_len
, homedir
);
707 a_strcat(confpath
, confpath_len
, "/");
708 a_strcat(confpath
, confpath_len
, AWESOME_CONFIG_FILE
);
711 globalconf
.configpath
= a_strdup(confpath
);
713 cfg
= cfg_init(opts
, CFGF_NONE
);
715 ret
= cfg_parse(cfg
, confpath
);
720 perror("awesome: parsing configuration file failed");
721 if(!(defconfig
= fopen(confpath
, "w")))
722 perror("awesome: unable to create default configuration file");
724 case CFG_PARSE_ERROR
:
725 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
729 if(ret
!= CFG_SUCCESS
)
731 warn("using default compile-time configuration\n");
733 cfg
= cfg_init(opts
, CFGF_NONE
);
734 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
737 /* get the right screen section */
738 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
739 config_parse_screen(cfg
, screen
);
741 /* get general sections */
742 cfg_rules
= cfg_getsec(cfg
, "rules");
743 cfg_keys
= cfg_getsec(cfg
, "keys");
744 cfg_mouse
= cfg_getsec(cfg
, "mouse");
747 rule_list_init(&globalconf
.rules
);
748 for(i
= cfg_size(cfg_rules
, "rule") - 1; i
>= 0; i
--)
750 rule
= p_new(Rule
, 1);
751 cfgsectmp
= cfg_getnsec(cfg_rules
, "rule", i
);
752 rule
->prop_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "name"));
753 rule
->tags_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "tags"));
754 rule
->xprop
= a_strdup(cfg_getstr(cfgsectmp
, "xproperty_name"));
755 rule
->xpropval_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "xproperty_value"));
756 rule
->icon
= a_strdup(cfg_getstr(cfgsectmp
, "icon"));
757 rule
->isfloating
= rules_get_float_from_str(cfg_getstr(cfgsectmp
, "float"));
758 rule
->screen
= cfg_getint(cfgsectmp
, "screen");
759 rule
->not_master
= cfg_getbool(cfgsectmp
, "not_master");
760 rule
->opacity
= cfg_getfloat(cfgsectmp
, "opacity");
761 if(rule
->screen
>= globalconf
.nscreen
)
764 rule_list_push(&globalconf
.rules
, rule
);
767 /* Mouse: root window click bindings */
768 globalconf
.buttons
.root
= parse_mouse_bindings(cfg_mouse
, "root", True
);
770 /* Mouse: client windows click bindings */
771 globalconf
.buttons
.client
= parse_mouse_bindings(cfg_mouse
, "client", True
);
774 globalconf
.numlockmask
= get_numlockmask(globalconf
.display
);
776 globalconf
.keys
= section_keys(cfg_keys
);
780 cfg_print(cfg
, defconfig
);
784 /* Free! Like a river! */
789 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80