store location and width of each widgets

This commit is contained in:
Julien Danjou 2007-12-27 11:22:57 +01:00
parent 26ce9ee5d7
commit 33add50256
9 changed files with 79 additions and 71 deletions

View File

@ -232,6 +232,8 @@ struct Widget
Statusbar *statusbar;
int alignment;
void *data;
int location;
int width;
Widget *next;
};

8
tag.c
View File

@ -142,17 +142,17 @@ Tag **
get_current_tags(int screen)
{
Tag *tag, **tags = NULL;
int n = 0;
int n = 1;
tags = p_new(Tag *, n);
for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
if(tag->selected)
{
p_realloc(tags, ++n);
tags[n - 1] = tag;
p_realloc(&tags, ++n);
tags[n - 2] = tag;
}
/* finish with null */
p_realloc(tags, ++n);
tags[n - 1] = NULL;
return tags;

View File

@ -13,29 +13,33 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen,
get_current_tag(widget->statusbar->screen));
int location = widget_calculate_offset(vscreen.statusbar->width,
0,
offset,
widget->alignment);
widget->location = widget_calculate_offset(vscreen.statusbar->width,
0,
offset,
widget->alignment);
if(sel)
{
draw_text(ctx, location, 0, vscreen.statusbar->width - used,
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
vscreen.statusbar->height, vscreen.font, sel->name,
vscreen.colors_selected[ColFG],
vscreen.colors_selected[ColBG]);
if(sel->isfloating)
draw_circle(ctx, location, 0,
draw_circle(ctx, widget->location, 0,
(vscreen.font->height + 2) / 4,
sel->ismax,
vscreen.colors_selected[ColFG]);
}
else
draw_text(ctx, location, 0, vscreen.statusbar->width - used,
draw_text(ctx, widget->location, 0, vscreen.statusbar->width - used,
vscreen.statusbar->height, vscreen.font, NULL,
vscreen.colors_normal[ColFG],
vscreen.colors_normal[ColBG]);
return vscreen.statusbar->width - used;
widget->width = vscreen.statusbar->width - used;
return widget->width;
}
Widget *

View File

@ -29,18 +29,16 @@ static int
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused)))
{
int location, width;
widget->width = draw_get_image_width(widget->data);
width = draw_get_image_width(widget->data);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
location = widget_calculate_offset(widget->statusbar->width,
width,
offset,
widget->alignment);
draw_image(ctx, widget->location, 0, 0, widget->data);
draw_image(ctx, location, 0, 0, widget->data);
return width;
return widget->width;
}
static void

View File

@ -24,7 +24,7 @@
#include <confuse.h>
#include "widget.h"
#include "util.h"
#include "layout.h"
#include "tag.h"
extern AwesomeConf globalconf;
@ -34,15 +34,20 @@ layoutinfo_draw(Widget *widget,
int offset,
int used __attribute__ ((unused)))
{
int location = widget_calculate_offset(widget->statusbar->width,
widget->statusbar->height,
offset,
widget->alignment);
Tag **curtags = get_current_tags(widget->statusbar->screen);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->statusbar->height,
offset,
widget->alignment);
draw_image(ctx, location, 0, widget->statusbar->height,
get_current_layout(widget->statusbar->screen)->image);
widget->width = widget->statusbar->height;
return widget->statusbar->height;
draw_image(ctx, widget->location, 0, widget->statusbar->height,
curtags[0]->layout->image);
p_delete(&curtags);
return widget->width;
}
Widget *

View File

@ -35,12 +35,10 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
{
unsigned long *data, pixel;
Atom type;
int format, location, width, height, size, i;
int format, width, height, size, i;
unsigned long items, rest;
unsigned char *image, *imgdata;
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen,
get_current_tag(widget->statusbar->screen));
Client *sel = globalconf.focus->client;
if(!sel)
return 0;
@ -78,17 +76,19 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
imgdata[2] = pixel & 0xff; /* B */
}
location = widget_calculate_offset(vscreen.statusbar->width,
width,
offset,
widget->alignment);
widget->location = widget_calculate_offset(widget->statusbar->width,
width,
offset,
widget->alignment);
draw_image_from_argb_data(ctx, location, 0, width, height, vscreen.statusbar->height, image);
draw_image_from_argb_data(ctx, widget->location, 0, width, height, widget->statusbar->height, image);
p_delete(&image);
XFree(data);
return vscreen.statusbar->height;
widget->width = widget->statusbar->height;
return widget->width;
}
Widget *

View File

@ -39,40 +39,40 @@ static int
progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused)))
{
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int location, width, pwidth, margin, height;
int width, pwidth, margin, height;
Data *d = widget->data;
height = vscreen.statusbar->height / 2;
margin = (vscreen.statusbar->height - height) / 2 - 1;
height = widget->statusbar->height / 2;
margin = (widget->statusbar->height - height) / 2 - 1;
width = d->width - (margin * 2);
location = widget_calculate_offset(vscreen.statusbar->width,
d->width,
offset,
widget->alignment) + margin;
widget->location = widget_calculate_offset(widget->statusbar->width,
d->width,
offset,
widget->alignment) + margin;
pwidth = d->percent ? (width * d->percent) / 100 : 0;
draw_rectangle(ctx,
location + 1, margin,
widget->location + 1, margin,
width, height,
False, d->fg);
if(pwidth > 0)
draw_rectangle(ctx,
location + 1, margin + 1,
widget->location + 1, margin + 1,
pwidth, height - 2,
True, d->fg);
if(width - pwidth - 2 > 0)
draw_rectangle(ctx,
location + pwidth + 2, margin + 1,
widget->location + pwidth + 2, margin + 1,
width - pwidth - 2, height - 2,
True, d->bg);
return d->width;
widget->width = d->width;
return widget->width;
}
static void

View File

@ -65,21 +65,20 @@ taglist_draw(Widget *widget,
Tag *tag;
Client *sel = globalconf.focus->client;
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int w = 0, width = 0, location;
int flagsize;
int w = 0, flagsize;
XColor *colors;
flagsize = (vscreen.font->height + 2) / 4;
for(tag = vscreen.tags; tag; tag = tag->next)
width += textwidth(ctx, vscreen.font, tag->name);
widget->width += textwidth(ctx, vscreen.font, tag->name);
location = widget_calculate_offset(vscreen.statusbar->width,
width,
offset,
widget->alignment);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
width = 0;
widget->width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
{
w = textwidth(ctx, vscreen.font, tag->name);
@ -89,21 +88,21 @@ taglist_draw(Widget *widget,
colors = vscreen.colors_urgent;
else
colors = vscreen.colors_normal;
draw_text(ctx, location + width, 0, w,
draw_text(ctx, widget->location + widget->width, 0, w,
vscreen.statusbar->height,
vscreen.font,
tag->name,
colors[ColFG],
colors[ColBG]);
if(isoccupied(widget->statusbar->screen, tag))
draw_rectangle(ctx, location + width, 0, flagsize, flagsize,
draw_rectangle(ctx, widget->location + widget->width, 0, flagsize, flagsize,
sel && is_client_tagged(sel,
tag,
widget->statusbar->screen),
colors[ColFG]);
width += w;
widget->width += w;
}
return width;
return widget->width;
}
Widget *

View File

@ -47,18 +47,18 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused)))
{
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
int width, location;
Data *d = widget->data;
width = textwidth(ctx, vscreen.font, d->text);
location = widget_calculate_offset(vscreen.statusbar->width,
width,
offset,
widget->alignment);
widget->width = textwidth(ctx, vscreen.font, d->text);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
draw_text(ctx, location, 0, width, vscreen.statusbar->height,
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
vscreen.font, d->text, d->fg, d->bg);
return width;
return widget->width;
}
static void