2006-10-12 16:10:57 +02:00
|
|
|
/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
2006-02-09 22:48:01 +01:00
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
2006-10-20 10:07:55 +02:00
|
|
|
#include "wmii.h"
|
2006-06-26 22:21:09 -04:00
|
|
|
#include <math.h>
|
2006-02-09 22:48:01 +01:00
|
|
|
#include <string.h>
|
2006-03-09 02:15:43 +01:00
|
|
|
#include <stdlib.h>
|
2006-02-09 22:48:01 +01:00
|
|
|
|
2007-02-04 21:02:05 -05:00
|
|
|
Bar *free_bars = nil;
|
2006-04-02 22:53:56 +02:00
|
|
|
|
2006-04-12 10:44:07 +02:00
|
|
|
Bar *
|
2006-10-12 16:10:57 +02:00
|
|
|
create_bar(Bar **b_link, char *name) {
|
2007-02-12 01:24:24 -05:00
|
|
|
static uint id = 1;
|
2006-06-26 22:21:09 -04:00
|
|
|
Bar **i, *b = bar_of_name(*b_link, name);;
|
2006-10-12 16:10:57 +02:00
|
|
|
|
2006-05-01 20:53:30 +02:00
|
|
|
if(b)
|
|
|
|
return b;
|
2006-06-08 10:54:19 +02:00
|
|
|
if(free_bars) {
|
|
|
|
b = free_bars;
|
|
|
|
free_bars = b->next;
|
2006-07-05 17:40:55 -04:00
|
|
|
memset(b, 0, sizeof(*b));
|
2006-06-08 10:54:19 +02:00
|
|
|
}
|
|
|
|
else
|
2007-02-14 23:20:47 -05:00
|
|
|
b = emallocz(sizeof(Bar));
|
2006-05-01 20:53:30 +02:00
|
|
|
b->id = id++;
|
2006-10-12 16:10:57 +02:00
|
|
|
strncpy(b->name, name, sizeof(b->name));
|
2006-06-29 20:02:52 -04:00
|
|
|
b->brush = screen->bbrush;
|
2006-06-22 11:03:42 +02:00
|
|
|
b->brush.color = def.normcolor;
|
2007-02-05 21:56:03 -05:00
|
|
|
for(i = b_link; *i; i = &(*i)->next)
|
2006-06-19 22:13:29 -04:00
|
|
|
if(strcmp((*i)->name, name) >= 0)
|
2006-06-17 07:32:49 -04:00
|
|
|
break;
|
2006-06-08 10:54:19 +02:00
|
|
|
b->next = *i;
|
|
|
|
*i = b;
|
|
|
|
|
2006-05-01 20:53:30 +02:00
|
|
|
return b;
|
2006-02-09 22:48:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-10-12 16:10:57 +02:00
|
|
|
destroy_bar(Bar **b_link, Bar *b) {
|
2006-06-20 15:37:50 +02:00
|
|
|
Bar **p;
|
2006-10-12 16:10:57 +02:00
|
|
|
|
2007-02-05 21:56:03 -05:00
|
|
|
for(p = b_link; *p; p = &(*p)->next)
|
|
|
|
if(*p == b) break;
|
2006-06-20 15:37:50 +02:00
|
|
|
*p = b->next;
|
2006-06-08 10:54:19 +02:00
|
|
|
b->next = free_bars;
|
|
|
|
free_bars = b;
|
2006-02-09 22:48:01 +01:00
|
|
|
}
|
|
|
|
|
2006-02-10 18:32:35 +01:00
|
|
|
void
|
2006-10-12 16:10:57 +02:00
|
|
|
resize_bar(WMScreen *s) {
|
2006-06-08 10:54:19 +02:00
|
|
|
View *v;
|
|
|
|
|
2006-06-29 20:02:52 -04:00
|
|
|
s->brect = s->rect;
|
2006-10-12 16:12:22 +02:00
|
|
|
s->brect.height = labelh(&def.font);
|
2006-06-29 20:02:52 -04:00
|
|
|
s->brect.y = s->rect.height - s->brect.height;
|
2006-07-03 18:41:14 +02:00
|
|
|
XMoveResizeWindow(blz.dpy, s->barwin, s->brect.x, s->brect.y, s->brect.width, s->brect.height);
|
|
|
|
XSync(blz.dpy, False);
|
2006-06-29 20:02:52 -04:00
|
|
|
draw_bar(s);
|
2007-02-05 21:56:03 -05:00
|
|
|
for(v = view; v; v = v->next)
|
2006-06-30 02:02:44 -04:00
|
|
|
arrange_view(v);
|
2006-02-10 18:32:35 +01:00
|
|
|
}
|
|
|
|
|
2006-02-09 22:48:01 +01:00
|
|
|
void
|
2006-10-12 16:10:57 +02:00
|
|
|
draw_bar(WMScreen *s) {
|
2007-02-12 01:24:24 -05:00
|
|
|
uint width, tw, nb, size;
|
2006-06-26 22:21:09 -04:00
|
|
|
float shrink;
|
|
|
|
Bar *b, *tb, *largest, **pb;
|
2006-06-22 11:03:42 +02:00
|
|
|
|
2006-10-12 16:12:22 +02:00
|
|
|
draw_tile(&s->bbrush);
|
2006-06-29 20:02:52 -04:00
|
|
|
if(!s->lbar && !s->rbar)
|
2006-05-29 10:08:29 +02:00
|
|
|
goto MapBar;
|
2007-02-04 21:02:05 -05:00
|
|
|
largest = b = tb = nil;
|
2006-06-26 22:21:09 -04:00
|
|
|
tw = width = nb = size = 0;
|
2007-02-07 12:45:00 -05:00
|
|
|
for(b = s->lbar, nb = 2; nb; --nb && (b = s->rbar))
|
2006-06-26 22:21:09 -04:00
|
|
|
for(; b; b=b->next) {
|
2006-06-27 03:14:10 -04:00
|
|
|
b->brush.rect.x = b->brush.rect.y = 0;
|
2007-02-05 19:25:29 -05:00
|
|
|
b->brush.rect.width = def.font.height & ~1;
|
2006-06-22 11:46:39 +02:00
|
|
|
if(b->text && strlen(b->text))
|
2006-10-12 16:12:22 +02:00
|
|
|
b->brush.rect.width += textwidth(b->brush.font, b->text);
|
2006-06-29 20:02:52 -04:00
|
|
|
b->brush.rect.height = s->brect.height;
|
2006-06-26 22:21:09 -04:00
|
|
|
width += b->brush.rect.width;
|
2006-06-19 22:13:29 -04:00
|
|
|
}
|
2006-06-26 22:21:09 -04:00
|
|
|
/* Not enough room. Shrink bars until they all fit */
|
2006-06-29 20:02:52 -04:00
|
|
|
if(width > s->brect.width) {
|
2007-02-07 12:45:00 -05:00
|
|
|
for(b = s->lbar, nb = 2; nb; --nb && (b = s->rbar))
|
2007-02-05 21:56:03 -05:00
|
|
|
for(; b; b = b->next) {
|
|
|
|
for(pb = &largest; *pb; pb = &(*pb)->smaller)
|
|
|
|
if((*pb)->brush.rect.width < b->brush.rect.width)
|
|
|
|
break;
|
2006-06-26 22:21:09 -04:00
|
|
|
b->smaller = *pb;
|
|
|
|
*pb = b;
|
2006-06-19 22:13:29 -04:00
|
|
|
}
|
2007-02-05 21:56:03 -05:00
|
|
|
for(tb = largest; tb; tb = tb->smaller) {
|
2006-06-26 22:21:09 -04:00
|
|
|
width -= tb->brush.rect.width;
|
|
|
|
tw += tb->brush.rect.width;
|
2006-06-29 20:02:52 -04:00
|
|
|
shrink = (s->brect.width - width) / (float)tw;
|
2006-06-27 03:14:10 -04:00
|
|
|
if(tb->smaller)
|
2006-06-26 22:21:09 -04:00
|
|
|
if(tb->brush.rect.width * shrink >= tb->smaller->brush.rect.width)
|
|
|
|
break;
|
|
|
|
}
|
2006-06-29 23:09:47 -04:00
|
|
|
if(tb)
|
2007-02-05 21:56:03 -05:00
|
|
|
for(b = largest; b != tb->smaller; b = b->smaller)
|
2007-02-06 17:12:24 -05:00
|
|
|
b->brush.rect.width = (int)(b->brush.rect.width * shrink);
|
2006-06-26 22:21:09 -04:00
|
|
|
width += tw * shrink;
|
2007-02-05 21:56:03 -05:00
|
|
|
tb = nil;
|
2006-03-26 18:21:12 +02:00
|
|
|
}
|
2007-02-07 12:45:00 -05:00
|
|
|
for(b = s->lbar, nb = 2; nb; b = s->rbar, nb--)
|
2007-02-05 21:56:03 -05:00
|
|
|
for(; b; tb = b, b = b->next) {
|
2006-06-29 20:02:52 -04:00
|
|
|
if(b == s->rbar) {
|
2006-06-22 11:03:42 +02:00
|
|
|
b->brush.align = EAST;
|
2006-06-29 20:02:52 -04:00
|
|
|
s->rbar->brush.rect.width += (s->brect.width - width);
|
2006-06-26 22:21:09 -04:00
|
|
|
}else
|
|
|
|
b->brush.align = CENTER;
|
|
|
|
if(tb)
|
|
|
|
b->brush.rect.x = tb->brush.rect.x + tb->brush.rect.width;
|
2006-10-12 16:12:22 +02:00
|
|
|
draw_label(&b->brush, b->text);
|
2007-02-05 20:40:00 +01:00
|
|
|
draw_border(&b->brush);
|
2006-06-19 22:13:29 -04:00
|
|
|
}
|
2006-05-29 10:08:29 +02:00
|
|
|
MapBar:
|
2006-07-03 18:41:14 +02:00
|
|
|
XCopyArea(blz.dpy, s->bbrush.drawable, s->barwin, s->bbrush.gc, 0, 0,
|
2006-06-29 20:02:52 -04:00
|
|
|
s->brect.width, s->brect.height, 0, 0);
|
2006-07-03 18:41:14 +02:00
|
|
|
XSync(blz.dpy, False);
|
2006-02-09 22:48:01 +01:00
|
|
|
}
|
|
|
|
|
2006-04-12 10:44:07 +02:00
|
|
|
Bar *
|
2006-10-12 16:10:57 +02:00
|
|
|
bar_of_name(Bar *b_link, const char *name) {
|
2006-03-31 07:57:33 +02:00
|
|
|
static char buf[256];
|
2006-06-08 10:54:19 +02:00
|
|
|
Bar *b;
|
2006-03-09 02:15:43 +01:00
|
|
|
|
2006-10-12 16:10:57 +02:00
|
|
|
strncpy(buf, name, sizeof(buf));
|
2007-02-05 21:56:03 -05:00
|
|
|
for(b = b_link; b; b = b->next)
|
2006-06-26 22:21:09 -04:00
|
|
|
if(!strncmp(b->name, name, sizeof(b->name))) break;
|
2006-06-08 10:54:19 +02:00
|
|
|
return b;
|
2006-03-09 02:15:43 +01:00
|
|
|
}
|