add align option to widget to specify their alignment

This commit is contained in:
Julien Danjou 2008-02-08 10:59:55 +01:00
parent 4970e57048
commit 0bfa880b0f
12 changed files with 54 additions and 22 deletions

View File

@ -141,6 +141,8 @@ This widget shows the tag list.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
layoutinfo
~~~~~~~~~~
@ -152,6 +154,8 @@ This widget shows a icon for the selected layout.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
focusicon
~~~~~~~~~
@ -163,6 +167,8 @@ This widget shows a icon for the focused window using NET_WM_ICON or icon file
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
tasklist
~~~~~~~~
@ -213,6 +219,8 @@ This widget shows a text.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
iconbox
~~~~~~~
@ -228,6 +236,8 @@ This widget shows an icon.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
progressbar
~~~~~~~~~~~
@ -257,6 +267,8 @@ This widget shows one or more progress-bars.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
graph
~~~~~
@ -292,6 +304,8 @@ This widget shows a graph.
Horizontal offset (auto-alignment if not set).
*y*::
Vertical offset (auto-alignment if not set).
*align*::
Widget alignment.
OPTIONS
--------
@ -379,6 +393,7 @@ screen <integer> [MULTI]
taglist <identifier> [MULTI]
{
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -388,6 +403,7 @@ screen <integer> [MULTI]
layoutinfo <identifier>
{
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -397,6 +413,7 @@ screen <integer> [MULTI]
focusicon <identifier>
{
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -412,7 +429,7 @@ screen <integer> [MULTI]
font = <font>
show_icons = <boolean>
show = <{all,tags,focus}>
align = <{center,left,right}>
text_align = <{center,left,right}>
x = <integer> y = <integer>
mouse [MULTI]
{
@ -427,8 +444,9 @@ screen <integer> [MULTI]
fg = <color>
font = <font>
width = <integer>
align = <{center,left,right}>
text_align = <{center,left,right}>
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -440,6 +458,7 @@ screen <integer> [MULTI]
image = <image>
resize = <boolean>
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -458,6 +477,7 @@ screen <integer> [MULTI]
height = <float>
padding = <integer>
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}
@ -477,6 +497,7 @@ screen <integer> [MULTI]
bg = <color>
bordercolor = <color>
x = <integer> y = <integer>
align = <{auto,right,left}>
mouse [MULTI]
{
button = <integer> modkey = {<mod>, ...}

View File

@ -71,6 +71,7 @@ cfg_opt_t widget_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_END()
};
@ -78,6 +79,7 @@ cfg_opt_t widget_taglist_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
CFG_END()
};
@ -85,6 +87,7 @@ cfg_opt_t widget_iconbox_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE),
@ -94,6 +97,7 @@ cfg_opt_t widget_textbox_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_INT((char *) "width", 0, CFGF_NONE),
CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
@ -132,6 +136,7 @@ cfg_opt_t widget_graph_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_SEC((char *) "data", widget_graph_data_opts, CFGF_MULTI),
CFG_INT((char *) "width", 100, CFGF_NONE),
@ -154,6 +159,7 @@ cfg_opt_t widget_progressbar_opts[] =
{
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
CFG_SEC((char *) "bar", widget_progressbar_bar_opts, CFGF_MULTI),
CFG_INT((char *) "width", 100, CFGF_NONE),

View File

@ -535,12 +535,14 @@ draw_textwidth(Display *disp, XftFont *font, char *text)
Alignment
draw_get_align(const char *align)
{
if(!a_strncmp(align, "center", 6))
if(!a_strncmp(align, "left", 4))
return AlignLeft;
else if(!a_strncmp(align, "center", 6))
return AlignCenter;
else if(!a_strncmp(align, "right", 5))
return AlignRight;
return AlignLeft;
return AlignAuto;
}
/** Initialize an X color

View File

@ -33,8 +33,9 @@ typedef enum
{
AlignLeft,
AlignRight,
AlignCenter,
AlignFlex,
AlignCenter
AlignAuto
} Alignment;
typedef struct Area Area;

View File

@ -72,7 +72,7 @@ static void
statusbar_draw(Statusbar *statusbar)
{
int phys_screen = get_phys_screen(statusbar->screen);
Widget *widget, *last_drawn = NULL;
Widget *widget;
int left = 0, right = 0;
Area rectangle = { 0, 0, 0, 0, NULL };
Drawable d;
@ -116,13 +116,13 @@ statusbar_draw(Statusbar *statusbar)
}
/* renders right widget from last to first */
for(widget = statusbar->widgets; widget; widget = widget->next)
if (widget->alignment == AlignRight && last_drawn == widget->next)
for(widget = *widget_list_last(&statusbar->widgets);
widget;
widget = widget_list_prev(&statusbar->widgets, widget))
if (widget->alignment == AlignRight)
{
widget->cache.needs_update = False;
right += widget->draw(widget, ctx, right, (left + right));
last_drawn = widget;
widget = statusbar->widgets;
}
for(widget = statusbar->widgets; widget; widget = widget->next)

View File

@ -31,23 +31,18 @@ extern AwesomeConf globalconf;
void
widget_calculate_alignments(Widget *widget)
{
for(; widget; widget = widget->next)
{
if(widget->alignment == AlignFlex)
{
widget = widget->next;
break;
}
widget->alignment = AlignLeft;
}
for(; widget && widget->alignment != AlignFlex; widget = widget->next)
if(widget->alignment == AlignAuto)
widget->alignment = AlignLeft;
if(widget)
for(; widget; widget = widget->next)
for(widget = widget->next; widget; widget = widget->next)
{
if (widget->alignment == AlignFlex)
if(widget->alignment == AlignFlex)
warn("Multiple flex widgets in panel -"
" ignoring flex for all but the first.");
widget->alignment = AlignRight;
if(widget->alignment == AlignAuto)
widget->alignment = AlignRight;
}
}

View File

@ -100,6 +100,7 @@ focusicon_new(Statusbar *statusbar, cfg_t *config)
w = p_new(Widget, 1);
widget_common_new(w, statusbar, config);
w->draw = focusicon_draw;
w->alignment = draw_get_align(cfg_getstr(config, "align"));
/* Set cache property */
w->cache.flags = WIDGET_CACHE_CLIENTS;

View File

@ -81,6 +81,7 @@ iconbox_new(Statusbar *statusbar, cfg_t *config)
w = p_new(Widget, 1);
widget_common_new(w, statusbar, config);
w->alignment = draw_get_align(cfg_getstr(config, "align"));
w->draw = iconbox_draw;
w->tell = iconbox_tell;
w->data = d = p_new(Data, 1);

View File

@ -64,6 +64,7 @@ layoutinfo_new(Statusbar *statusbar, cfg_t* config)
w = p_new(Widget, 1);
widget_common_new(w, statusbar, config);
w->draw = layoutinfo_draw;
w->alignment = draw_get_align(cfg_getstr(config, "align"));
/* Set cache property */
w->cache.flags = WIDGET_CACHE_LAYOUTS;

View File

@ -149,6 +149,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
w->tell = progressbar_tell;
d = w->data = p_new(Data, 1);
d->width = cfg_getint(config, "width");
w->alignment = draw_get_align(cfg_getstr(config, "align"));
if(!(d->bars = cfg_size(config, "bar")))
{

View File

@ -193,6 +193,7 @@ taglist_new(Statusbar *statusbar, cfg_t *config)
widget_common_new(w, statusbar, config);
w->draw = taglist_draw;
w->button_press = taglist_button_press;
w->alignment = draw_get_align(cfg_getstr(config, "align"));
/* Set cache property */
w->cache.flags = WIDGET_CACHE_TAGS | WIDGET_CACHE_CLIENTS;

View File

@ -104,6 +104,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
widget_common_new(w, statusbar, config);
w->draw = textbox_draw;
w->tell = textbox_tell;
w->alignment = draw_get_align(cfg_getstr(config, "align"));
w->data = d = p_new(Data, 1);
@ -127,6 +128,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
w->font = globalconf.screens[statusbar->screen].font;
d->text = a_strdup(cfg_getstr(config, "text"));
return w;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80