diff --git a/config.h b/config.h index 6eb18df60..15cf022ea 100644 --- a/config.h +++ b/config.h @@ -106,6 +106,9 @@ struct Widget Alignment alignment; /** Misc private data */ void *data; + /** True if user supplied coords */ + Bool user_supplied_x; + Bool user_supplied_y; /** Area */ Area area; /** Buttons bindings */ diff --git a/widget.c b/widget.c index 33f60cacf..121c882fc 100644 --- a/widget.c +++ b/widget.c @@ -117,6 +117,8 @@ widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config) widget->button_press = widget_common_button_press; widget->area.x = cfg_getint(config, "x"); widget->area.y = cfg_getint(config, "y"); + widget->user_supplied_x = (widget->area.x >= 0); + widget->user_supplied_y = (widget->area.y >= 0); } /** Send command to widget diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 868a2aa4e..190ebd5cc 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -43,32 +43,31 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) { Data *d = widget->data; Client *sel = focus_get_current_client(widget->statusbar->screen); - Area widget_area = widget->area; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, 0, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; if(sel) { - draw_text(ctx, widget_area.x, widget_area.y, + draw_text(ctx, widget->area.x, widget->area.y, widget->statusbar->width - used, widget->statusbar->height, d->align, widget->font->height / 2, widget->font, sel->name, d->fg, d->bg); if(sel->isfloating) - draw_circle(ctx, widget_area.x, widget_area.y, + draw_circle(ctx, widget->area.x, widget->area.y, (widget->font->height + 2) / 4, sel->ismax, d->fg); } else - draw_rectangle(ctx, widget_area.x, widget_area.y, + draw_rectangle(ctx, widget->area.x, widget->area.y, widget->statusbar->width - used, widget->statusbar->height, True, d->bg); widget->area.width = widget->statusbar->width - used; diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 6ad6aa011..7b9bd1254 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -35,23 +35,23 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { Data *d = widget->data; - Area area = draw_get_image_size(d->image), widget_area = widget->area; + Area area = draw_get_image_size(d->image); if(d->resize) widget->area.width = ((double) widget->statusbar->height / area.height) * area.width; else widget->area.width = area.width; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.width, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; - draw_image(ctx, widget_area.x, widget_area.y, + draw_image(ctx, widget->area.x, widget->area.y, d->resize ? widget->statusbar->height : 0, d->image); return widget->area.width; diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index cc0e86c5c..90172d7bc 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -34,20 +34,19 @@ layoutinfo_draw(Widget *widget, int used __attribute__ ((unused))) { Tag **curtags = get_current_tags(widget->statusbar->screen); - Area widget_area = widget->area; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->statusbar->height, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; widget->area.width = widget->statusbar->height; - draw_image(ctx, widget_area.x, widget_area.y, + draw_image(ctx, widget->area.x, widget->area.y, widget->statusbar->height, curtags[0]->layout->image); diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index ad70094da..119c77d1c 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -34,7 +34,7 @@ static int netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - Area area, widget_area = widget->area; + Area area; Rule* r; Client *sel = focus_get_current_client(widget->statusbar->screen); NetWMIcon *icon; @@ -51,15 +51,15 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, area = draw_get_image_size(r->icon); widget->area.width = ((double) widget->statusbar->height / (double) area.height) * area.width; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.width, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; - draw_image(ctx, widget_area.x, widget_area.y, + if(!widget->user_supplied_y) + widget->area.y = 0; + draw_image(ctx, widget->area.x, widget->area.y, widget->statusbar->height, r->icon); return widget->area.width; @@ -74,17 +74,17 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.width, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; draw_image_from_argb_data(ctx, - widget_area.x, widget_area.y, + widget->area.x, widget->area.y, icon->width, icon->height, widget->statusbar->height, icon->image); diff --git a/widgets/progressbar.c b/widgets/progressbar.c index 8b6a4ee1c..dad829235 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -55,7 +55,6 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { int i, width, pwidth, margin_top, pb_height, left_offset; - Area widget_area = widget->area; Data *d = widget->data; @@ -64,18 +63,18 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, width = d->width - d->lpadding; - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, d->width, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; - margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5 + widget_area.y; + margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5 + widget->area.y; pb_height = (int) (widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5; - left_offset = widget_area.x + d->lpadding; + left_offset = widget->area.x + d->lpadding; for(i = 0; i < d->bars; i++) { diff --git a/widgets/taglist.c b/widgets/taglist.c index c7d3b5e5f..084a13531 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -75,12 +75,13 @@ taglist_draw(Widget *widget, for(tag = vscreen.tags; tag; tag = tag->next) widget->area.width += textwidth(vscreen.font, tag->name) + vscreen.font->height; - widget->area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.width, offset, widget->alignment); - if(widget->area.y < 0) + if(!widget->user_supplied_y) widget->area.y = 0; widget->area.width = 0; diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 599a0da16..9008530fb 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -67,14 +67,14 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) box_width = (widget->statusbar->width - used) / n; - if(widget->area.x < 0) + if(!widget->user_supplied_x) widget->area.x = widget_calculate_offset(widget->statusbar->width, 0, offset, widget->alignment); - if(widget->area.y < 0) - widget->area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = widget->area.y = 0; for(c = globalconf.clients; c; c = c->next) if(ISVISIBLE_ON_TB(c, widget->statusbar->screen)) diff --git a/widgets/textbox.c b/widgets/textbox.c index a971b43b8..6176dce2a 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -40,22 +40,21 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { Data *d = widget->data; - Area widget_area = widget->area; if(d->width) widget->area.width = d->width; else widget->area.width = textwidth(widget->font, d->text); - if(widget->area.x < 0) - widget_area.x = widget_calculate_offset(widget->statusbar->width, + if(!widget->user_supplied_x) + widget->area.x = widget_calculate_offset(widget->statusbar->width, widget->area.width, offset, widget->alignment); - if(widget->area.y < 0) - widget_area.y = 0; + if(!widget->user_supplied_y) + widget->area.y = 0; - draw_text(ctx, widget_area.x, widget_area.y, widget->area.width, + draw_text(ctx, widget->area.x, widget->area.y, widget->area.width, widget->statusbar->height, d->align, 0, widget->font, d->text, d->fg, d->bg);