From a4c09d142c598159c99b42b6211e1857b4581ff4 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 4 Jan 2008 22:05:52 +0100 Subject: [PATCH] add support for x,y coords supplying in widgets --- config.c | 14 ++++++++++++++ widget.c | 2 ++ widgets/focustitle.c | 18 +++++++++++------- widgets/iconbox.c | 15 ++++++++++----- widgets/layoutinfo.c | 16 +++++++++++----- widgets/netwmicon.c | 29 +++++++++++++++++++---------- widgets/progressbar.c | 19 +++++++++++-------- widgets/taglist.c | 18 ++++++++++++------ widgets/tasklist.c | 27 ++++++++++++++++++--------- widgets/textbox.c | 9 +++++---- 10 files changed, 113 insertions(+), 54 deletions(-) diff --git a/config.c b/config.c index 476147db..69e59019 100644 --- a/config.c +++ b/config.c @@ -514,16 +514,22 @@ config_parse(const char *confpatharg) }; static cfg_opt_t widget_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_END() }; static cfg_opt_t widget_taglist_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI), CFG_END() }; static cfg_opt_t widget_iconbox_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, 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), @@ -531,6 +537,8 @@ config_parse(const char *confpatharg) }; static cfg_opt_t widget_textbox_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, 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), @@ -542,6 +550,8 @@ config_parse(const char *confpatharg) }; static cfg_opt_t widget_focustitle_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), @@ -551,6 +561,8 @@ config_parse(const char *confpatharg) }; static cfg_opt_t widget_tasklist_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), @@ -569,6 +581,8 @@ config_parse(const char *confpatharg) }; static cfg_opt_t widget_progressbar_opts[] = { + CFG_INT((char *) "x", -1, CFGF_NONE), + CFG_INT((char *) "y", -1, 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), diff --git a/widget.c b/widget.c index 16a3498d..33f60cac 100644 --- a/widget.c +++ b/widget.c @@ -115,6 +115,8 @@ widget_common_new(Widget *widget, Statusbar *statusbar, cfg_t* config) widget->name = a_strdup(name); widget->tell = widget_common_tell; widget->button_press = widget_common_button_press; + widget->area.x = cfg_getint(config, "x"); + widget->area.y = cfg_getint(config, "y"); } /** Send command to widget diff --git a/widgets/focustitle.c b/widgets/focustitle.c index e7f3577d..84e7178b 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -44,26 +44,30 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) Data *d = widget->data; Client *sel = focus_get_current_client(widget->statusbar->screen); - widget->area.x = widget_calculate_offset(widget->statusbar->width, - 0, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + 0, + offset, + widget->alignment); + + if(widget->area.y < 0) + widget->area.y = 0; if(sel) { - draw_text(ctx, widget->area.x, 0, + 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, 0, + 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, 0, + 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 872e0857..4ceaf7cb 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -42,12 +42,17 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, else widget->area.width = area.width; - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->area.width, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + widget->area.width, + offset, + widget->alignment); - draw_image(ctx, widget->area.x, 0, d->resize ? widget->statusbar->height : 0, d->image); + if(widget->area.y < 0) + widget->area.y = 0; + + 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 b420bd83..46fccb57 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -34,14 +34,20 @@ layoutinfo_draw(Widget *widget, int used __attribute__ ((unused))) { Tag **curtags = get_current_tags(widget->statusbar->screen); - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->statusbar->height, - offset, - widget->alignment); + + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + widget->statusbar->height, + offset, + widget->alignment); + + if(widget->area.y < 0) + widget->area.y = 0; widget->area.width = widget->statusbar->height; - draw_image(ctx, widget->area.x, 0, widget->statusbar->height, + draw_image(ctx, widget->area.x, widget->area.y, + widget->statusbar->height, curtags[0]->layout->image); p_delete(&curtags); diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index 111af833..c4d667f5 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -51,11 +51,16 @@ 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; - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->area.width, - offset, - widget->alignment); - draw_image(ctx, widget->area.x, 0, widget->statusbar->height, r->icon); + if(widget->area.x < 0) + 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, + widget->statusbar->height, r->icon); return widget->area.width; } @@ -69,13 +74,17 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width; - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->area.width, - offset, - widget->alignment); + if(widget->area.x < 0) + 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_from_argb_data(ctx, - widget->area.x, 0, + 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 2c08b34a..c1dfd587 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -61,19 +61,22 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset, if (!(d->bars)) return 0; - margin_top = (int) (widget->statusbar->height * (1 - d->height)) / 2 + 0.5; - pb_height = (int) (widget->statusbar->height * d->height - (d->gap * (d->bars - 1))) / d->bars + 0.5; - width = d->width - d->lpadding; - widget->area.x = widget_calculate_offset(widget->statusbar->width, - d->width, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + d->width, + offset, + widget->alignment); + if(widget->area.y < 0) + widget->area.y = 0; + + 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; - for (i = 0; i < d->bars; i++) + for(i = 0; i < d->bars; i++) { pwidth = (int) d->percent[i] ? ((width - 2) * d->percent[i]) / 100 : 0; diff --git a/widgets/taglist.c b/widgets/taglist.c index abd7748a..29e7622b 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -75,10 +75,14 @@ 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, - widget->area.width, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + widget->area.width, + offset, + widget->alignment); + + if(widget->area.y < 0) + widget->area.y = 0; widget->area.width = 0; for(tag = vscreen.tags; tag; tag = tag->next) @@ -91,7 +95,7 @@ taglist_draw(Widget *widget, else colors = vscreen.colors_normal; draw_text(ctx, - widget->area.x + widget->area.width, 0, + widget->area.x + widget->area.width, widget->area.y, w, widget->statusbar->height, AlignCenter, vscreen.font->height / 2, @@ -100,7 +104,9 @@ taglist_draw(Widget *widget, colors[ColFG], colors[ColBG]); if(isoccupied(tag)) - draw_rectangle(ctx, widget->area.x + widget->area.width, 0, flagsize, flagsize, + draw_rectangle(ctx, + widget->area.x + widget->area.width, widget->area.y, + flagsize, flagsize, sel && is_client_tagged(sel, tag), colors[ColFG]); widget->area.width += w; } diff --git a/widgets/tasklist.c b/widgets/tasklist.c index bf4b89ff..599a0da1 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -67,10 +67,14 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) box_width = (widget->statusbar->width - used) / n; - widget->area.x = widget_calculate_offset(widget->statusbar->width, - 0, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + 0, + offset, + widget->alignment); + + if(widget->area.y < 0) + widget->area.y = 0; for(c = globalconf.clients; c; c = c->next) if(ISVISIBLE_ON_TB(c, widget->statusbar->screen)) @@ -86,7 +90,8 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width; draw_image(ctx, widget->area.x + box_width * i, - 0, widget->statusbar->height, + widget->area.y, + widget->statusbar->height, r->icon); } @@ -95,7 +100,8 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) icon_width = ((double) widget->statusbar->height / (double) icon->height) * icon->width; draw_image_from_argb_data(ctx, - widget->area.x + box_width * i, 0, + widget->area.x + box_width * i, + widget->area.y, icon->width, icon->height, widget->statusbar->height, icon->image); p_delete(&icon->image); @@ -105,7 +111,8 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) if(sel == c) { - draw_text(ctx, widget->area.x + icon_width + box_width * i, 0, + draw_text(ctx, widget->area.x + icon_width + box_width * i, + widget->area.y, box_width - icon_width, widget->statusbar->height, d->align, @@ -113,14 +120,16 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) d->fg_sel, d->bg_sel); } else - draw_text(ctx, widget->area.x + icon_width + box_width * i, 0, + draw_text(ctx, widget->area.x + icon_width + box_width * i, + widget->area.y, box_width - icon_width, widget->statusbar->height, d->align, widget->font->height / 2, widget->font, c->name, d->fg, d->bg); if(c->isfloating) - draw_circle(ctx, widget->area.x + icon_width + box_width * i, 0, + draw_circle(ctx, widget->area.x + icon_width + box_width * i, + widget->area.y, (widget->font->height + 2) / 4, c->ismax, d->fg); i++; diff --git a/widgets/textbox.c b/widgets/textbox.c index b3e8275f..2bac9236 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -46,10 +46,11 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, else widget->area.width = textwidth(widget->font, d->text); - widget->area.x = widget_calculate_offset(widget->statusbar->width, - widget->area.width, - offset, - widget->alignment); + if(widget->area.x < 0) + widget->area.x = widget_calculate_offset(widget->statusbar->width, + widget->area.width, + offset, + widget->alignment); draw_text(ctx, widget->area.x, 0, widget->area.width, widget->statusbar->height, d->align, 0, widget->font, d->text, d->fg, d->bg);