From 8880a3804e30d8db5140aaf16db81eb556b58c3f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sun, 16 Dec 2007 14:28:29 +1100 Subject: [PATCH] Simplify widget draw interface. --- config.h | 2 +- statusbar.c | 6 +++--- widget.c | 5 ++++- widgets/focustitle.c | 6 +++--- widgets/layoutinfo.c | 10 ++++------ widgets/taglist.c | 15 +++++++-------- widgets/textbox.c | 11 +++++------ 7 files changed, 27 insertions(+), 28 deletions(-) diff --git a/config.h b/config.h index f6125143..eec067c3 100644 --- a/config.h +++ b/config.h @@ -224,7 +224,7 @@ typedef struct struct Widget { char *name; - int (*draw)(DrawCtx *, int, int, int, int); + int (*draw)(Widget *, DrawCtx *, int, int); Statusbar *statusbar; int alignment; Widget *next; diff --git a/statusbar.c b/statusbar.c index 0055e13a..db2f2744 100644 --- a/statusbar.c +++ b/statusbar.c @@ -50,13 +50,13 @@ statusbar_draw(int screen) for(widget = vscreen.statusbar.widgets; widget; widget = widget->next) if (widget->alignment == AlignLeft) - left += widget->draw(ctx, screen, left, (left + right), AlignLeft); + left += widget->draw(widget, ctx, left, (left + right)); else if (widget->alignment == AlignRight) - right += widget->draw(ctx, screen, right, (left + right), AlignRight); + right += widget->draw(widget, ctx, right, (left + right)); for(widget = vscreen.statusbar.widgets; widget; widget = widget->next) if (widget->alignment == AlignFlex) - left += widget->draw(ctx, screen, left, (left + right), AlignFlex); + left += widget->draw(widget, ctx, left, (left + right)); if(vscreen.statusbar.position == BarRight || vscreen.statusbar.position == BarLeft) { diff --git a/widget.c b/widget.c index 0b3193b3..f4830774 100644 --- a/widget.c +++ b/widget.c @@ -24,8 +24,11 @@ calculate_alignments(Widget *widget) } if(widget) - for(; widget; widget = widget->next) + for(; widget; widget = widget->next){ + if (widget->alignment == AlignFlex) + warn("Multiple flex widgets in panel - ignoring flex for all but the first."); widget->alignment = AlignRight; + } } int diff --git a/widgets/focustitle.c b/widgets/focustitle.c index 75429c16..7aad756a 100644 --- a/widgets/focustitle.c +++ b/widgets/focustitle.c @@ -6,11 +6,11 @@ extern awesome_config globalconf; static char name[] = "focustitle"; static int -focustitle_draw(DrawCtx *ctx, int screen, int offset, int used, int align) +focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used) { Client *sel = globalconf.focus->client; - VirtScreen vscreen = globalconf.screens[screen]; - int location = calculate_offset(vscreen.statusbar.width, 0, offset, align); + VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; + int location = calculate_offset(vscreen.statusbar.width, 0, offset, widget->alignment); if(sel) { diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index 4937364e..497c51bd 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -7,21 +7,19 @@ extern awesome_config globalconf; static char name[] = "layoutinfo"; static int -layoutinfo_draw(DrawCtx *ctx, int screen, int offset, - int used __attribute__ ((unused)), - int align __attribute__ ((unused))) +layoutinfo_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { int width = 0, location; - VirtScreen vscreen = globalconf.screens[screen]; + VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; Layout *l; for(l = vscreen.layouts ; l; l = l->next) width = MAX(width, (textwidth(ctx, vscreen.font, l->symbol))); - location = calculate_offset(vscreen.statusbar.width, width, offset, align); + location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment); drawtext(ctx, location, 0, width, vscreen.statusbar.height, vscreen.font, - get_current_layout(screen)->symbol, + get_current_layout(widget->statusbar->screen)->symbol, vscreen.colors_normal); return width; } diff --git a/widgets/taglist.c b/widgets/taglist.c index 9c96327d..5bce17e6 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -25,15 +25,14 @@ isoccupied(int screen, Tag *t) } static int -taglist_draw(DrawCtx *ctx, - int screen, +taglist_draw(Widget *widget, + DrawCtx *ctx, int offset, - int used __attribute__ ((unused)), - int align __attribute__ ((unused))) + int used __attribute__ ((unused))) { Tag *tag; Client *sel = globalconf.focus->client; - VirtScreen vscreen = globalconf.screens[screen]; + VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; int w = 0, width = 0, location; int flagsize; XColor *colors; @@ -44,7 +43,7 @@ taglist_draw(DrawCtx *ctx, { width += textwidth(ctx, vscreen.font, tag->name); } - location = calculate_offset(vscreen.statusbar.width, width, offset, align); + location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment); width = 0; for(tag = vscreen.tags; tag; tag = tag->next) @@ -56,9 +55,9 @@ taglist_draw(DrawCtx *ctx, colors = vscreen.colors_normal; drawtext(ctx, location + width, 0, w, vscreen.statusbar.height, vscreen.font, tag->name, colors); - if(isoccupied(screen, tag)) + if(isoccupied(widget->statusbar->screen, tag)) drawrectangle(ctx, location + width, 0, flagsize, flagsize, - sel && is_client_tagged(sel, tag, screen), + sel && is_client_tagged(sel, tag, widget->statusbar->screen), colors[ColFG]); width += w; } diff --git a/widgets/textbox.c b/widgets/textbox.c index a8f8b6ca..4233204b 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -6,15 +6,14 @@ extern awesome_config globalconf; static char name[] = "textbox"; static int -textbox_draw(DrawCtx *ctx, - int screen __attribute__ ((unused)), +textbox_draw(Widget *widget, + DrawCtx *ctx, int offset, - int used __attribute__ ((unused)), - int align) + int used __attribute__ ((unused))) { - VirtScreen vscreen = globalconf.screens[screen]; + VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; int width = textwidth(ctx, vscreen.font, vscreen.statustext); - int location = calculate_offset(vscreen.statusbar.width, width, offset, align); + int location = calculate_offset(vscreen.statusbar.width, width, offset, widget->alignment); drawtext(ctx, location, 0, width, vscreen.statusbar.height, vscreen.font, vscreen.statustext, vscreen.colors_normal); return width;