wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 3cb086a412e343941ab86c925e60fac0f8204e96
parent d4d4b770033ddb7c0a45f4f39088fe1725b248b5
Author: Kris Maglione <bsdaemon@wmii.de>
Date:   Mon, 26 Jun 2006 22:21:09 -0400

Improved the bar sizing algorithm... not quite perfect yet, though


Diffstat:
cmd/wm/bar.c | 72+++++++++++++++++++++++++++++++++++++++---------------------------------
cmd/wm/fs.c | 4++--
cmd/wm/wm.h | 4++--
libixp/request.c | 4++--
4 files changed, 45 insertions(+), 39 deletions(-)

diff --git a/cmd/wm/bar.c b/cmd/wm/bar.c @@ -3,6 +3,7 @@ * See LICENSE file for license details. */ +#include <math.h> #include <string.h> #include <stdlib.h> @@ -14,7 +15,7 @@ Bar * create_bar(Bar **b_link, char *name) { static unsigned int id = 1; - Bar **i, *b = bar_of_name(name);; + Bar **i, *b = bar_of_name(*b_link, name);; if(b) return b; @@ -86,48 +87,60 @@ resize_bar() void draw_bar() { - unsigned int i = 0, w = 0, nb, size = 0; - Bar *b = nil, *prev = nil; + unsigned int width, tw, nb, size; + float shrink; + Bar *b, *tb, *largest, **pb; blitz_draw_tile(&bbrush); if(!lbar && !rbar) goto MapBar; + largest = b = tb = nil; + tw = width = nb = size = 0; + for(b=lbar, nb=2 ;nb; --nb && (b = rbar)) - for(; b && (w < brect.width); b=b->next, size++) { + for(; b; b=b->next) { b->brush.rect.x = 0; b->brush.rect.y = 0; b->brush.rect.width = brect.height; if(b->text && strlen(b->text)) b->brush.rect.width += blitz_textwidth(b->brush.font, b->text); b->brush.rect.height = brect.height; - w += b->brush.rect.width; + width += b->brush.rect.width; } - if(b) { /* give all bars same width */ - for( ;nb; b = rbar, nb--) /* finish counting */ - for(; b; b=b->next, size++); - - w = brect.width / size; - for(b = lbar, nb=2 ;nb; b = rbar, nb--) - for(; b; b=b->next, i++) { - b->brush.rect.x = i * w; - b->brush.rect.width = w; + /* Not enough room. Shrink bars until they all fit */ + if(width > brect.width) { + for(b=lbar, nb=2 ;nb; --nb && (b = rbar)) + 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; } - } - else { /* expand rbar properly */ - if(rbar) - rbar->brush.rect.width += (brect.width - w); - for(b=lbar, nb=2 ;nb; b = rbar, nb--) - for(; b; prev = b, b=b->next) - if(prev) b->brush.rect.x = prev->brush.rect.x + prev->brush.rect.width; + for(tb=largest; tb; tb=tb->smaller) { + width -= tb->brush.rect.width; + tw += tb->brush.rect.width; + shrink = (brect.width - width) / (float)tw; + 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; } for(b=lbar, nb=2 ;nb; b=rbar, nb--) - for(; b; b=b->next) { - if(b == rbar) + for(; b; tb = b, b=b->next) { + if(b == rbar) { b->brush.align = EAST; + rbar->brush.rect.width += (brect.width - width); + }else + b->brush.align = CENTER; + if(tb) + b->brush.rect.x = tb->brush.rect.x + tb->brush.rect.width; blitz_draw_label(&b->brush, b->text); } MapBar: @@ -137,20 +150,13 @@ MapBar: } Bar * -bar_of_name(const char *name) +bar_of_name(Bar *b_link, const char *name) { static char buf[256]; Bar *b; cext_strlcpy(buf, name, sizeof(buf)); - for(b=lbar; b && strncmp(b->name, name, sizeof(b->name)); b=b->next); - return b; -} - -Bar * -bar_of_id(unsigned short id) -{ - Bar *b; - for(b=lbar; b && b->id != id; b=b->next); + for(b=b_link; b; b=b->next) + if(!strncmp(b->name, name, sizeof(b->name))) break; return b; } diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c @@ -214,7 +214,6 @@ write_to_buf(P9Req *r, void *buf, unsigned int *len, unsigned int max) { memcpy(buf + offset, r->ifcall.data, count); r->ofcall.count = count; ((char *)buf)[offset+count] = '\0'; - /* and save some lines later... we alloc for it anyway */ } /* This should be moved to libixp */ @@ -724,7 +723,7 @@ fs_write(P9Req *r) { /* XXX: This should validate after each write */ i = strlen(f->bar->buf); write_to_buf(r, &f->bar->buf, &i, 279); - r->ofcall.count = i- r->ifcall.offset; + r->ofcall.count = i - r->ifcall.offset; return respond(r, nil); case FsFCctl: data_to_cstring(r); @@ -787,6 +786,7 @@ fs_open(P9Req *r) { return respond(r, Enoperm); if((r->ifcall.mode&~(3|P9OAPPEND|P9OTRUNC))) return respond(r, Enoperm); + respond(r, nil); } diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h @@ -127,6 +127,7 @@ struct Key { typedef struct Bar Bar; struct Bar { Bar *next; + Bar *smaller; char buf[280]; char text[256]; char name[256]; @@ -215,10 +216,9 @@ Client *sel_client_of_area(Area *a); Bar *create_bar(Bar **b_link, char *name); void destroy_bar(Bar **b_link, Bar *b); void draw_bar(); -Bar *bar_of_id(unsigned short id); void resize_bar(); unsigned int height_of_bar(); -Bar *bar_of_name(const char *name); +Bar *bar_of_name(Bar *b_link, const char *name); /* client.c */ Client *create_client(Window w, XWindowAttributes *wa); diff --git a/libixp/request.c b/libixp/request.c @@ -46,7 +46,7 @@ free_p9conn(P9Conn *pc) { free(pc); } -void * +static void * createfid(Intmap *map, int fid, P9Conn *pc) { Fid *f = cext_emallocz(sizeof(Fid)); f->fid = fid; @@ -59,7 +59,7 @@ createfid(Intmap *map, int fid, P9Conn *pc) { return nil; } -int +static int destroyfid(P9Conn *pc, unsigned long fid) { Fid *f; if(!(f = deletekey(&pc->fidmap, fid)))