diff --git a/config.h b/config.h index 3433f2c9..c485d963 100644 --- a/config.h +++ b/config.h @@ -232,6 +232,8 @@ struct Widget Statusbar *statusbar; int alignment; void *data; + int location; + int width; Widget *next; }; diff --git a/tag.c b/tag.c index bf8d7c04..5cc59dd7 100644 --- a/tag.c +++ b/tag.c @@ -142,17 +142,17 @@ Tag ** get_current_tags(int screen) { Tag *tag, **tags = NULL; - int n = 0; + int n = 1; + tags = p_new(Tag *, n); for(tag = globalconf.screens[screen].tags; tag; tag = tag->next) if(tag->selected) { - p_realloc(tags, ++n); - tags[n - 1] = tag; + p_realloc(&tags, ++n); + tags[n - 2] = tag; } /* finish with null */ - p_realloc(tags, ++n); tags[n - 1] = NULL; return tags; diff --git a/widgets/focustitle.c b/widgets/focustitle.c index d515c270..f73d8253 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -13,29 +13,33 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen, get_current_tag(widget->statusbar->screen)); - int location = widget_calculate_offset(vscreen.statusbar->width, - 0, - offset, - widget->alignment); + + widget->location = widget_calculate_offset(vscreen.statusbar->width, + 0, + offset, + widget->alignment); if(sel) { - draw_text(ctx, location, 0, vscreen.statusbar->width - used, + draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used, vscreen.statusbar->height, vscreen.font, sel->name, vscreen.colors_selected[ColFG], vscreen.colors_selected[ColBG]); if(sel->isfloating) - draw_circle(ctx, location, 0, + draw_circle(ctx, widget->location, 0, (vscreen.font->height + 2) / 4, sel->ismax, vscreen.colors_selected[ColFG]); } else - draw_text(ctx, location, 0, vscreen.statusbar->width - used, + draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used, vscreen.statusbar->height, vscreen.font, NULL, vscreen.colors_normal[ColFG], vscreen.colors_normal[ColBG]); - return vscreen.statusbar->width - used; + + widget->width = vscreen.statusbar->width - used; + + return widget->width; } Widget * diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 90f36050..fde258f0 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -29,18 +29,16 @@ static int iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - int location, width; + widget->width = draw_get_image_width(widget->data); - width = draw_get_image_width(widget->data); + widget->location = widget_calculate_offset(widget->statusbar->width, + widget->width, + offset, + widget->alignment); - location = widget_calculate_offset(widget->statusbar->width, - width, - offset, - widget->alignment); + draw_image(ctx, widget->location, 0, 0, widget->data); - draw_image(ctx, location, 0, 0, widget->data); - - return width; + return widget->width; } static void diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index 8b9e9c71..14c1eff0 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -24,7 +24,7 @@ #include #include "widget.h" #include "util.h" -#include "layout.h" +#include "tag.h" extern AwesomeConf globalconf; @@ -34,15 +34,20 @@ layoutinfo_draw(Widget *widget, int offset, int used __attribute__ ((unused))) { - int location = widget_calculate_offset(widget->statusbar->width, - widget->statusbar->height, - offset, - widget->alignment); + Tag **curtags = get_current_tags(widget->statusbar->screen); + widget->location = widget_calculate_offset(widget->statusbar->width, + widget->statusbar->height, + offset, + widget->alignment); - draw_image(ctx, location, 0, widget->statusbar->height, - get_current_layout(widget->statusbar->screen)->image); + widget->width = widget->statusbar->height; - return widget->statusbar->height; + draw_image(ctx, widget->location, 0, widget->statusbar->height, + curtags[0]->layout->image); + + p_delete(&curtags); + + return widget->width; } Widget * diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index 73d23aa1..c32dc452 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -35,12 +35,10 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, { unsigned long *data, pixel; Atom type; - int format, location, width, height, size, i; + int format, width, height, size, i; unsigned long items, rest; unsigned char *image, *imgdata; - VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; - Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen, - get_current_tag(widget->statusbar->screen)); + Client *sel = globalconf.focus->client; if(!sel) return 0; @@ -78,17 +76,19 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, imgdata[2] = pixel & 0xff; /* B */ } - location = widget_calculate_offset(vscreen.statusbar->width, - width, - offset, - widget->alignment); + widget->location = widget_calculate_offset(widget->statusbar->width, + width, + offset, + widget->alignment); - draw_image_from_argb_data(ctx, location, 0, width, height, vscreen.statusbar->height, image); + draw_image_from_argb_data(ctx, widget->location, 0, width, height, widget->statusbar->height, image); p_delete(&image); XFree(data); - return vscreen.statusbar->height; + + widget->width = widget->statusbar->height; + return widget->width; } Widget * diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 2e9b1f7b..d6fc7dbd 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -39,40 +39,40 @@ static int progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; - int location, width, pwidth, margin, height; + int width, pwidth, margin, height; Data *d = widget->data; - height = vscreen.statusbar->height / 2; - margin = (vscreen.statusbar->height - height) / 2 - 1; + height = widget->statusbar->height / 2; + margin = (widget->statusbar->height - height) / 2 - 1; width = d->width - (margin * 2); - location = widget_calculate_offset(vscreen.statusbar->width, - d->width, - offset, - widget->alignment) + margin; + widget->location = widget_calculate_offset(widget->statusbar->width, + d->width, + offset, + widget->alignment) + margin; pwidth = d->percent ? (width * d->percent) / 100 : 0; draw_rectangle(ctx, - location + 1, margin, + widget->location + 1, margin, width, height, False, d->fg); if(pwidth > 0) draw_rectangle(ctx, - location + 1, margin + 1, + widget->location + 1, margin + 1, pwidth, height - 2, True, d->fg); if(width - pwidth - 2 > 0) draw_rectangle(ctx, - location + pwidth + 2, margin + 1, + widget->location + pwidth + 2, margin + 1, width - pwidth - 2, height - 2, True, d->bg); - return d->width; + widget->width = d->width; + return widget->width; } static void diff --git a/widgets/taglist.c b/widgets/taglist.c index b72e5760..2918ff4a 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -65,21 +65,20 @@ taglist_draw(Widget *widget, Tag *tag; Client *sel = globalconf.focus->client; VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; - int w = 0, width = 0, location; - int flagsize; + int w = 0, flagsize; XColor *colors; flagsize = (vscreen.font->height + 2) / 4; for(tag = vscreen.tags; tag; tag = tag->next) - width += textwidth(ctx, vscreen.font, tag->name); + widget->width += textwidth(ctx, vscreen.font, tag->name); - location = widget_calculate_offset(vscreen.statusbar->width, - width, - offset, - widget->alignment); + widget->location = widget_calculate_offset(widget->statusbar->width, + widget->width, + offset, + widget->alignment); - width = 0; + widget->width = 0; for(tag = vscreen.tags; tag; tag = tag->next) { w = textwidth(ctx, vscreen.font, tag->name); @@ -89,21 +88,21 @@ taglist_draw(Widget *widget, colors = vscreen.colors_urgent; else colors = vscreen.colors_normal; - draw_text(ctx, location + width, 0, w, + draw_text(ctx, widget->location + widget->width, 0, w, vscreen.statusbar->height, vscreen.font, tag->name, colors[ColFG], colors[ColBG]); if(isoccupied(widget->statusbar->screen, tag)) - draw_rectangle(ctx, location + width, 0, flagsize, flagsize, + draw_rectangle(ctx, widget->location + widget->width, 0, flagsize, flagsize, sel && is_client_tagged(sel, tag, widget->statusbar->screen), colors[ColFG]); - width += w; + widget->width += w; } - return width; + return widget->width; } Widget * diff --git a/widgets/textbox.c b/widgets/textbox.c index f979b0f5..e3e96c21 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -47,18 +47,18 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; - int width, location; Data *d = widget->data; - width = textwidth(ctx, vscreen.font, d->text); - location = widget_calculate_offset(vscreen.statusbar->width, - width, - offset, - widget->alignment); + widget->width = textwidth(ctx, vscreen.font, d->text); + widget->location = widget_calculate_offset(widget->statusbar->width, + widget->width, + offset, + widget->alignment); - draw_text(ctx, location, 0, width, vscreen.statusbar->height, + draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height, vscreen.font, d->text, d->fg, d->bg); - return width; + + return widget->width; } static void