Simplify widget draw interface.

This commit is contained in:
Aldo Cortesi 2007-12-16 14:28:29 +11:00 committed by Julien Danjou
parent 65d8d846f2
commit 8880a3804e
7 changed files with 27 additions and 28 deletions

View file

@ -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;

View file

@ -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)
{

View file

@ -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

View file

@ -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)
{

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;