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.
|
|
|
|
*/
|
|
|
|
|
2006-06-27 06:21:09 +04:00
|
|
|
#include <math.h>
|
2006-02-10 00:48:01 +03:00
|
|
|
#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-27 06:21:09 +04:00
|
|
|
Bar **i, *b = bar_of_name(*b_link, 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-30 04:02:52 +04:00
|
|
|
b->brush = screen->bbrush;
|
2006-06-22 13:03:42 +04:00
|
|
|
b->brush.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-20 17:37:50 +04:00
|
|
|
Bar **p;
|
|
|
|
for(p=b_link; *p && *p != b; p=&(*p)->next);
|
|
|
|
*p = b->next;
|
2006-06-08 12:54:19 +04:00
|
|
|
|
|
|
|
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-06-30 04:02:52 +04:00
|
|
|
resize_bar(WMScreen *s)
|
2006-02-10 20:32:35 +03:00
|
|
|
{
|
2006-06-08 12:54:19 +04:00
|
|
|
View *v;
|
|
|
|
Area *a;
|
|
|
|
Frame *f;
|
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
s->brect = s->rect;
|
|
|
|
s->brect.height = height_of_bar();
|
|
|
|
s->brect.y = s->rect.height - s->brect.height;
|
|
|
|
XMoveResizeWindow(blz.display, s->barwin, s->brect.x, s->brect.y, s->brect.width, s->brect.height);
|
2006-06-22 13:03:42 +04:00
|
|
|
XSync(blz.display, False);
|
2006-06-30 04:02:52 +04:00
|
|
|
draw_bar(s);
|
2006-06-08 12:54:19 +04:00
|
|
|
|
|
|
|
for(v=view; v; v=v->next) {
|
|
|
|
for(a = v->area; a; a=a->next) {
|
2006-06-30 04:02:52 +04:00
|
|
|
a->rect.height = s->rect.height - s->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
|
2006-06-30 04:02:52 +04:00
|
|
|
draw_bar(WMScreen *s)
|
2006-02-10 00:48:01 +03:00
|
|
|
{
|
2006-06-27 06:21:09 +04:00
|
|
|
unsigned int width, tw, nb, size;
|
|
|
|
float shrink;
|
|
|
|
Bar *b, *tb, *largest, **pb;
|
2006-06-22 13:03:42 +04:00
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
blitz_draw_tile(&s->bbrush);
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
if(!s->lbar && !s->rbar)
|
2006-05-29 12:08:29 +04:00
|
|
|
goto MapBar;
|
2006-03-23 22:48:26 +03:00
|
|
|
|
2006-06-27 06:21:09 +04:00
|
|
|
largest = b = tb = nil;
|
|
|
|
tw = width = nb = size = 0;
|
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar))
|
2006-06-27 06:21:09 +04:00
|
|
|
for(; b; b=b->next) {
|
2006-06-27 11:14:10 +04:00
|
|
|
b->brush.rect.x = b->brush.rect.y = 0;
|
2006-06-30 04:02:52 +04:00
|
|
|
b->brush.rect.width = s->brect.height;
|
2006-06-22 13:46:39 +04:00
|
|
|
if(b->text && strlen(b->text))
|
|
|
|
b->brush.rect.width += blitz_textwidth(b->brush.font, b->text);
|
2006-06-30 04:02:52 +04:00
|
|
|
b->brush.rect.height = s->brect.height;
|
2006-06-27 06:21:09 +04:00
|
|
|
width += b->brush.rect.width;
|
2006-06-20 06:13:29 +04:00
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-27 06:21:09 +04:00
|
|
|
/* Not enough room. Shrink bars until they all fit */
|
2006-06-30 04:02:52 +04:00
|
|
|
if(width > s->brect.width) {
|
|
|
|
for(b=s->lbar, nb=2 ;nb; --nb && (b = s->rbar))
|
2006-06-27 06:21:09 +04:00
|
|
|
for(; b; b=b->next) {
|
|
|
|
for(pb=&largest; *pb; pb=&(*pb)->smaller)
|
|
|
|
if((*pb)->brush.rect.width < b->brush.rect.width) break;
|
|
|
|
b->smaller = *pb;
|
|
|
|
*pb = b;
|
2006-06-20 06:13:29 +04:00
|
|
|
}
|
2006-06-27 06:21:09 +04:00
|
|
|
for(tb=largest; tb; tb=tb->smaller) {
|
|
|
|
width -= tb->brush.rect.width;
|
|
|
|
tw += tb->brush.rect.width;
|
2006-06-30 04:02:52 +04:00
|
|
|
shrink = (s->brect.width - width) / (float)tw;
|
2006-06-27 11:14:10 +04:00
|
|
|
if(tb->smaller)
|
2006-06-27 06:21:09 +04:00
|
|
|
if(tb->brush.rect.width * shrink >= tb->smaller->brush.rect.width)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(b=largest; b != tb->smaller; b=b->smaller)
|
|
|
|
b->brush.rect.width = floor(b->brush.rect.width * shrink);
|
|
|
|
width += tw * shrink;
|
|
|
|
tb=nil;
|
2006-03-26 20:21:12 +04:00
|
|
|
}
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-06-30 04:02:52 +04:00
|
|
|
for(b=s->lbar, nb=2 ;nb; b=s->rbar, nb--)
|
2006-06-27 06:21:09 +04:00
|
|
|
for(; b; tb = b, b=b->next) {
|
2006-06-30 04:02:52 +04:00
|
|
|
if(b == s->rbar) {
|
2006-06-22 13:03:42 +04:00
|
|
|
b->brush.align = EAST;
|
2006-06-30 04:02:52 +04:00
|
|
|
s->rbar->brush.rect.width += (s->brect.width - width);
|
2006-06-27 06:21:09 +04:00
|
|
|
}else
|
|
|
|
b->brush.align = CENTER;
|
|
|
|
if(tb)
|
|
|
|
b->brush.rect.x = tb->brush.rect.x + tb->brush.rect.width;
|
2006-06-22 14:00:18 +04:00
|
|
|
blitz_draw_label(&b->brush, b->text);
|
2006-06-20 06:13:29 +04:00
|
|
|
}
|
2006-05-29 12:08:29 +04:00
|
|
|
MapBar:
|
2006-06-30 04:02:52 +04:00
|
|
|
XCopyArea(blz.display, s->bbrush.drawable, s->barwin, s->bbrush.gc, 0, 0,
|
|
|
|
s->brect.width, s->brect.height, 0, 0);
|
2006-06-22 13:03:42 +04:00
|
|
|
XSync(blz.display, False);
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
2006-04-12 12:44:07 +04:00
|
|
|
Bar *
|
2006-06-27 06:21:09 +04:00
|
|
|
bar_of_name(Bar *b_link, 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-27 06:21:09 +04:00
|
|
|
for(b=b_link; b; b=b->next)
|
|
|
|
if(!strncmp(b->name, name, sizeof(b->name))) break;
|
2006-06-08 12:54:19 +04:00
|
|
|
return b;
|
2006-03-09 04:15:43 +03:00
|
|
|
}
|