first try to get widget configurable

This commit is contained in:
Julien Danjou 2007-12-15 18:21:02 +01:00
parent 4432bd6d39
commit 602f921559
6 changed files with 52 additions and 14 deletions

View File

@ -21,6 +21,14 @@ screen 0
layout dwindle { symbol = "[\\]" }
layout floating { symbol = "><>" }
}
statusbar
{
position = "top"
widget taglist {}
widget layoutinfo {}
widget focustitle {}
widget textbox {}
}
}
rules

View File

@ -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"))
{

View File

@ -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;
};

View File

@ -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);

View File

@ -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)
{

View File

@ -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