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>
|
2006-03-09 04:15:43 +03:00
|
|
|
#include <stdlib.h>
|
2006-02-10 00:48:01 +03:00
|
|
|
|
|
|
|
#include "wm.h"
|
|
|
|
|
2006-06-08 12:54:19 +04:00
|
|
|
Bar *free_bars = nil;
|
2006-04-03 00:53:56 +04:00
|
|
|
|
2006-04-12 12:44:07 +04:00
|
|
|
Bar *
|
2006-06-20 06:13:29 +04:00
|
|
|
create_bar(Bar **b_link, char *name)
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
|
|
|
static unsigned int id = 1;
|
2006-06-08 12:54:19 +04:00
|
|
|
Bar **i, *b = bar_of_name(name);;
|
2006-05-01 22:53:30 +04:00
|
|
|
if(b)
|
|
|
|
return b;
|
2006-06-08 12:54:19 +04:00
|
|
|
|
|
|
|
if(free_bars) {
|
|
|
|
b = free_bars;
|
|
|
|
free_bars = b->next;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
b = cext_emallocz(sizeof(Bar));
|
|
|
|
|
2006-05-01 22:53:30 +04:00
|
|
|
b->id = id++;
|
|
|
|
cext_strlcpy(b->name, name, sizeof(b->name));
|
2006-06-19 12:28:37 +04:00
|
|
|
b->color = def.normcolor;
|
2006-06-08 12:54:19 +04:00
|
|
|
|
2006-06-20 06:13:29 +04:00
|
|
|
for(i=b_link; *i; i=&(*i)->next)
|
|
|
|
if(strcmp((*i)->name, name) >= 0)
|
2006-06-17 15:32:49 +04:00
|
|
|
break;
|
2006-06-08 12:54:19 +04:00
|
|
|
b->next = *i;
|
|
|
|
*i = b;
|
|
|
|
|
2006-05-01 22:53:30 +04:00
|
|
|
return b;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-20 06:13:29 +04:00
|
|
|
destroy_bar(Bar **b_link, Bar *b)
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
2006-06-08 12:54:19 +04:00
|
|
|
Bar **i;
|
2006-06-20 06:13:29 +04:00
|
|
|
for(i=b_link; *i && *i != b; i=&(*i)->next);
|
2006-06-08 12:54:19 +04:00
|
|
|
*i = b->next;
|
|
|
|
|
|
|
|
b->next = free_bars;
|
|
|
|
free_bars = b;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2006-02-24 12:38:48 +03:00
|
|
|
unsigned int
|
2006-04-12 12:44:07 +04:00
|
|
|
height_of_bar()
|
2006-02-24 12:38:48 +03:00
|
|
|
{
|
2006-04-11 16:23:13 +04:00
|
|
|
enum { BAR_PADDING = 4 };
|
2006-06-19 12:28:37 +04:00
|
|
|
return def.font.ascent + def.font.descent + BAR_PADDING;
|
2006-02-24 12:38:48 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 20:32:35 +03:00
|
|
|
void
|
2006-04-12 12:44:07 +04:00
|
|
|
resize_bar()
|
2006-02-10 20:32:35 +03:00
|
|
|
{
|
2006-06-08 12:54:19 +04:00
|
|
|
View *v;
|
|
|
|
Area *a;
|
|
|
|
Frame *f;
|
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
brect = rect;
|
2006-04-12 12:44:07 +04:00
|
|
|
brect.height = height_of_bar();
|
2006-03-23 01:49:18 +03:00
|
|
|
brect.y = rect.height - brect.height;
|
|
|
|
XMoveResizeWindow(dpy, barwin, brect.x, brect.y, brect.width, brect.height);
|
|
|
|
XSync(dpy, False);
|
|
|
|
XFreePixmap(dpy, barpmap);
|
|
|
|
barpmap = XCreatePixmap(dpy, barwin, brect.width, brect.height,
|
|
|
|
DefaultDepth(dpy, screen));
|
|
|
|
XSync(dpy, False);
|
2006-02-10 20:32:35 +03:00
|
|
|
draw_bar();
|
2006-06-08 12:54:19 +04:00
|
|
|
|
|
|
|
for(v=view; v; v=v->next) {
|
|
|
|
for(a = v->area; a; a=a->next) {
|
2006-03-11 23:48:02 +03:00
|
|
|
a->rect.height = rect.height - brect.height;
|
2006-04-06 19:03:12 +04:00
|
|
|
arrange_column(a, False);
|
2006-02-19 17:40:44 +03:00
|
|
|
}
|
2006-06-08 12:54:19 +04:00
|
|
|
for(f=v->area->frame; f; f=f->anext) {
|
2006-03-15 18:00:39 +03:00
|
|
|
resize_client(f->client, &f->rect, False);
|
2006-03-11 23:48:02 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-10 20:32:35 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
void
|
|
|
|
draw_bar()
|
|
|
|
{
|
2006-06-20 06:13:29 +04:00
|
|
|
unsigned int i = 0, w = 0, nb, size = 0;
|
2006-04-23 22:00:47 +04:00
|
|
|
BlitzDraw d = { 0 };
|
2006-06-20 06:13:29 +04:00
|
|
|
Bar *b = nil, *prev = nil;
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-03-23 01:49:18 +03:00
|
|
|
d.gc = bargc;
|
|
|
|
d.drawable = barpmap;
|
|
|
|
d.rect = brect;
|
2006-03-23 22:48:26 +03:00
|
|
|
d.rect.x = d.rect.y = 0;
|
2006-06-19 12:28:37 +04:00
|
|
|
d.font = def.font;
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-19 12:28:37 +04:00
|
|
|
d.color = def.normcolor;
|
2006-06-12 17:20:03 +04:00
|
|
|
blitz_drawlabel(&d);
|
|
|
|
blitz_drawborder(&d);
|
2006-03-24 15:36:35 +03:00
|
|
|
|
2006-06-20 06:13:29 +04:00
|
|
|
if(!lbar && !rbar)
|
2006-05-29 12:08:29 +04:00
|
|
|
goto MapBar;
|
2006-03-23 22:48:26 +03:00
|
|
|
|
2006-06-20 06:13:29 +04:00
|
|
|
for(b=lbar, nb=2 ;nb; --nb && (b = rbar))
|
|
|
|
for(; b && (w < brect.width); b=b->next, size++) {
|
|
|
|
b->rect.x = 0;
|
|
|
|
b->rect.y = 0;
|
|
|
|
b->rect.width = brect.height;
|
|
|
|
if(strlen(b->data))
|
|
|
|
b->rect.width += blitz_textwidth(&def.font, b->data);
|
|
|
|
b->rect.height = brect.height;
|
|
|
|
w += b->rect.width;
|
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-08 12:54:19 +04:00
|
|
|
if(b) { /* give all bars same width */
|
2006-06-20 06:13:29 +04:00
|
|
|
/* finish counting */
|
|
|
|
for( ;nb; b = rbar, nb--)
|
|
|
|
for(; b; b=b->next, size++);
|
|
|
|
|
2006-06-08 12:54:19 +04:00
|
|
|
w = brect.width / size;
|
2006-06-20 06:13:29 +04:00
|
|
|
for(b = lbar, nb=2 ;nb; b = rbar, nb--) {
|
|
|
|
for(; b; b=b->next) {
|
|
|
|
b->rect.x = i * w;
|
|
|
|
b->rect.width = w;
|
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
2006-03-24 15:36:35 +03:00
|
|
|
}
|
2006-06-20 06:13:29 +04:00
|
|
|
else { /* expand rbar properly */
|
|
|
|
if(rbar)
|
|
|
|
rbar->rect.width += (brect.width - w);
|
|
|
|
for(b=lbar, nb=2 ;nb--; b = rbar)
|
|
|
|
for(; b; prev = b, b=b->next)
|
|
|
|
if(prev) b->rect.x = prev->rect.x + prev->rect.width;
|
2006-03-26 20:21:12 +04:00
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-20 06:13:29 +04:00
|
|
|
for(b=lbar, nb=2 ;nb; b=rbar, nb--)
|
|
|
|
for(; b; b=b->next) {
|
|
|
|
d.color = b->color;
|
|
|
|
d.rect = b->rect;
|
|
|
|
d.data = b->data;
|
|
|
|
/* XXX: This is broken; everything shoult align EAST */
|
|
|
|
if(b == rbar)
|
|
|
|
d.align = EAST;
|
|
|
|
else
|
|
|
|
d.align = CENTER;
|
|
|
|
blitz_drawlabel(&d);
|
|
|
|
blitz_drawborder(&d);
|
|
|
|
}
|
2006-05-29 12:08:29 +04:00
|
|
|
MapBar:
|
2006-03-23 01:49:18 +03:00
|
|
|
XCopyArea(dpy, barpmap, barwin, bargc, 0, 0, brect.width, brect.height, 0, 0);
|
|
|
|
XSync(dpy, False);
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2006-04-12 12:44:07 +04:00
|
|
|
Bar *
|
|
|
|
bar_of_name(const char *name)
|
2006-03-09 04:15:43 +03:00
|
|
|
{
|
2006-03-31 09:57:33 +04:00
|
|
|
static char buf[256];
|
2006-06-08 12:54:19 +04:00
|
|
|
Bar *b;
|
2006-03-09 04:15:43 +03:00
|
|
|
|
2006-03-23 18:12:06 +03:00
|
|
|
cext_strlcpy(buf, name, sizeof(buf));
|
2006-06-17 15:32:49 +04:00
|
|
|
for(b=lbar; b && strncmp(b->name, name, sizeof(b->name)); b=b->next);
|
2006-06-08 12:54:19 +04:00
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bar *
|
|
|
|
bar_of_id(unsigned short id)
|
|
|
|
{
|
|
|
|
Bar *b;
|
2006-06-17 15:32:49 +04:00
|
|
|
for(b=lbar; b && b->id != id; b=b->next);
|
2006-06-08 12:54:19 +04:00
|
|
|
return b;
|
2006-03-09 04:15:43 +03:00
|
|
|
}
|