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; Statusbar *statusbar;
int alignment; int alignment;
void *data; void *data;
int location;
int width;
Widget *next; Widget *next;
}; };

8
tag.c
View File

@ -142,17 +142,17 @@ Tag **
get_current_tags(int screen) get_current_tags(int screen)
{ {
Tag *tag, **tags = NULL; 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) for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
if(tag->selected) if(tag->selected)
{ {
p_realloc(tags, ++n); p_realloc(&tags, ++n);
tags[n - 1] = tag; tags[n - 2] = tag;
} }
/* finish with null */ /* finish with null */
p_realloc(tags, ++n);
tags[n - 1] = NULL; tags[n - 1] = NULL;
return tags; 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]; VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen, Client *sel = focus_get_latest_client_for_tag(widget->statusbar->screen,
get_current_tag(widget->statusbar->screen)); get_current_tag(widget->statusbar->screen));
int location = widget_calculate_offset(vscreen.statusbar->width,
0, widget->location = widget_calculate_offset(vscreen.statusbar->width,
offset, 0,
widget->alignment); offset,
widget->alignment);
if(sel) 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.statusbar->height, vscreen.font, sel->name,
vscreen.colors_selected[ColFG], vscreen.colors_selected[ColFG],
vscreen.colors_selected[ColBG]); vscreen.colors_selected[ColBG]);
if(sel->isfloating) if(sel->isfloating)
draw_circle(ctx, location, 0, draw_circle(ctx, widget->location, 0,
(vscreen.font->height + 2) / 4, (vscreen.font->height + 2) / 4,
sel->ismax, sel->ismax,
vscreen.colors_selected[ColFG]); vscreen.colors_selected[ColFG]);
} }
else 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.statusbar->height, vscreen.font, NULL,
vscreen.colors_normal[ColFG], vscreen.colors_normal[ColFG],
vscreen.colors_normal[ColBG]); vscreen.colors_normal[ColBG]);
return vscreen.statusbar->width - used;
widget->width = vscreen.statusbar->width - used;
return widget->width;
} }
Widget * Widget *

View File

@ -29,18 +29,16 @@ static int
iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) 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, draw_image(ctx, widget->location, 0, 0, widget->data);
width,
offset,
widget->alignment);
draw_image(ctx, location, 0, 0, widget->data); return widget->width;
return width;
} }
static void static void

View File

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

View File

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

View File

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

View File

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

View File

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