2006-02-10 00:48:01 +03:00
|
|
|
/*
|
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
Label *
|
|
|
|
new_label()
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
|
|
|
static unsigned int id = 1;
|
2006-02-10 17:59:30 +03:00
|
|
|
Label *l = cext_emallocz(sizeof(Label));
|
|
|
|
l->id = id++;
|
|
|
|
cext_strlcpy(l->colstr, def.selcolor, sizeof(l->colstr));
|
|
|
|
l->color = def.sel;
|
|
|
|
label = (Label **)cext_array_attach((void **)label, l, sizeof(Label *), &labelsz);
|
|
|
|
nlabel++;
|
|
|
|
return l;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-02-10 17:59:30 +03:00
|
|
|
detach_label(Label *l)
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
cext_array_detach((void **)label, l, &labelsz);
|
|
|
|
nlabel--;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2006-02-24 12:38:48 +03:00
|
|
|
unsigned int
|
|
|
|
bar_height()
|
|
|
|
{
|
|
|
|
return xfont->ascent + xfont->descent + 4;
|
|
|
|
}
|
|
|
|
|
2006-02-10 20:32:35 +03:00
|
|
|
void
|
|
|
|
update_bar_geometry()
|
|
|
|
{
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int i, j;
|
2006-02-10 20:32:35 +03:00
|
|
|
brect = rect;
|
2006-02-24 12:38:48 +03:00
|
|
|
brect.height = bar_height();
|
2006-02-10 20:32:35 +03:00
|
|
|
brect.y = rect.height - brect.height;
|
|
|
|
XMoveResizeWindow(dpy, winbar, brect.x, brect.y, brect.width, brect.height);
|
|
|
|
XSync(dpy, False);
|
|
|
|
XFreePixmap(dpy, pmapbar);
|
|
|
|
pmapbar = XCreatePixmap(dpy, winbar, brect.width, brect.height, DefaultDepth(dpy, screen));
|
|
|
|
XSync(dpy, False);
|
|
|
|
draw_bar();
|
2006-03-04 11:23:17 +03:00
|
|
|
for(i = 0; i < ntag; i++)
|
|
|
|
for(j = 1; j < tag[i]->narea; j++) {
|
|
|
|
update_area_geometry(tag[i]->area[j]);
|
|
|
|
arrange_area(tag[i]->area[j]);
|
2006-02-19 17:40:44 +03:00
|
|
|
}
|
2006-02-10 20:32:35 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
void
|
|
|
|
draw_bar()
|
|
|
|
{
|
2006-03-01 13:55:46 +03:00
|
|
|
unsigned int i;
|
2006-02-10 00:48:01 +03:00
|
|
|
unsigned int w = 0;
|
|
|
|
Draw d = { 0 };
|
|
|
|
|
|
|
|
d.align = WEST;
|
|
|
|
d.gc = gcbar;
|
|
|
|
d.drawable = pmapbar;
|
|
|
|
d.rect = brect;
|
|
|
|
d.rect.y = 0;
|
|
|
|
d.font = xfont;
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
if(!nlabel) { /* /default only */
|
2006-02-10 00:48:01 +03:00
|
|
|
d.color = def.sel;
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
}
|
|
|
|
else {
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
|
|
|
Label *l = label[i];
|
|
|
|
l->rect.x = l->rect.y = 0;
|
|
|
|
l->rect.height = brect.height;
|
2006-02-10 00:48:01 +03:00
|
|
|
if(i == iexpand)
|
|
|
|
continue;
|
2006-02-10 17:59:30 +03:00
|
|
|
l->rect.width = brect.height;
|
|
|
|
if(strlen(l->data)) {
|
|
|
|
if(!strncmp(l->data, "%m:", 3))
|
|
|
|
l->rect.width = brect.height / 2;
|
2006-02-10 00:48:01 +03:00
|
|
|
else
|
2006-02-10 17:59:30 +03:00
|
|
|
l->rect.width += XTextWidth(xfont, l->data, strlen(l->data));
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
w += l->rect.width;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if(w >= brect.width) {
|
|
|
|
/* failsafe mode, give all labels same width */
|
2006-02-10 17:59:30 +03:00
|
|
|
w = brect.width / nlabel;
|
|
|
|
for(i = 0; i < nlabel; i++) {
|
|
|
|
label[i]->rect.x = i * w;
|
|
|
|
label[i]->rect.width = w;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
i--;
|
2006-02-10 17:59:30 +03:00
|
|
|
label[i]->rect.width = brect.width - label[i]->rect.x;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-02-10 17:59:30 +03:00
|
|
|
label[iexpand]->rect.width = brect.width - w;
|
|
|
|
for(i = 1; i < nlabel; i++)
|
|
|
|
label[i]->rect.x = label[i - 1]->rect.x + label[i - 1]->rect.width;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
|
|
|
d.color = label[i]->color;
|
|
|
|
d.rect = label[i]->rect;
|
|
|
|
d.data = label[i]->data;
|
2006-02-10 00:48:01 +03:00
|
|
|
if(d.data && !strncmp(d.data, "%m:", 3))
|
|
|
|
blitz_drawmeter(dpy, &d);
|
|
|
|
else
|
|
|
|
blitz_drawlabel(dpy, &d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XCopyArea(dpy, pmapbar, winbar, gcbar, 0, 0, brect.width, brect.height, 0, 0);
|
|
|
|
XSync(dpy, False);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-03-01 09:51:04 +03:00
|
|
|
lid2index(unsigned short id)
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++)
|
|
|
|
if(label[i]->id == id)
|
2006-02-10 00:48:01 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|