Simplify widget draw interface.
This commit is contained in:
parent
65d8d846f2
commit
8880a3804e
2
config.h
2
config.h
|
@ -224,7 +224,7 @@ typedef struct
|
||||||
struct Widget
|
struct Widget
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
int (*draw)(DrawCtx *, int, int, int, int);
|
int (*draw)(Widget *, DrawCtx *, int, int);
|
||||||
Statusbar *statusbar;
|
Statusbar *statusbar;
|
||||||
int alignment;
|
int alignment;
|
||||||
Widget *next;
|
Widget *next;
|
||||||
|
|
|
@ -50,13 +50,13 @@ statusbar_draw(int screen)
|
||||||
|
|
||||||
for(widget = vscreen.statusbar.widgets; widget; widget = widget->next)
|
for(widget = vscreen.statusbar.widgets; widget; widget = widget->next)
|
||||||
if (widget->alignment == AlignLeft)
|
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)
|
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)
|
for(widget = vscreen.statusbar.widgets; widget; widget = widget->next)
|
||||||
if (widget->alignment == AlignFlex)
|
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)
|
if(vscreen.statusbar.position == BarRight || vscreen.statusbar.position == BarLeft)
|
||||||
{
|
{
|
||||||
|
|
5
widget.c
5
widget.c
|
@ -24,8 +24,11 @@ calculate_alignments(Widget *widget)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(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;
|
widget->alignment = AlignRight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -6,11 +6,11 @@ extern awesome_config globalconf;
|
||||||
static char name[] = "focustitle";
|
static char name[] = "focustitle";
|
||||||
|
|
||||||
static int
|
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;
|
Client *sel = globalconf.focus->client;
|
||||||
VirtScreen vscreen = globalconf.screens[screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
int location = calculate_offset(vscreen.statusbar.width, 0, offset, align);
|
int location = calculate_offset(vscreen.statusbar.width, 0, offset, widget->alignment);
|
||||||
|
|
||||||
if(sel)
|
if(sel)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,21 +7,19 @@ extern awesome_config globalconf;
|
||||||
static char name[] = "layoutinfo";
|
static char name[] = "layoutinfo";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
layoutinfo_draw(DrawCtx *ctx, int screen, int offset,
|
layoutinfo_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused)))
|
||||||
int used __attribute__ ((unused)),
|
|
||||||
int align __attribute__ ((unused)))
|
|
||||||
{
|
{
|
||||||
int width = 0, location;
|
int width = 0, location;
|
||||||
VirtScreen vscreen = globalconf.screens[screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
Layout *l;
|
Layout *l;
|
||||||
for(l = vscreen.layouts ; l; l = l->next)
|
for(l = vscreen.layouts ; l; l = l->next)
|
||||||
width = MAX(width, (textwidth(ctx, vscreen.font, l->symbol)));
|
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,
|
drawtext(ctx, location, 0,
|
||||||
width,
|
width,
|
||||||
vscreen.statusbar.height,
|
vscreen.statusbar.height,
|
||||||
vscreen.font,
|
vscreen.font,
|
||||||
get_current_layout(screen)->symbol,
|
get_current_layout(widget->statusbar->screen)->symbol,
|
||||||
vscreen.colors_normal);
|
vscreen.colors_normal);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,14 @@ isoccupied(int screen, Tag *t)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
taglist_draw(DrawCtx *ctx,
|
taglist_draw(Widget *widget,
|
||||||
int screen,
|
DrawCtx *ctx,
|
||||||
int offset,
|
int offset,
|
||||||
int used __attribute__ ((unused)),
|
int used __attribute__ ((unused)))
|
||||||
int align __attribute__ ((unused)))
|
|
||||||
{
|
{
|
||||||
Tag *tag;
|
Tag *tag;
|
||||||
Client *sel = globalconf.focus->client;
|
Client *sel = globalconf.focus->client;
|
||||||
VirtScreen vscreen = globalconf.screens[screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
int w = 0, width = 0, location;
|
int w = 0, width = 0, location;
|
||||||
int flagsize;
|
int flagsize;
|
||||||
XColor *colors;
|
XColor *colors;
|
||||||
|
@ -44,7 +43,7 @@ taglist_draw(DrawCtx *ctx,
|
||||||
{
|
{
|
||||||
width += textwidth(ctx, vscreen.font, tag->name);
|
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;
|
width = 0;
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next)
|
for(tag = vscreen.tags; tag; tag = tag->next)
|
||||||
|
@ -56,9 +55,9 @@ taglist_draw(DrawCtx *ctx,
|
||||||
colors = vscreen.colors_normal;
|
colors = vscreen.colors_normal;
|
||||||
drawtext(ctx, location + width, 0, w,
|
drawtext(ctx, location + width, 0, w,
|
||||||
vscreen.statusbar.height, vscreen.font, tag->name, colors);
|
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,
|
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]);
|
colors[ColFG]);
|
||||||
width += w;
|
width += w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,14 @@ extern awesome_config globalconf;
|
||||||
static char name[] = "textbox";
|
static char name[] = "textbox";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
textbox_draw(DrawCtx *ctx,
|
textbox_draw(Widget *widget,
|
||||||
int screen __attribute__ ((unused)),
|
DrawCtx *ctx,
|
||||||
int offset,
|
int offset,
|
||||||
int used __attribute__ ((unused)),
|
int used __attribute__ ((unused)))
|
||||||
int align)
|
|
||||||
{
|
{
|
||||||
VirtScreen vscreen = globalconf.screens[screen];
|
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
||||||
int width = textwidth(ctx, vscreen.font, vscreen.statustext);
|
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,
|
drawtext(ctx, location, 0, width, vscreen.statusbar.height,
|
||||||
vscreen.font, vscreen.statustext, vscreen.colors_normal);
|
vscreen.font, vscreen.statustext, vscreen.colors_normal);
|
||||||
return width;
|
return width;
|
||||||
|
|
Loading…
Reference in New Issue