[taglist] Honors style; use pointers instead of hard copies
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
5397e10a0f
commit
c9f8d4e859
|
@ -81,6 +81,17 @@ tag_isurgent(tag_t *t)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static style_t *
|
||||||
|
taglist_style_get(tag_t *tag, VirtScreen *vs)
|
||||||
|
{
|
||||||
|
if(tag->selected)
|
||||||
|
return &vs->styles.focus;
|
||||||
|
else if(tag_isurgent(tag))
|
||||||
|
return &vs->styles.urgent;
|
||||||
|
|
||||||
|
return &vs->styles.normal;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
taglist_text_get(tag_t *tag, taglist_data_t *data)
|
taglist_text_get(tag_t *tag, taglist_data_t *data)
|
||||||
{
|
{
|
||||||
|
@ -101,27 +112,28 @@ taglist_draw(widget_t *widget,
|
||||||
tag_t *tag;
|
tag_t *tag;
|
||||||
taglist_data_t *data = widget->data;
|
taglist_data_t *data = widget->data;
|
||||||
client_t *sel = globalconf.focus->client;
|
client_t *sel = globalconf.focus->client;
|
||||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
VirtScreen *vscreen = &globalconf.screens[widget->statusbar->screen];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
style_t style = vscreen.styles.normal;
|
style_t **styles;
|
||||||
area_t *area, rectangle = { 0, 0, 0, 0, NULL, NULL };
|
area_t *area, rectangle = { 0, 0, 0, 0, NULL, NULL };
|
||||||
char **text;
|
char **text;
|
||||||
|
|
||||||
rectangle.width = rectangle.height = (style.font->height + 2) / 3;
|
|
||||||
|
|
||||||
widget->area.width = 0;
|
widget->area.width = 0;
|
||||||
|
|
||||||
area_list_wipe(&data->draw_area);
|
area_list_wipe(&data->draw_area);
|
||||||
|
|
||||||
text = p_new(char *, 1);
|
text = p_new(char *, 1);
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++)
|
styles = p_new(style_t *, 1);
|
||||||
|
for(tag = vscreen->tags; tag; tag = tag->next, i++)
|
||||||
{
|
{
|
||||||
area = p_new(area_t, 1);
|
|
||||||
p_realloc(&text, i + 1);
|
p_realloc(&text, i + 1);
|
||||||
|
p_realloc(&styles, i + 1);
|
||||||
|
styles[i] = taglist_style_get(tag, vscreen);
|
||||||
|
area = p_new(area_t, 1);
|
||||||
text[i] = taglist_text_get(tag, data);
|
text[i] = taglist_text_get(tag, data);
|
||||||
text[i] = tag_markup_parse(tag, text[i], a_strlen(text[i]));
|
text[i] = tag_markup_parse(tag, text[i], a_strlen(text[i]));
|
||||||
*area = draw_text_extents(ctx->connection, ctx->default_screen,
|
*area = draw_text_extents(ctx->connection, ctx->default_screen,
|
||||||
style.font, text[i]);
|
styles[i]->font, text[i]);
|
||||||
area->x = widget->area.width;
|
area->x = widget->area.width;
|
||||||
area->height = widget->statusbar->height;
|
area->height = widget->statusbar->height;
|
||||||
area_list_append(&data->draw_area, area);
|
area_list_append(&data->draw_area, area);
|
||||||
|
@ -137,21 +149,26 @@ taglist_draw(widget_t *widget,
|
||||||
if(!widget->user_supplied_y)
|
if(!widget->user_supplied_y)
|
||||||
widget->area.y = 0;
|
widget->area.y = 0;
|
||||||
|
|
||||||
for(area = data->draw_area, tag = vscreen.tags, i = 0;
|
for(area = data->draw_area, tag = vscreen->tags, i = 0;
|
||||||
tag && area;
|
tag && area;
|
||||||
tag = tag->next, area = area->next, i++)
|
tag = tag->next, area = area->next, i++)
|
||||||
{
|
{
|
||||||
draw_text(ctx, *area, text[i], style);
|
draw_text(ctx, *area, text[i], *styles[i]);
|
||||||
|
p_delete(&text[i]);
|
||||||
|
|
||||||
if(tag_isoccupied(tag))
|
if(tag_isoccupied(tag))
|
||||||
{
|
{
|
||||||
|
rectangle.width = rectangle.height = (styles[i]->font->height + 2) / 3;
|
||||||
rectangle.x = area->x;
|
rectangle.x = area->x;
|
||||||
rectangle.y = area->y;
|
rectangle.y = area->y;
|
||||||
draw_rectangle(ctx, rectangle, 1.0,
|
draw_rectangle(ctx, rectangle, 1.0,
|
||||||
sel && is_client_tagged(sel, tag), style.fg);
|
sel && is_client_tagged(sel, tag), styles[i]->fg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p_delete(&text);
|
||||||
|
p_delete(&styles);
|
||||||
|
|
||||||
widget->area.height = widget->statusbar->height;
|
widget->area.height = widget->statusbar->height;
|
||||||
return widget->area.width;
|
return widget->area.width;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +176,7 @@ taglist_draw(widget_t *widget,
|
||||||
static void
|
static void
|
||||||
taglist_button_press(widget_t *widget, xcb_button_press_event_t *ev)
|
taglist_button_press(widget_t *widget, xcb_button_press_event_t *ev)
|
||||||
{
|
{
|
||||||
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
|
VirtScreen *vscreen = &globalconf.screens[widget->statusbar->screen];
|
||||||
Button *b;
|
Button *b;
|
||||||
tag_t *tag;
|
tag_t *tag;
|
||||||
char buf[4];
|
char buf[4];
|
||||||
|
@ -172,7 +189,7 @@ taglist_button_press(widget_t *widget, xcb_button_press_event_t *ev)
|
||||||
switch(widget->statusbar->position)
|
switch(widget->statusbar->position)
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++, area = area->next)
|
for(tag = vscreen->tags; tag; tag = tag->next, i++, area = area->next)
|
||||||
if(ev->event_x >= AREA_LEFT(*area)
|
if(ev->event_x >= AREA_LEFT(*area)
|
||||||
&& ev->event_x < AREA_RIGHT(*area))
|
&& ev->event_x < AREA_RIGHT(*area))
|
||||||
{
|
{
|
||||||
|
@ -182,7 +199,7 @@ taglist_button_press(widget_t *widget, xcb_button_press_event_t *ev)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++, area = area->next)
|
for(tag = vscreen->tags; tag; tag = tag->next, i++, area = area->next)
|
||||||
if(ev->event_y >= AREA_LEFT(*area)
|
if(ev->event_y >= AREA_LEFT(*area)
|
||||||
&& ev->event_y < AREA_RIGHT(*area))
|
&& ev->event_y < AREA_RIGHT(*area))
|
||||||
{
|
{
|
||||||
|
@ -192,7 +209,7 @@ taglist_button_press(widget_t *widget, xcb_button_press_event_t *ev)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Left:
|
case Left:
|
||||||
for(tag = vscreen.tags; tag; tag = tag->next, i++, area = area->next)
|
for(tag = vscreen->tags; tag; tag = tag->next, i++, area = area->next)
|
||||||
if(widget->statusbar->width - ev->event_y >= AREA_LEFT(*area)
|
if(widget->statusbar->width - ev->event_y >= AREA_LEFT(*area)
|
||||||
&& widget->statusbar->width - ev->event_y < AREA_RIGHT(*area))
|
&& widget->statusbar->width - ev->event_y < AREA_RIGHT(*area))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue