use Area in Widget

This commit is contained in:
Julien Danjou 2008-01-04 21:46:25 +01:00
parent e77729ed50
commit 6ca7d7b2db
10 changed files with 96 additions and 97 deletions

View File

@ -106,10 +106,8 @@ struct Widget
Alignment alignment;
/** Misc private data */
void *data;
/** Location on status bar */
int location;
/** Widget width */
int width;
/** Area */
Area area;
/** Buttons bindings */
Button *buttons;
/** Font */

View File

@ -76,7 +76,7 @@ handle_event_buttonpress(XEvent *e)
|| globalconf.screens[screen].statusbar->position == Bottom)
{
for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->x >= widget->location && ev->x <= widget->location + widget->width)
if(ev->x >= widget->area.x && ev->x <= widget->area.x + widget->area.width)
{
widget->button_press(widget, ev);
return;
@ -85,7 +85,7 @@ handle_event_buttonpress(XEvent *e)
else if(statusbar->position == Right)
{
for(widget = statusbar->widgets; widget; widget = widget->next)
if(ev->y >= widget->location && ev->y <= widget->location + widget->width)
if(ev->y >= widget->area.x && ev->y <= widget->area.x + widget->area.width)
{
widget->button_press(widget, ev);
return;
@ -94,8 +94,8 @@ handle_event_buttonpress(XEvent *e)
else
{
for(widget = statusbar->widgets; widget; widget = widget->next)
if(statusbar->width - ev->y >= widget->location
&& statusbar->width - ev->y <= widget->location + widget->width)
if(statusbar->width - ev->y >= widget->area.x
&& statusbar->width - ev->y <= widget->area.x + widget->area.width)
{
widget->button_press(widget, ev);
return;

View File

@ -44,31 +44,31 @@ focustitle_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
Data *d = widget->data;
Client *sel = focus_get_current_client(widget->statusbar->screen);
widget->location = widget_calculate_offset(widget->statusbar->width,
0,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
0,
offset,
widget->alignment);
if(sel)
{
draw_text(ctx, widget->location, 0,
draw_text(ctx, widget->area.x, 0,
widget->statusbar->width - used,
widget->statusbar->height,
d->align,
widget->font->height / 2, widget->font, sel->name,
d->fg, d->bg);
if(sel->isfloating)
draw_circle(ctx, widget->location, 0,
draw_circle(ctx, widget->area.x, 0,
(widget->font->height + 2) / 4,
sel->ismax, d->fg);
}
else
draw_rectangle(ctx, widget->location, 0,
draw_rectangle(ctx, widget->area.x, 0,
widget->statusbar->width - used, widget->statusbar->height, True, d->bg);
widget->width = widget->statusbar->width - used;
widget->area.width = widget->statusbar->width - used;
return widget->width;
return widget->area.width;
}
Widget *

View File

@ -38,18 +38,18 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset,
Area area = draw_get_image_size(d->image);
if(d->resize)
widget->width = ((double) widget->statusbar->height / area.height) * area.width;
widget->area.width = ((double) widget->statusbar->height / area.height) * area.width;
else
widget->width = area.width;
widget->area.width = area.width;
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width,
offset,
widget->alignment);
draw_image(ctx, widget->location, 0, d->resize ? widget->statusbar->height : 0, d->image);
draw_image(ctx, widget->area.x, 0, d->resize ? widget->statusbar->height : 0, d->image);
return widget->width;
return widget->area.width;
}
static void

View File

@ -34,19 +34,19 @@ layoutinfo_draw(Widget *widget,
int used __attribute__ ((unused)))
{
Tag **curtags = get_current_tags(widget->statusbar->screen);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->statusbar->height,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->statusbar->height,
offset,
widget->alignment);
widget->width = widget->statusbar->height;
widget->area.width = widget->statusbar->height;
draw_image(ctx, widget->location, 0, widget->statusbar->height,
draw_image(ctx, widget->area.x, 0, widget->statusbar->height,
curtags[0]->layout->image);
p_delete(&curtags);
return widget->width;
return widget->area.width;
}
Widget *

View File

@ -41,7 +41,7 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
if(!sel)
{
widget->width = 0;
widget->area.width = 0;
return 0;
}
@ -49,39 +49,40 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset,
if(r->icon && client_match_rule(sel, r))
{
area = draw_get_image_size(r->icon);
widget->width = ((double) widget->statusbar->height / (double) area.height) * area.width;
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
draw_image(ctx, widget->location, 0, widget->statusbar->height, r->icon);
widget->area.width = ((double) widget->statusbar->height / (double) area.height)
* area.width;
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width,
offset,
widget->alignment);
draw_image(ctx, widget->area.x, 0, widget->statusbar->height, r->icon);
return widget->width;
return widget->area.width;
}
if(!(icon = ewmh_get_window_icon(sel->win)))
{
widget->width = 0;
widget->area.width = 0;
return 0;
}
widget->width = ((double) widget->statusbar->height / (double) icon->height) * icon->width;
widget->area.width = ((double) widget->statusbar->height / (double) icon->height) * icon->width;
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width,
offset,
widget->alignment);
draw_image_from_argb_data(ctx,
widget->location, 0,
widget->area.x, 0,
icon->width, icon->height,
widget->statusbar->height, icon->image);
p_delete(&icon->image);
p_delete(&icon);
return widget->width;
return widget->area.width;
}
Widget *

View File

@ -66,12 +66,12 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
width = d->width - d->lpadding;
widget->location = widget_calculate_offset(widget->statusbar->width,
d->width,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
d->width,
offset,
widget->alignment);
left_offset = widget->location + d->lpadding;
left_offset = widget->area.x + d->lpadding;
for (i = 0; i < d->bars; i++)
{
@ -97,8 +97,8 @@ progressbar_draw(Widget *widget, DrawCtx *ctx, int offset,
margin_top += (pb_height + d->gap);
}
widget->width = d->width;
return widget->width;
widget->area.width = d->width;
return widget->area.width;
}
static void

View File

@ -70,17 +70,17 @@ taglist_draw(Widget *widget,
flagsize = (vscreen.font->height + 2) / 3;
widget->width = 0;
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
widget->width += textwidth(vscreen.font, tag->name) + vscreen.font->height;
widget->area.width += textwidth(vscreen.font, tag->name) + vscreen.font->height;
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width,
offset,
widget->alignment);
widget->width = 0;
widget->area.width = 0;
for(tag = vscreen.tags; tag; tag = tag->next)
{
w = textwidth(vscreen.font, tag->name) + vscreen.font->height;
@ -91,7 +91,7 @@ taglist_draw(Widget *widget,
else
colors = vscreen.colors_normal;
draw_text(ctx,
widget->location + widget->width, 0,
widget->area.x + widget->area.width, 0,
w, widget->statusbar->height,
AlignCenter,
vscreen.font->height / 2,
@ -100,12 +100,12 @@ taglist_draw(Widget *widget,
colors[ColFG],
colors[ColBG]);
if(isoccupied(tag))
draw_rectangle(ctx, widget->location + widget->width, 0, flagsize, flagsize,
draw_rectangle(ctx, widget->area.x + widget->area.width, 0, flagsize, flagsize,
sel && is_client_tagged(sel, tag), colors[ColFG]);
widget->width += w;
widget->area.width += w;
}
return widget->width;
return widget->area.width;
}
static void
@ -126,8 +126,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(ev->x >= widget->location + prev_width
&& ev->x <= widget->location + prev_width + width)
if(ev->x >= widget->area.x + prev_width
&& ev->x <= widget->area.x + prev_width + width)
{
snprintf(buf, sizeof(buf), "%d", i);
b->func(widget->statusbar->screen, buf);
@ -140,8 +140,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(ev->y >= widget->location + prev_width
&& ev->y <= widget->location + prev_width + width)
if(ev->y >= widget->area.x + prev_width
&& ev->y <= widget->area.x + prev_width + width)
{
snprintf(buf, sizeof(buf), "%d", i);
b->func(widget->statusbar->screen, buf);
@ -154,8 +154,8 @@ taglist_button_press(Widget *widget, XButtonPressedEvent *ev)
for(tag = vscreen.tags; tag; tag = tag->next, i++)
{
width = textwidth(vscreen.font, tag->name) + vscreen.font->height;
if(widget->statusbar->width - ev->y >= widget->location + prev_width
&& widget->statusbar->width - ev->y <= widget->location + prev_width + width)
if(widget->statusbar->width - ev->y >= widget->area.x + prev_width
&& widget->statusbar->width - ev->y <= widget->area.x + prev_width + width)
{
snprintf(buf, sizeof(buf), "%d", i);
b->func(widget->statusbar->screen, buf);

View File

@ -61,16 +61,16 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(!n)
{
widget->width = 0;
return widget->width;
widget->area.width = 0;
return widget->area.width;
}
box_width = (widget->statusbar->width - used) / n;
widget->location = widget_calculate_offset(widget->statusbar->width,
0,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
0,
offset,
widget->alignment);
for(c = globalconf.clients; c; c = c->next)
if(ISVISIBLE_ON_TB(c, widget->statusbar->screen))
@ -85,7 +85,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
area = draw_get_image_size(r->icon);
icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width;
draw_image(ctx,
widget->location + box_width * i,
widget->area.x + box_width * i,
0, widget->statusbar->height,
r->icon);
}
@ -95,7 +95,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
icon_width = ((double) widget->statusbar->height / (double) icon->height)
* icon->width;
draw_image_from_argb_data(ctx,
widget->location + box_width * i, 0,
widget->area.x + box_width * i, 0,
icon->width, icon->height,
widget->statusbar->height, icon->image);
p_delete(&icon->image);
@ -105,7 +105,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(sel == c)
{
draw_text(ctx, widget->location + icon_width + box_width * i, 0,
draw_text(ctx, widget->area.x + icon_width + box_width * i, 0,
box_width - icon_width,
widget->statusbar->height,
d->align,
@ -113,22 +113,22 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
d->fg_sel, d->bg_sel);
}
else
draw_text(ctx, widget->location + icon_width + box_width * i, 0,
draw_text(ctx, widget->area.x + icon_width + box_width * i, 0,
box_width - icon_width,
widget->statusbar->height,
d->align,
widget->font->height / 2, widget->font, c->name,
d->fg, d->bg);
if(c->isfloating)
draw_circle(ctx, widget->location + icon_width + box_width * i, 0,
draw_circle(ctx, widget->area.x + icon_width + box_width * i, 0,
(widget->font->height + 2) / 4,
c->ismax, d->fg);
i++;
}
widget->width = widget->statusbar->width - used;
widget->area.width = widget->statusbar->width - used;
return widget->width;
return widget->area.width;
}
static void
@ -148,7 +148,7 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
if(!n)
return;
box_width = widget->width / n;
box_width = widget->area.width / n;
if(ev->button == Button1 && CLEANMASK(ev->state) == NoSymbol)
{
@ -156,13 +156,13 @@ tasklist_button_press(Widget *widget, XButtonPressedEvent *ev)
{
case Top:
case Bottom:
ci = (ev->x - widget->location) / box_width;
ci = (ev->x - widget->area.x) / box_width;
break;
case Right:
ci = (ev->y - widget->location) / box_width;
ci = (ev->y - widget->area.x) / box_width;
break;
default:
ci = ((widget->statusbar->width - ev->y) - widget->location) / box_width;
ci = ((widget->statusbar->width - ev->y) - widget->area.x) / box_width;
break;
}
/* found first visible client */

View File

@ -42,19 +42,19 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
Data *d = widget->data;
if(d->width)
widget->width = d->width;
widget->area.width = d->width;
else
widget->width = textwidth(widget->font, d->text);
widget->area.width = textwidth(widget->font, d->text);
widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width,
offset,
widget->alignment);
widget->area.x = widget_calculate_offset(widget->statusbar->width,
widget->area.width,
offset,
widget->alignment);
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
draw_text(ctx, widget->area.x, 0, widget->area.width, widget->statusbar->height,
d->align, 0, widget->font, d->text, d->fg, d->bg);
return widget->width;
return widget->area.width;
}
static void