mirror of
https://github.com/0intro/wmii
synced 2024-12-26 05:16:59 +03:00
Fixed event queueing, added drawing of rbar
This commit is contained in:
parent
68e5ceae90
commit
05856824c1
85
cmd/wm/bar.c
85
cmd/wm/bar.c
@ -11,7 +11,7 @@
|
||||
Bar *free_bars = nil;
|
||||
|
||||
Bar *
|
||||
create_bar(char *name)
|
||||
create_bar(Bar **b_link, char *name)
|
||||
{
|
||||
static unsigned int id = 1;
|
||||
Bar **i, *b = bar_of_name(name);;
|
||||
@ -29,8 +29,8 @@ create_bar(char *name)
|
||||
cext_strlcpy(b->name, name, sizeof(b->name));
|
||||
b->color = def.normcolor;
|
||||
|
||||
for(i=&lbar; *i; i=&(*i)->next)
|
||||
if(strcmp((*i)->name, name) < 0)
|
||||
for(i=b_link; *i; i=&(*i)->next)
|
||||
if(strcmp((*i)->name, name) >= 0)
|
||||
break;
|
||||
b->next = *i;
|
||||
*i = b;
|
||||
@ -39,10 +39,10 @@ create_bar(char *name)
|
||||
}
|
||||
|
||||
void
|
||||
destroy_bar(Bar *b)
|
||||
destroy_bar(Bar **b_link, Bar *b)
|
||||
{
|
||||
Bar **i;
|
||||
for(i=&lbar; *i && *i != b; i=&(*i)->next);
|
||||
for(i=b_link; *i && *i != b; i=&(*i)->next);
|
||||
*i = b->next;
|
||||
|
||||
b->next = free_bars;
|
||||
@ -88,10 +88,9 @@ resize_bar()
|
||||
void
|
||||
draw_bar()
|
||||
{
|
||||
unsigned int i = 0, w = 0, size = 0;
|
||||
Bar *exp = nil;
|
||||
unsigned int i = 0, w = 0, nb, size = 0;
|
||||
BlitzDraw d = { 0 };
|
||||
Bar *b = nil;
|
||||
Bar *b = nil, *prev = nil;
|
||||
|
||||
d.gc = bargc;
|
||||
d.drawable = barpmap;
|
||||
@ -103,46 +102,54 @@ draw_bar()
|
||||
blitz_drawlabel(&d);
|
||||
blitz_drawborder(&d);
|
||||
|
||||
if(!lbar)
|
||||
if(!lbar && !rbar)
|
||||
goto MapBar;
|
||||
|
||||
for(b=lbar; 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
if(b) { /* give all bars same width */
|
||||
for(; b; b=b->next, size++);
|
||||
/* finish counting */
|
||||
for( ;nb; b = rbar, nb--)
|
||||
for(; b; b=b->next, size++);
|
||||
|
||||
w = brect.width / size;
|
||||
for(b=lbar; b; b=b->next) {
|
||||
b->rect.x = i * w;
|
||||
b->rect.width = w;
|
||||
for(b = lbar, nb=2 ;nb; b = rbar, nb--) {
|
||||
for(; b; b=b->next) {
|
||||
b->rect.x = i * w;
|
||||
b->rect.width = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* expand lbar properly */
|
||||
for(exp = lbar; exp && exp->next; exp=exp->next);
|
||||
if(exp)
|
||||
exp->rect.width += (brect.width - w);
|
||||
for(b=lbar; b->next; b=b->next)
|
||||
b->next->rect.x = b->rect.x + b->rect.width;
|
||||
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;
|
||||
}
|
||||
|
||||
for(b=lbar; b; b=b->next) {
|
||||
d.color = b->color;
|
||||
d.rect = b->rect;
|
||||
d.data = b->data;
|
||||
if(b == exp)
|
||||
d.align = EAST;
|
||||
else
|
||||
d.align = CENTER;
|
||||
blitz_drawlabel(&d);
|
||||
blitz_drawborder(&d);
|
||||
}
|
||||
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);
|
||||
}
|
||||
MapBar:
|
||||
XCopyArea(dpy, barpmap, barwin, bargc, 0, 0, brect.width, brect.height, 0, 0);
|
||||
XSync(dpy, False);
|
||||
|
89
cmd/wm/fs.c
89
cmd/wm/fs.c
@ -19,11 +19,18 @@ struct Dirtab {
|
||||
unsigned int perm;
|
||||
};
|
||||
|
||||
typedef struct FidLink FidLink;
|
||||
struct FidLink {
|
||||
FidLink *next;
|
||||
Fid *fid;
|
||||
};
|
||||
|
||||
typedef struct FileId FileId;
|
||||
struct FileId {
|
||||
FileId *next;
|
||||
union {
|
||||
void *ref;
|
||||
char *buf;
|
||||
Bar *bar;
|
||||
Bar **bar_p;
|
||||
View *view;
|
||||
@ -39,6 +46,7 @@ struct FileId {
|
||||
|
||||
/* Function prototypes */
|
||||
static void dostat(Stat *s, unsigned int len, FileId *f);
|
||||
void respond_event(Req *r);
|
||||
|
||||
/* Error messages */
|
||||
static char
|
||||
@ -76,6 +84,7 @@ enum { /* Dirs */
|
||||
/* Global vars */
|
||||
FileId *free_fileid = nil;
|
||||
Req *pending_event_reads = nil;
|
||||
FidLink *pending_event_fids;
|
||||
P9Srv p9srv = {
|
||||
.open= fs_open,
|
||||
.walk= fs_walk,
|
||||
@ -495,8 +504,7 @@ fs_read(Req *r) {
|
||||
write_buf(r, (void *)buf, n);
|
||||
return respond(r, nil);
|
||||
case FsFEvent:
|
||||
r->aux = pending_event_reads;
|
||||
pending_event_reads = r;
|
||||
respond_event(r);
|
||||
return;
|
||||
}
|
||||
/* XXX: This should be taken care of by open */
|
||||
@ -510,6 +518,7 @@ fs_attach(Req *r) {
|
||||
FileId *f = get_file();
|
||||
f->tab = dirtab[FsRoot][0];
|
||||
f->tab.name = strdup("/");
|
||||
f->ref = nil; /* shut up valgrind */
|
||||
r->fid->aux = f;
|
||||
r->fid->qid.type = f->tab.qtype;
|
||||
r->fid->qid.path = QID(f->tab.type, 0);
|
||||
@ -519,6 +528,16 @@ fs_attach(Req *r) {
|
||||
|
||||
void
|
||||
fs_open(Req *r) {
|
||||
FidLink *fl;
|
||||
FileId *f = r->fid->aux;
|
||||
switch(f->tab.type) {
|
||||
case FsFEvent:
|
||||
fl = cext_emallocz(sizeof(FidLink));
|
||||
fl->fid = r->fid;
|
||||
fl->next = pending_event_fids;
|
||||
pending_event_fids = fl;
|
||||
break;
|
||||
}
|
||||
/* XXX */
|
||||
r->ofcall.mode = r->ifcall.mode;
|
||||
respond(r, nil);
|
||||
@ -564,15 +583,13 @@ write_to_buf(Req *r, void *buf, unsigned int *len, unsigned int max) {
|
||||
void
|
||||
data_to_cstring(Req *r) {
|
||||
unsigned int i;
|
||||
if(r->ifcall.count) {
|
||||
for(i=0; i < r->ifcall.count; i++)
|
||||
if(r->ifcall.data[i] == '\n')
|
||||
break;
|
||||
if(i == r->ifcall.count)
|
||||
r->ifcall.data = realloc(r->ifcall.data, i + 1);
|
||||
cext_assert(r->ifcall.data);
|
||||
r->ifcall.data[i] = '\0';
|
||||
}
|
||||
for(i=0; i < r->ifcall.count; i++)
|
||||
if(r->ifcall.data[i] == '\n')
|
||||
break;
|
||||
if(i == r->ifcall.count)
|
||||
r->ifcall.data = realloc(r->ifcall.data, i + 1);
|
||||
cext_assert(r->ifcall.data);
|
||||
r->ifcall.data[i] = '\0';
|
||||
}
|
||||
|
||||
/* This should be moved to liblitz */
|
||||
@ -695,6 +712,7 @@ fs_write(Req *r) {
|
||||
void
|
||||
fs_clunk(Req *r) {
|
||||
Client *c;
|
||||
FidLink **fl;
|
||||
char *buf;
|
||||
int i;
|
||||
FileId *f = r->fid->aux;
|
||||
@ -726,6 +744,13 @@ fs_clunk(Req *r) {
|
||||
strncpy(f->bar->data, buf, 255);
|
||||
draw_bar();
|
||||
break;
|
||||
case FsFEvent:
|
||||
for(fl=&pending_event_fids; *fl; fl=&(*fl)->next)
|
||||
if((*fl)->fid == r->fid) {
|
||||
*fl = (*fl)->next;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
respond(r, nil);
|
||||
}
|
||||
@ -733,13 +758,12 @@ fs_clunk(Req *r) {
|
||||
void
|
||||
fs_flush(Req *r) {
|
||||
Req **t;
|
||||
for(t=&pending_event_reads; *t; t=(Req **)&(*t)->aux) {
|
||||
for(t=&pending_event_reads; *t; t=(Req **)&(*t)->aux)
|
||||
if(*t == r->oldreq) {
|
||||
*t = (*t)->aux;
|
||||
respond(r->oldreq, Einterrupted);
|
||||
break;
|
||||
}
|
||||
}
|
||||
respond(r, nil);
|
||||
}
|
||||
|
||||
@ -753,7 +777,7 @@ fs_create(Req *r) {
|
||||
case FsDBar:
|
||||
if(!strlen(r->ifcall.name))
|
||||
return respond(r, Ebadvalue);
|
||||
create_bar(r->ifcall.name);
|
||||
create_bar(f->bar_p, r->ifcall.name);
|
||||
f = lookup_file(f, r->ifcall.name);
|
||||
if(!f)
|
||||
return respond(r, Enofile);
|
||||
@ -773,7 +797,7 @@ fs_remove(Req *r) {
|
||||
/* XXX: This should be taken care of by the library */
|
||||
return respond(r, Enoperm);
|
||||
case FsFBar:
|
||||
destroy_bar(f->bar);
|
||||
destroy_bar(f->next->bar_p, f->bar);
|
||||
respond(r, nil);
|
||||
break;
|
||||
}
|
||||
@ -781,16 +805,37 @@ fs_remove(Req *r) {
|
||||
|
||||
void
|
||||
write_event(char *buf) {
|
||||
unsigned int len, slen;
|
||||
FidLink *f;
|
||||
FileId *fi;
|
||||
Req *aux;
|
||||
unsigned int len;
|
||||
|
||||
if(!(len = strlen(buf)))
|
||||
return;
|
||||
for(; pending_event_reads; pending_event_reads=aux) {
|
||||
aux = pending_event_reads->aux;
|
||||
/* XXX: It would be nice if strdup wasn't necessary here */
|
||||
pending_event_reads->ofcall.data = (void *)strdup(buf);
|
||||
pending_event_reads->ofcall.count = len;
|
||||
respond(pending_event_reads, nil);
|
||||
for(f=pending_event_fids; f; f=f->next) {
|
||||
fi = f->fid->aux;
|
||||
slen = fi->buf ? strlen(fi->buf) : 0;
|
||||
fi->buf = realloc(fi->buf, slen + len + 1);
|
||||
fi->buf[slen] = '\0'; /* shut up valgring */
|
||||
strcat(fi->buf, buf);
|
||||
}
|
||||
while((aux = pending_event_reads)) {
|
||||
pending_event_reads = pending_event_reads->aux;
|
||||
respond_event(aux);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
respond_event(Req *r) {
|
||||
FileId *f = r->fid->aux;
|
||||
if(f->buf) {
|
||||
r->ofcall.data = f->buf;
|
||||
r->ofcall.count = strlen(f->buf);
|
||||
respond(r, nil);
|
||||
f->buf = nil;
|
||||
}else{
|
||||
r->aux = pending_event_reads;
|
||||
pending_event_reads = r;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,14 +52,18 @@ destroy_view(View *v)
|
||||
Area *a;
|
||||
View **i;
|
||||
|
||||
for(a=v->area; a; a=a->next)
|
||||
while((a = v->area)) {
|
||||
v->area = a->next;
|
||||
destroy_area(a);
|
||||
};
|
||||
|
||||
for(i=&view; *i && *i != v; i=&(*i)->next);
|
||||
for(i=&view; *i; i=&(*i)->next)
|
||||
if(*i == v) break;
|
||||
*i = v->next;
|
||||
|
||||
if(sel == v)
|
||||
for(sel=view; sel && sel->next != *i; sel=sel->next);
|
||||
for(sel=view; sel; sel=sel->next)
|
||||
if(sel->next == *i) break;
|
||||
|
||||
snprintf(buf, sizeof(buf), "DestroyTag %s\n", v->name);
|
||||
write_event(buf);
|
||||
|
@ -221,8 +221,8 @@ int idx_of_area(Area *a);
|
||||
Client *sel_client_of_area(Area *a);
|
||||
|
||||
/* bar.c */
|
||||
Bar *create_bar(char *name);
|
||||
void destroy_bar(Bar *b);
|
||||
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();
|
||||
|
@ -6,9 +6,9 @@ xwrite() {
|
||||
echo -n "$@" | wmiir write "$file"
|
||||
}
|
||||
|
||||
wmiir remove /lbar/status 2>/dev/null && sleep 2
|
||||
wmiir create /lbar/status
|
||||
while xwrite /lbar/status "$WMII_NORMCOLORS" `date` `uptime | sed 's/.*://; s/,//g'`
|
||||
wmiir remove /rbar/status 2>/dev/null && sleep 2
|
||||
wmiir create /rbar/status
|
||||
while xwrite /rbar/status "$WMII_NORMCOLORS" `date` `uptime | sed 's/.*://; s/,//g'`
|
||||
do
|
||||
sleep 1
|
||||
done
|
||||
|
10
rc/wmiirc
10
rc/wmiirc
@ -118,17 +118,17 @@ do
|
||||
exit
|
||||
fi;;
|
||||
CreateTag)
|
||||
wmiir create /bar/$1
|
||||
xwrite /bar/$1/data $1
|
||||
wmiir create /lbar/$1
|
||||
xwrite /lbar/$1 $WMII_SELCOLORS $1
|
||||
;;
|
||||
DestroyTag)
|
||||
wmiir remove /bar/$1
|
||||
wmiir remove /lbar/$1
|
||||
;;
|
||||
FocusTag)
|
||||
xwrite /bar/$1/colors $WMII_SELCOLORS
|
||||
xwrite /lbar/$1 $WMII_SELCOLORS $1
|
||||
;;
|
||||
UnfocusTag)
|
||||
xwrite /bar/$1/colors $WMII_NORMCOLORS
|
||||
xwrite /lbar/$1 $WMII_NORMCOLORS $1
|
||||
;;
|
||||
BarClick)
|
||||
xwrite /ctl view "$1";;
|
||||
|
Loading…
Reference in New Issue
Block a user