diff --git a/awesomerc b/awesomerc index 2f370f57a..4af8e5637 100644 --- a/awesomerc +++ b/awesomerc @@ -21,6 +21,14 @@ screen 0 layout dwindle { symbol = "[\\]" } layout floating { symbol = "><>" } } + statusbar + { + position = "top" + widget taglist {} + widget layoutinfo {} + widget focustitle {} + widget textbox {} + } } rules diff --git a/config.c b/config.c index a5d1facb3..861482e82 100644 --- a/config.c +++ b/config.c @@ -32,6 +32,7 @@ #include "util.h" #include "rules.h" #include "screen.h" +#include "widget.h" #include "layouts/tile.h" #include "layouts/floating.h" #include "layouts/max.h" @@ -58,6 +59,7 @@ typedef struct } MouseButton; extern const NameFuncLink UicbList[]; +extern const NameFuncLink WidgetList[]; /** List of keyname and corresponding X11 mask codes */ static const KeyMod KeyModList[] = @@ -269,9 +271,14 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) CFG_STR((char *) "tab_border", (char *) "#ff0000", CFGF_NONE), CFG_END() }; + static cfg_opt_t widget_opts[] = + { + CFG_END() + }; static cfg_opt_t statusbar_opts[] = { CFG_STR((char *) "position", (char *) "top", CFGF_NONE), + CFG_SEC((char *) "widget", widget_opts, CFGF_TITLE | CFGF_MULTI), CFG_END() }; static cfg_opt_t tag_opts[] = @@ -382,7 +389,7 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) CFG_END() }; cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_screen, *cfg_statusbar, *cfg_tags, - *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp, *cfg_padding; + *cfg_layouts, *cfg_rules, *cfg_keys, *cfg_mouse, *cfg_padding, *cfgsectmp; int ret, screen; unsigned int i = 0; const char *tmp, *homedir; @@ -391,6 +398,8 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) Rule *rule = NULL; Layout *layout = NULL; Tag *tag = NULL; + Widget_ptr widget = NULL; + Widget_ptr (*widget_fct)(Statusbar *); FILE *defconfig = NULL; if(confpatharg) @@ -472,6 +481,22 @@ parse_config(const char *confpatharg, awesome_config *awesomeconf) awesomeconf->screens[screen].statusbar.dposition = statusbar_get_position_from_str(cfg_getstr(cfg_statusbar, "position")); + /* Statusbar widgets */ + if(cfg_size(cfg_statusbar, "widget")) + for(i = 0; i < cfg_size(cfg_statusbar, "widget"); i++) + { + cfgsectmp = cfg_getnsec(cfg_statusbar, "widget", i); + widget_fct = (Widget_ptr **) name_func_lookup(cfg_title(cfgsectmp), WidgetList); + if(!widget) + awesomeconf->screens[screen].statusbar.widgets = widget = + widget_fct(&awesomeconf->screens[screen].statusbar); + else + { + widget->next = widget_fct(&awesomeconf->screens[screen].statusbar); + widget = widget->next; + } + } + /* Layouts */ if(cfg_size(cfg_layouts, "layout")) { diff --git a/config.h b/config.h index dccbb7096..b8e1cb5e7 100644 --- a/config.h +++ b/config.h @@ -81,6 +81,7 @@ struct Button /** Status bar */ typedef struct Widget Widget; +typedef Widget * Widget_ptr; typedef struct { /** Bar width */ @@ -98,7 +99,7 @@ typedef struct /** Screen */ int screen; /** Screen */ - Widget *widgets; + Widget_ptr widgets; } Statusbar; typedef struct Client Client; @@ -229,7 +230,7 @@ struct Widget VirtScreen, int, int, int, int); Statusbar *statusbar; int alignment; - Widget *next; + Widget_ptr next; }; diff --git a/statusbar.c b/statusbar.c index 6dd41f574..5587644ee 100644 --- a/statusbar.c +++ b/statusbar.c @@ -86,7 +86,6 @@ statusbar_init(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, X XSetWindowAttributes wa; int phys_screen = get_phys_screen(disp, screen); ScreenInfo *si = get_screen_info(disp, screen, NULL, padding); - Widget *widget; statusbar->height = font->height * 1.5; @@ -121,12 +120,6 @@ statusbar_init(Display *disp, int screen, Statusbar *statusbar, Cursor cursor, X CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(disp, statusbar->window, cursor); - /* For now, we just create a standard set of widgets by hand. As the refactoring continues, - * these will become configurable. */ - statusbar->widgets = widget = taglist_new(statusbar); - widget->next = layoutinfo_new(statusbar); widget = widget->next; - widget->next = focustitle_new(statusbar); widget = widget->next; - widget->next = textbox_new(statusbar); calculate_alignments(statusbar->widgets); statusbar_update_position(disp, *statusbar, padding); diff --git a/widget.c b/widget.c index fe4b7ed7c..40cd9c0f5 100644 --- a/widget.c +++ b/widget.c @@ -1,5 +1,14 @@ +#include "util.h" #include "widget.h" +const NameFuncLink WidgetList[] = +{ + {"taglist", taglist_new}, + {"layoutinfo", layoutinfo_new}, + {"focustitle", focustitle_new}, + {"textbox", textbox_new} +}; + void calculate_alignments(Widget *widget) { diff --git a/widget.h b/widget.h index fefddce23..2aa7ea6e4 100644 --- a/widget.h +++ b/widget.h @@ -6,13 +6,15 @@ enum { AlignLeft, AlignRight, AlignFlex }; +typedef Widget_ptr (WidgetConstructor)(Statusbar *); + int calculate_offset(int, int, int, int); void calculate_alignments(Widget *widget); -Widget *layoutinfo_new(Statusbar*); -Widget *taglist_new(Statusbar*); -Widget *textbox_new(Statusbar*); -Widget *focustitle_new(Statusbar*); +Widget_ptr layoutinfo_new(Statusbar*); +Widget_ptr taglist_new(Statusbar*); +Widget_ptr textbox_new(Statusbar*); +Widget_ptr focustitle_new(Statusbar*); #endif