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"
38 #define AWESOME_CONFIG_FILE ".awesomerc"
40 extern AwesomeConf globalconf
;
42 /** Link a name to a key symbol */
49 /** Link a name to a mouse button symbol */
56 extern const NameFuncLink UicbList
[];
57 extern const NameFuncLink WidgetList
[];
58 extern const NameFuncLink LayoutsList
[];
62 get_numlockmask(Display
*disp
)
64 XModifierKeymap
*modmap
;
65 unsigned int mask
= 0;
68 modmap
= XGetModifierMapping(disp
);
69 for(i
= 0; i
< 8; i
++)
70 for(j
= 0; j
< modmap
->max_keypermod
; j
++)
71 if(modmap
->modifiermap
[i
* modmap
->max_keypermod
+ j
]
72 == XKeysymToKeycode(disp
, XK_Num_Lock
))
75 XFreeModifiermap(modmap
);
80 /** Lookup for a key mask from its name
81 * \param keyname Key name
82 * \return Key mask or 0 if not found
85 key_mask_lookup(const char *keyname
)
87 /** List of keyname and corresponding X11 mask codes */
88 static const KeyMod KeyModList
[] =
92 {"Control", ControlMask
},
103 for(i
= 0; KeyModList
[i
].name
; i
++)
104 if(!a_strcmp(keyname
, KeyModList
[i
].name
))
105 return KeyModList
[i
].keysym
;
110 /** Lookup for a mouse button from its name
111 * \param button Mouse button name
112 * \return Mouse button or 0 if not found
115 mouse_button_lookup(const char *button
)
117 /** List of button name and corresponding X11 mask codes */
118 static const MouseButton MouseButtonList
[] =
130 for(i
= 0; MouseButtonList
[i
].name
; i
++)
131 if(!a_strcmp(button
, MouseButtonList
[i
].name
))
132 return MouseButtonList
[i
].button
;
138 parse_mouse_bindings(cfg_t
* cfg
, const char *secname
, Bool handle_arg
)
142 Button
*b
= NULL
, *head
= NULL
;
144 /* Mouse: layout click bindings */
145 for(i
= 0; i
< cfg_size(cfg
, secname
); i
++)
147 /* init first elem */
149 head
= b
= p_new(Button
, 1);
151 cfgsectmp
= cfg_getnsec(cfg
, secname
, i
);
152 for(j
= 0; j
< cfg_size(cfgsectmp
, "modkey"); j
++)
153 b
->mod
|= key_mask_lookup(cfg_getnstr(cfgsectmp
, "modkey", j
));
154 b
->button
= mouse_button_lookup(cfg_getstr(cfgsectmp
, "button"));
155 b
->func
= name_func_lookup(cfg_getstr(cfgsectmp
, "command"), UicbList
);
157 warn("unknown command %s\n", cfg_getstr(cfgsectmp
, "command"));
159 b
->arg
= a_strdup(cfg_getstr(cfgsectmp
, "arg"));
163 /* switch to next elem or finalize the list */
164 if(i
< cfg_size(cfg
, secname
) - 1)
166 b
->next
= p_new(Button
, 1);
178 set_key_info(Key
*key
, cfg_t
*cfg
)
182 for(j
= 0; j
< cfg_size(cfg
, "modkey"); j
++)
183 key
->mod
|= key_mask_lookup(cfg_getnstr(cfg
, "modkey", j
));
184 key
->func
= name_func_lookup(cfg_getstr(cfg
, "command"), UicbList
);
186 warn("unknown command %s\n", cfg_getstr(cfg
, "command"));
191 section_keys(cfg_t
*cfg_keys
)
194 unsigned int i
, j
, numkeys
;
198 for(i
= 0; i
< cfg_size(cfg_keys
, "key"); i
++)
201 key
= head
= p_new(Key
, 1);
204 key
->next
= p_new(Key
, 1);
207 cfgkeytmp
= cfg_getnsec(cfg_keys
, "key", i
);
208 set_key_info(key
, cfgkeytmp
);
209 key
->keysym
= XStringToKeysym(cfg_getstr(cfgkeytmp
, "key"));
210 key
->arg
= a_strdup(cfg_getstr(cfgkeytmp
, "arg"));
213 for(i
= 0; i
< cfg_size(cfg_keys
, "keylist"); i
++)
215 cfgkeytmp
= cfg_getnsec(cfg_keys
, "keylist", i
);
216 numkeys
= cfg_size(cfgkeytmp
, "keylist");
217 if (numkeys
!= cfg_size(cfgkeytmp
, "arglist"))
219 warn("number of keys != number of args in keylist");
222 for(j
=0; j
< numkeys
; j
++)
231 key
->next
= p_new(Key
, 1);
234 set_key_info(key
, cfgkeytmp
);
235 key
->keysym
= XStringToKeysym(cfg_getnstr(cfgkeytmp
, "keylist", j
));
236 key
->arg
= a_strdup(cfg_getnstr(cfgkeytmp
, "arglist", j
));
239 key
->next
= p_new(Key
, 1);
251 cmp_widget_cfg(const void *a
, const void *b
)
253 if (((cfg_t
*)a
)->line
< ((cfg_t
*)b
)->line
)
256 if (((cfg_t
*)a
)->line
> ((cfg_t
*)b
)->line
)
263 create_widgets(cfg_t
* cfg_statusbar
, Statusbar
*statusbar
)
265 cfg_t
* widgets
, *wptr
;
266 Widget
*widget
= NULL
;
267 unsigned int i
, j
, numwidgets
= 0;
268 WidgetConstructor
*widget_new
;
270 for(i
= 0; WidgetList
[i
].name
; i
++)
271 numwidgets
+= cfg_size(cfg_statusbar
, WidgetList
[i
].name
);
273 widgets
= p_new(cfg_t
, numwidgets
);
276 for(i
= 0; WidgetList
[i
].name
; i
++)
277 for (j
= 0; j
< cfg_size(cfg_statusbar
, WidgetList
[i
].name
); j
++)
280 cfg_getnsec(cfg_statusbar
, WidgetList
[i
].name
, j
),
285 qsort(widgets
, numwidgets
, sizeof(cfg_t
), cmp_widget_cfg
);
287 for (i
= 0; i
< numwidgets
; i
++)
290 widget_new
= name_func_lookup(cfg_name(wptr
), WidgetList
);
294 statusbar
->widgets
= widget
= widget_new(statusbar
, wptr
);
297 widget
->next
= widget_new(statusbar
, wptr
);
298 widget
= widget
->next
;
300 widget
->buttons
= parse_mouse_bindings(wptr
, "mouse", a_strcmp(cfg_name(wptr
), "taglist"));
303 warn("Ignoring unknown widget: %s.\n", cfg_name(widgets
+ i
));
308 config_parse_screen(cfg_t
*cfg
, int screen
)
312 Layout
*layout
= NULL
;
314 Statusbar
*statusbar
= NULL
;
315 cfg_t
*cfg_general
, *cfg_colors
, *cfg_screen
, *cfg_tags
,
316 *cfg_layouts
, *cfg_padding
, *cfgsectmp
;
317 VirtScreen
*virtscreen
= &globalconf
.screens
[screen
];
319 int phys_screen
= get_phys_screen(screen
);
321 snprintf(buf
, sizeof(buf
), "%d", screen
);
322 cfg_screen
= cfg_gettsec(cfg
, "screen", buf
);
324 cfg_screen
= cfg_getsec(cfg
, "screen");
328 warn("parsing configuration file failed, no screen section found\n");
329 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
330 cfg_screen
= cfg_getsec(cfg
, "screen");
333 /* get screen specific sections */
334 cfg_tags
= cfg_getsec(cfg_screen
, "tags");
335 cfg_colors
= cfg_getsec(cfg_screen
, "colors");
336 cfg_general
= cfg_getsec(cfg_screen
, "general");
337 cfg_layouts
= cfg_getsec(cfg_screen
, "layouts");
338 cfg_padding
= cfg_getsec(cfg_screen
, "padding");
341 /* General section */
342 virtscreen
->borderpx
= cfg_getint(cfg_general
, "border");
343 virtscreen
->snap
= cfg_getint(cfg_general
, "snap");
344 virtscreen
->resize_hints
= cfg_getbool(cfg_general
, "resize_hints");
345 virtscreen
->opacity_unfocused
= cfg_getint(cfg_general
, "opacity_unfocused");
346 virtscreen
->focus_move_pointer
= cfg_getbool(cfg_general
, "focus_move_pointer");
347 virtscreen
->allow_lower_floats
= cfg_getbool(cfg_general
, "allow_lower_floats");
348 virtscreen
->sloppy_focus
= cfg_getbool(cfg_general
, "sloppy_focus");
349 virtscreen
->new_become_master
= cfg_getbool(cfg_general
, "new_become_master");
350 virtscreen
->font
= XftFontOpenName(globalconf
.display
,
352 cfg_getstr(cfg_general
, "font"));
353 if(!virtscreen
->font
)
354 eprint("awesome: cannot init font\n");
357 virtscreen
->colors_normal
[ColBorder
] = initxcolor(phys_screen
,
358 cfg_getstr(cfg_colors
, "normal_border"));
359 virtscreen
->colors_normal
[ColBG
] = initxcolor(phys_screen
,
360 cfg_getstr(cfg_colors
, "normal_bg"));
361 virtscreen
->colors_normal
[ColFG
] = initxcolor(phys_screen
,
362 cfg_getstr(cfg_colors
, "normal_fg"));
363 virtscreen
->colors_selected
[ColBorder
] = initxcolor(phys_screen
,
364 cfg_getstr(cfg_colors
, "focus_border"));
365 virtscreen
->colors_selected
[ColBG
] = initxcolor(phys_screen
,
366 cfg_getstr(cfg_colors
, "focus_bg"));
367 virtscreen
->colors_selected
[ColFG
] = initxcolor(phys_screen
,
368 cfg_getstr(cfg_colors
, "focus_fg"));
369 virtscreen
->colors_urgent
[ColBG
] = initxcolor(phys_screen
,
370 cfg_getstr(cfg_colors
, "urgent_bg"));
371 virtscreen
->colors_urgent
[ColFG
] = initxcolor(phys_screen
,
372 cfg_getstr(cfg_colors
, "urgent_fg"));
376 if(cfg_size(cfg_screen
, "statusbar"))
378 virtscreen
->statusbar
= statusbar
= p_new(Statusbar
, 1);
379 for(i
= 0; i
< cfg_size(cfg_screen
, "statusbar"); i
++)
381 cfgsectmp
= cfg_getnsec(cfg_screen
, "statusbar", i
);
382 statusbar
->position
= statusbar
->dposition
=
383 statusbar_get_position_from_str(cfg_getstr(cfgsectmp
, "position"));
384 statusbar
->height
= cfg_getint(cfgsectmp
, "height");
385 statusbar
->width
= cfg_getint(cfgsectmp
, "width");
386 statusbar
->name
= a_strdup(cfg_title(cfgsectmp
));
387 create_widgets(cfgsectmp
, statusbar
);
389 if(i
< cfg_size(cfg_screen
, "statusbar") - 1)
390 statusbar
= statusbar
->next
= p_new(Statusbar
, 1);
395 virtscreen
->layouts
= layout
= p_new(Layout
, 1);
396 if(cfg_size(cfg_layouts
, "layout"))
397 for(i
= 0; i
< cfg_size(cfg_layouts
, "layout"); i
++)
399 cfgsectmp
= cfg_getnsec(cfg_layouts
, "layout", i
);
400 layout
->arrange
= name_func_lookup(cfg_title(cfgsectmp
), LayoutsList
);
403 warn("unknown layout %s in configuration file\n", cfg_title(cfgsectmp
));
404 layout
->image
= NULL
;
407 layout
->image
= a_strdup(cfg_getstr(cfgsectmp
, "image"));
409 if(i
< cfg_size(cfg_layouts
, "layout") - 1)
410 layout
= layout
->next
= p_new(Layout
, 1);
414 warn("no default layout available\n");
415 layout
->arrange
= layout_tile
;
419 virtscreen
->tags
= tag
= p_new(Tag
, 1);
420 if(cfg_size(cfg_tags
, "tag"))
421 for(i
= 0; i
< cfg_size(cfg_tags
, "tag"); i
++)
423 cfgsectmp
= cfg_getnsec(cfg_tags
, "tag", i
);
424 tag
->name
= a_strdup(cfg_title(cfgsectmp
));
425 tag
->selected
= False
;
426 tag
->was_selected
= False
;
427 tmp
= cfg_getstr(cfgsectmp
, "layout");
428 for(layout
= virtscreen
->layouts
;
429 layout
&& layout
->arrange
!= name_func_lookup(tmp
, LayoutsList
); layout
= layout
->next
);
431 tag
->layout
= virtscreen
->layouts
;
433 tag
->layout
= layout
;
434 tag
->mwfact
= cfg_getfloat(cfgsectmp
, "mwfact");
435 tag
->nmaster
= cfg_getint(cfgsectmp
, "nmaster");
436 tag
->ncol
= cfg_getint(cfgsectmp
, "ncol");
438 if(i
< cfg_size(cfg_tags
, "tag") - 1)
439 tag
= tag
->next
= p_new(Tag
, 1);
445 warn("fatal: no tags found in configuration file\n");
446 tag
->name
= a_strdup("default");
447 tag
->layout
= virtscreen
->layouts
;
453 ewmh_update_net_numbers_of_desktop(phys_screen
);
454 ewmh_update_net_current_desktop(phys_screen
);
455 ewmh_update_net_desktop_names(phys_screen
);
457 /* select first tag by default */
458 virtscreen
->tags
[0].selected
= True
;
459 virtscreen
->tags
[0].was_selected
= True
;
462 virtscreen
->padding
.top
= cfg_getint(cfg_padding
, "top");
463 virtscreen
->padding
.bottom
= cfg_getint(cfg_padding
, "bottom");
464 virtscreen
->padding
.left
= cfg_getint(cfg_padding
, "left");
465 virtscreen
->padding
.right
= cfg_getint(cfg_padding
, "right");
468 /** Parse configuration file and initialize some stuff
469 * \param confpatharg Path to configuration file
472 config_parse(const char *confpatharg
)
474 static cfg_opt_t general_opts
[] =
476 CFG_INT((char *) "border", 1, CFGF_NONE
),
477 CFG_INT((char *) "snap", 8, CFGF_NONE
),
478 CFG_BOOL((char *) "resize_hints", cfg_true
, CFGF_NONE
),
479 CFG_INT((char *) "opacity_unfocused", 100, CFGF_NONE
),
480 CFG_BOOL((char *) "focus_move_pointer", cfg_false
, CFGF_NONE
),
481 CFG_BOOL((char *) "allow_lower_floats", cfg_false
, CFGF_NONE
),
482 CFG_BOOL((char *) "sloppy_focus", cfg_true
, CFGF_NONE
),
483 CFG_BOOL((char *) "new_become_master", cfg_true
, CFGF_NONE
),
484 CFG_STR((char *) "font", (char *) "mono-12", CFGF_NONE
),
487 static cfg_opt_t colors_opts
[] =
489 CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE
),
490 CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE
),
491 CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE
),
492 CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE
),
493 CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE
),
494 CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE
),
495 CFG_STR((char *) "urgent_bg", (char *) "#ff0000", CFGF_NONE
),
496 CFG_STR((char *) "urgent_fg", (char *) "#ffffff", CFGF_NONE
),
497 CFG_STR((char *) "tab_border", (char *) "#ff0000", CFGF_NONE
),
500 static cfg_opt_t mouse_taglist_opts
[] =
502 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
503 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
504 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
507 static cfg_opt_t mouse_generic_opts
[] =
509 CFG_STR_LIST((char *) "modkey", (char *) "{}", CFGF_NONE
),
510 CFG_STR((char *) "button", (char *) "None", CFGF_NONE
),
511 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
512 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
515 static cfg_opt_t widget_opts
[] =
517 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
518 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
519 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
522 static cfg_opt_t widget_taglist_opts
[] =
524 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
525 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
526 CFG_SEC((char *) "mouse", mouse_taglist_opts
, CFGF_MULTI
),
529 static cfg_opt_t widget_iconbox_opts
[] =
531 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
532 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
533 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
534 CFG_STR((char *) "image", (char *) NULL
, CFGF_NONE
),
535 CFG_BOOL((char *) "resize", cfg_true
, CFGF_NONE
),
538 static cfg_opt_t widget_textbox_opts
[] =
540 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
541 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
542 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
543 CFG_INT((char *) "width", 0, CFGF_NONE
),
544 CFG_STR((char *) "text", (char *) NULL
, CFGF_NONE
),
545 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
546 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
547 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
548 CFG_STR((char *) "align", (char *) "center", CFGF_NONE
),
551 static cfg_opt_t widget_focustitle_opts
[] =
553 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
554 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
555 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
556 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
557 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
558 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
559 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
562 static cfg_opt_t widget_tasklist_opts
[] =
564 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
565 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
566 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
567 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
568 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
569 CFG_STR((char *) "focus_fg", (char *) NULL
, CFGF_NONE
),
570 CFG_STR((char *) "focus_bg", (char *) NULL
, CFGF_NONE
),
571 CFG_STR((char *) "font", (char *) NULL
, CFGF_NONE
),
572 CFG_STR((char *) "align", (char *) "left", CFGF_NONE
),
573 CFG_BOOL((char *) "show_icons", cfg_true
, CFGF_NONE
),
576 static cfg_opt_t widget_graph_opts
[] =
578 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
579 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
580 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
581 CFG_INT((char *) "width", 100, CFGF_NONE
),
582 CFG_INT((char *) "padding_left", 3, CFGF_NONE
),
583 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
584 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
585 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
586 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
589 static cfg_opt_t widget_progressbar_bar_opts
[] =
591 CFG_STR((char *) "fg", (char *) NULL
, CFGF_NONE
),
592 CFG_STR((char *) "bg", (char *) NULL
, CFGF_NONE
),
593 CFG_STR((char *) "bordercolor", (char *) NULL
, CFGF_NONE
),
595 static cfg_opt_t widget_progressbar_opts
[] =
597 CFG_INT((char *) "x", 0xffffffff, CFGF_NONE
),
598 CFG_INT((char *) "y", 0xffffffff, CFGF_NONE
),
599 CFG_SEC((char *) "mouse", mouse_generic_opts
, CFGF_MULTI
),
600 CFG_SEC((char *) "bar", widget_progressbar_bar_opts
, CFGF_MULTI
),
601 CFG_INT((char *) "width", 100, CFGF_NONE
),
602 CFG_INT((char *) "gap", 2, CFGF_NONE
),
603 CFG_INT((char *) "padding_left", 3, CFGF_NONE
),
604 CFG_FLOAT((char *) "height", 0.67, CFGF_NONE
),
607 static cfg_opt_t statusbar_opts
[] =
609 CFG_STR((char *) "position", (char *) "top", CFGF_NONE
),
610 CFG_INT((char *) "height", 0, CFGF_NONE
),
611 CFG_INT((char *) "width", 0, CFGF_NONE
),
612 CFG_SEC((char *) "textbox", widget_textbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
613 CFG_SEC((char *) "taglist", widget_taglist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
614 CFG_SEC((char *) "focustitle", widget_focustitle_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
615 CFG_SEC((char *) "layoutinfo", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
616 CFG_SEC((char *) "iconbox", widget_iconbox_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
617 CFG_SEC((char *) "netwmicon", widget_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
618 CFG_SEC((char *) "progressbar", widget_progressbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
619 CFG_SEC((char *) "graph", widget_graph_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
620 CFG_SEC((char *) "tasklist", widget_tasklist_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
623 static cfg_opt_t tag_opts
[] =
625 CFG_STR((char *) "layout", (char *) "tile", CFGF_NONE
),
626 CFG_FLOAT((char *) "mwfact", 0.5, CFGF_NONE
),
627 CFG_INT((char *) "nmaster", 1, CFGF_NONE
),
628 CFG_INT((char *) "ncol", 1, CFGF_NONE
),
631 static cfg_opt_t tags_opts
[] =
633 CFG_SEC((char *) "tag", tag_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
636 static cfg_opt_t layout_opts
[] =
638 CFG_STR((char *) "image", NULL
, CFGF_NONE
),
641 static cfg_opt_t layouts_opts
[] =
643 CFG_SEC((char *) "layout", layout_opts
, CFGF_TITLE
| CFGF_MULTI
),
646 static cfg_opt_t padding_opts
[] =
648 CFG_INT((char *) "top", 0, CFGF_NONE
),
649 CFG_INT((char *) "bottom", 0, CFGF_NONE
),
650 CFG_INT((char *) "right", 0, CFGF_NONE
),
651 CFG_INT((char *) "left", 0, CFGF_NONE
),
654 static cfg_opt_t screen_opts
[] =
656 CFG_SEC((char *) "general", general_opts
, CFGF_NONE
),
657 CFG_SEC((char *) "statusbar", statusbar_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
658 CFG_SEC((char *) "tags", tags_opts
, CFGF_NONE
),
659 CFG_SEC((char *) "colors", colors_opts
, CFGF_NONE
),
660 CFG_SEC((char *) "layouts", layouts_opts
, CFGF_NONE
),
661 CFG_SEC((char *) "padding", padding_opts
, CFGF_NONE
),
664 static cfg_opt_t rule_opts
[] =
666 CFG_STR((char *) "xproperty_name", NULL
, CFGF_NONE
),
667 CFG_STR((char *) "xproperty_value", NULL
, CFGF_NONE
),
668 CFG_STR((char *) "name", NULL
, CFGF_NONE
),
669 CFG_STR((char *) "tags", NULL
, CFGF_NONE
),
670 CFG_STR((char *) "icon", NULL
, CFGF_NONE
),
671 CFG_STR((char *) "float", (char *) "auto", CFGF_NONE
),
672 CFG_INT((char *) "screen", RULE_NOSCREEN
, CFGF_NONE
),
673 CFG_BOOL((char *) "not_master", cfg_false
, CFGF_NONE
),
676 static cfg_opt_t rules_opts
[] =
678 CFG_SEC((char *) "rule", rule_opts
, CFGF_MULTI
),
681 static cfg_opt_t key_opts
[] =
683 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
684 CFG_STR((char *) "key", (char *) "None", CFGF_NONE
),
685 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
686 CFG_STR((char *) "arg", NULL
, CFGF_NONE
),
689 static cfg_opt_t keylist_opts
[] =
691 CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE
),
692 CFG_STR_LIST((char *) "keylist", (char *) NULL
, CFGF_NONE
),
693 CFG_STR((char *) "command", (char *) "", CFGF_NONE
),
694 CFG_STR_LIST((char *) "arglist", NULL
, CFGF_NONE
),
697 static cfg_opt_t keys_opts
[] =
699 CFG_SEC((char *) "key", key_opts
, CFGF_MULTI
),
700 CFG_SEC((char *) "keylist", keylist_opts
, CFGF_MULTI
),
703 static cfg_opt_t mouse_opts
[] =
705 CFG_SEC((char *) "root", mouse_generic_opts
, CFGF_MULTI
),
706 CFG_SEC((char *) "client", mouse_generic_opts
, CFGF_MULTI
),
709 static cfg_opt_t opts
[] =
711 CFG_SEC((char *) "screen", screen_opts
, CFGF_TITLE
| CFGF_MULTI
| CFGF_NO_TITLE_DUPES
),
712 CFG_SEC((char *) "rules", rules_opts
, CFGF_NONE
),
713 CFG_SEC((char *) "keys", keys_opts
, CFGF_NONE
),
714 CFG_SEC((char *) "mouse", mouse_opts
, CFGF_NONE
),
717 cfg_t
*cfg
, *cfg_rules
, *cfg_keys
, *cfg_mouse
, *cfgsectmp
;
722 ssize_t confpath_len
;
724 FILE *defconfig
= NULL
;
727 confpath
= a_strdup(confpatharg
);
730 homedir
= getenv("HOME");
731 confpath_len
= a_strlen(homedir
) + a_strlen(AWESOME_CONFIG_FILE
) + 2;
732 confpath
= p_new(char, confpath_len
);
733 a_strcpy(confpath
, confpath_len
, homedir
);
734 a_strcat(confpath
, confpath_len
, "/");
735 a_strcat(confpath
, confpath_len
, AWESOME_CONFIG_FILE
);
738 globalconf
.configpath
= a_strdup(confpath
);
740 cfg
= cfg_init(opts
, CFGF_NONE
);
742 ret
= cfg_parse(cfg
, confpath
);
743 if(ret
== CFG_FILE_ERROR
)
745 perror("awesome: parsing configuration file failed");
746 if(!(defconfig
= fopen(confpath
, "w")))
747 perror("awesome: unable to create default configuration file");
749 else if(ret
== CFG_PARSE_ERROR
)
750 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
751 if(ret
!= CFG_SUCCESS
) {
752 fprintf(stderr
, "Using default compile-time configuration\n");
754 cfg
= cfg_init(opts
, CFGF_NONE
);
755 cfg_parse_buf(cfg
, AWESOME_DEFAULT_CONFIG
);
758 /* get the right screen section */
759 for(screen
= 0; screen
< get_screen_count(); screen
++)
760 config_parse_screen(cfg
, screen
);
762 /* get general sections */
763 cfg_rules
= cfg_getsec(cfg
, "rules");
764 cfg_keys
= cfg_getsec(cfg
, "keys");
765 cfg_mouse
= cfg_getsec(cfg
, "mouse");
768 if(cfg_size(cfg_rules
, "rule"))
770 globalconf
.rules
= rule
= p_new(Rule
, 1);
771 for(i
= 0; i
< cfg_size(cfg_rules
, "rule"); i
++)
773 cfgsectmp
= cfg_getnsec(cfg_rules
, "rule", i
);
774 rule
->prop_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "name"));
775 rule
->tags_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "tags"));
776 rule
->xprop
= a_strdup(cfg_getstr(cfgsectmp
, "xproperty_name"));
777 rule
->xpropval_r
= rules_compile_regex(cfg_getstr(cfgsectmp
, "xproperty_value"));
778 rule
->icon
= a_strdup(cfg_getstr(cfgsectmp
, "icon"));
779 rule
->isfloating
= rules_get_float_from_str(cfg_getstr(cfgsectmp
, "float"));
780 rule
->screen
= cfg_getint(cfgsectmp
, "screen");
781 rule
->not_master
= cfg_getbool(cfgsectmp
, "not_master");
782 if(rule
->screen
>= get_screen_count())
785 if(i
< cfg_size(cfg_rules
, "rule") - 1)
786 rule
= rule
->next
= p_new(Rule
, 1);
792 globalconf
.rules
= NULL
;
794 /* Mouse: root window click bindings */
795 globalconf
.buttons
.root
= parse_mouse_bindings(cfg_mouse
, "root", True
);
797 /* Mouse: client windows click bindings */
798 globalconf
.buttons
.client
= parse_mouse_bindings(cfg_mouse
, "client", True
);
801 globalconf
.numlockmask
= get_numlockmask(globalconf
.display
);
803 globalconf
.keys
= section_keys(cfg_keys
);
807 cfg_print(cfg
, defconfig
);
811 /* Free! Like a river! */
816 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80