changeset: 2088:7231b60eafd9
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Apr 17 00:28:43 2007 -0400
summary: Cleanup. Switch some lists to doubly linked.
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/area.c
--- a/cmd/wmii/area.c Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/area.c Tue Apr 17 00:28:43 2007 -0400
@@ -25,19 +25,15 @@ create_area(View *v, Area *pos, uint w)
static ushort id = 1;
uint areanum, colnum, i;
uint minwidth;
- Area *a, **p;
+ Area *a;
minwidth = Dx(screen->rect)/NCOL;
- p = &v->area;
- if(pos)
- p = &pos->next;
-
- i = areanum = 0;
- a = v->area;
- for(; a != *p; a = a->next)
- areanum++, i++;
- for(; a; a = a->next)
+ i = 0;
+ for(a = v->area; a != pos; a = a->next)
+ i++;
+ areanum = 0;
+ for(a = v->area; a; a = a->next)
areanum++;
colnum = max((areanum - 1), 0);
@@ -47,17 +43,19 @@ create_area(View *v, Area *pos, uint w)
if (w == 0)
w = Dx(screen->rect) / (colnum + 1);
}
- else w = Dx(screen->rect);
+ else
+ w = Dx(screen->rect);
}
if(w < minwidth)
w = minwidth;
if(colnum && (colnum * minwidth + w) > Dx(screen->rect))
return nil;
+
if(pos)
scale_view(v, Dx(screen->rect) - w);
- a = emallocz(sizeof(Area));
+ a = emallocz(sizeof *a);
a->view = v;
a->id = id++;
a->mode = def.colmode;
@@ -68,14 +66,22 @@ create_area(View *v, Area *pos, uint w)
a->rect.max.x = a->rect.min.x + w;
a->rect.max.x = screen->brect.min.y;
- a->next = *p;
- *p = a;
+ if(pos) {
+ a->next = pos->next;
+ a->prev = pos;
+ }else {
+ a->next = v->area;
+ v->area = a;
+ }
+ if(a->prev)
+ a->prev->next = a;
+ if(a->next)
+ a->next->prev = a;
if(a == v->area)
a->floating = True;
- if((!v->sel)
- || (v->sel->floating && v->area->next == a && a->next == nil))
+ if((v->sel == nil) || (v->sel->floating && v->area == a->prev && a->next == nil))
focus_area(a);
if(!a->floating)
@@ -94,24 +100,37 @@ destroy_area(Area *a) {
if(a->frame)
fatal("destroying non-empty area");
+
if(v->revert == a)
v->revert = nil;
+
for(c=client; c; c=c->next)
if(c->revert == a)
c->revert = nil;
- i = 1;
- for(ta=v->area; ta; ta=ta->next)
- if(ta->next == a) break;
- else i++;
- if(ta) {
- ta->next = a->next;
+ i = 0;
+ for(ta=v->area; ta != a; ta=ta->next)
+ i++;
+
+ if(a->prev)
+ ta = a->prev;
+ else
+ ta = a->next;
+
+ assert(a->prev || a->next == nil);
+
+ if(a->prev)
+ a->prev->next = a->next;
+ if(a->next)
+ a->next->prev = a->prev;
+
+ if(ta && v->sel == a) {
if(ta->floating && ta->next)
ta = ta->next;
- if(v->sel == a)
- focus_area(ta);
- }
- if(i) write_event("DestroyColumn %d\n", i);
+ focus_area(ta);
+ }
+ write_event("DestroyColumn %d\n", i);
+
free(a);
}
@@ -150,8 +169,7 @@ attach_to_area(Area *a, Frame *f, Bool s
n_frame = 0;
for(ft=a->frame; ft; ft=ft->anext)
n_frame++;
- if(n_frame == 0)
- n_frame = 1;
+ n_frame = max(n_frame, 1);
c->floating = a->floating;
if(!a->floating) {
@@ -178,7 +196,7 @@ void
void
detach_from_area(Frame *f) {
Frame *pr;
- Client *c;
+ Client *c, *cp;
Area *a;
View *v;
Area *ta;
@@ -188,14 +206,13 @@ detach_from_area(Frame *f) {
v = a->view;
c = f->client;
- for(pr = a->frame; pr; pr = pr->anext)
- if(pr->anext == f) break;
+ pr = f->aprev;
remove_frame(f);
if(a->sel == f) {
if(!pr)
pr = a->frame;
- if((a->view->sel == a) && (pr))
+ if(pr && (v->sel == a))
focus_frame(pr, False);
else
a->sel = pr;
@@ -206,7 +223,7 @@ detach_from_area(Frame *f) {
arrange_column(a, False);
else {
i = 0;
- for(ta=v->area; ta && ta != a; ta=ta->next)
+ for(ta=v->area; ta != a; ta=ta->next)
i++;
if(v->area->next->next)
@@ -219,11 +236,9 @@ detach_from_area(Frame *f) {
}
else if(!a->frame) {
if(c->trans) {
- Client *cl;
-
- cl = win2client(c->trans);
- if(cl && cl->frame) {
- a = cl->sel->area;
+ cp = win2client(c->trans);
+ if(cp && cp->frame) {
+ a = cp->sel->area;
if(a->view == v)
focus_area(a);
}
@@ -382,9 +397,8 @@ focus_area(Area *a) {
v->sel = a;
- if((old_a)
- && (a->floating != old_a->floating))
- v->revert = old_a;
+ if((old_a) && (a->floating != old_a->floating))
+ v->revert = old_a;
if(v != screen->sel)
return;
@@ -409,11 +423,11 @@ focus_area(Area *a) {
char *
select_area(Area *a, char *arg) {
+ static char Ebadvalue[] = "bad value";
Area *new;
uint i;
Frame *p, *f;
View *v;
- static char Ebadvalue[] = "bad value";
v = a->view;
f = a->sel;
@@ -427,18 +441,18 @@ select_area(Area *a, char *arg) {
} else if(!strncmp(arg, "left", 5)) {
if(a->floating)
return Ebadvalue;
- for(new=v->area->next; new->next; new=new->next)
- if(new->next == a) break;
+ new = a->prev;
} else if(!strncmp(arg, "right", 5)) {
if(a->floating)
return Ebadvalue;
- new = a->next ? a->next : v->area->next;
+ new = a->next;
+ if(new == nil)
+ new = v->area->next;
}
else if(!strncmp(arg, "up", 3)) {
if(!f)
return Ebadvalue;
- for(p=a->frame; p->anext; p=p->anext)
- if(p->anext == f) break;
+ p = f->aprev;
goto focus_frame;
}
else if(!strncmp(arg, "down", 5)) {
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/column.c
--- a/cmd/wmii/column.c Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/column.c Tue Apr 17 00:28:43 2007 -0400
@@ -178,7 +178,7 @@ Area *
Area *
new_column(View *v, Area *pos, uint w) {
Area *a;
-
+
a = create_area(v, pos, w);
if(!a)
return nil;
@@ -372,33 +372,32 @@ static void
static void
resize_colframeh(Frame *f, Rectangle *r) {
Area *a;
- Frame *fa, *fb;
+ Frame *fn, *fp;
uint minh;
minh = 2 * labelh(def.font);
a = f->area;
- fa = f->anext;
- for(fb = a->frame; fb; fb = fb->anext)
- if(fb->anext == f) break;
-
- if(fb)
- r->min.y = max(r->min.y, fb->rect.min.y + minh);
+ fn = f->anext;
+ fp = f->aprev;
+
+ if(fp)
+ r->min.y = max(r->min.y, fp->rect.min.y + minh);
else
r->min.y = max(r->min.y, a->rect.min.y);
- if(fa)
- r->max.y = min(r->max.y, fa->rect.max.y - minh);
+ if(fn)
+ r->max.y = min(r->max.y, fn->rect.max.y - minh);
else
r->max.y = min(r->max.y, a->rect.max.y);
- if(fb) {
- fb->rect.max.y = r->min.y;
- resize_frame(fb, fb->rect);
- }
- if(fa) {
- fa->rect.min.y = r->max.y;
- resize_frame(fa, fa->rect);
+ if(fp) {
+ fp->rect.max.y = r->min.y;
+ resize_frame(fp, fp->rect);
+ }
+ if(fn) {
+ fn->rect.min.y = r->max.y;
+ resize_frame(fn, fn->rect);
}
resize_frame(f, *r);
@@ -417,9 +416,8 @@ resize_colframe(Frame *f, Rectangle *r)
minw = Dx(screen->rect) / NCOL;
+ al = a->prev;
ar = a->next;
- for(al = v->area->next; al; al = al->next)
- if(al->next == a) break;
if(al)
r->min.x = max(r->min.x, al->rect.min.x + minw);
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/dat.h Tue Apr 17 00:28:43 2007 -0400
@@ -79,7 +79,7 @@ struct View {
};
struct Area {
- Area *next;
+ Area *next, *prev;
Frame *frame;
Frame *stack;
Frame *sel;
@@ -92,8 +92,8 @@ struct Area {
struct Frame {
Frame *cnext;
- Frame *anext;
- Frame *snext;
+ Frame *anext, *aprev;
+ Frame *snext, *sprev;
View *view;
Area *area;
ushort id;
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/frame.c Tue Apr 17 00:28:43 2007 -0400
@@ -36,43 +36,48 @@ void
void
remove_frame(Frame *f) {
Area *a;
- Frame **ft;
a = f->area;
- for(ft = &a->frame; *ft; ft=&(*ft)->anext)
- if(*ft == f) break;
- *ft = f->anext;
+ if(f->aprev)
+ f->aprev->anext = f->anext;
+ if(f->anext)
+ f->anext->aprev = f->aprev;
if(a->floating) {
- for(ft = &a->stack; *ft; ft=&(*ft)->snext)
- if(*ft == f) break;
- *ft = f->snext;
+ if(f->sprev)
+ f->sprev->snext = f->snext;
+ if(f->snext)
+ f->snext->sprev = f->sprev;
}
}
void
insert_frame(Frame *pos, Frame *f, Bool before) {
- Frame *ft, **p;
Area *a;
a = f->area;
- if(before) {
- for(ft=a->frame; ft; ft=ft->anext)
- if(ft->anext == pos) break;
- pos=ft;
- }
-
- p = &a->frame;
- if(pos)
- p = &pos->anext;
-
- f->anext = *p;
- *p = f;
+ if(before)
+ pos = pos->aprev;
+
+ if(pos) {
+ f->aprev = pos;
+ f->anext = pos->anext;
+ }else {
+ f->aprev = nil;
+ f->anext = f->area->frame;
+ f->area->frame = f;
+ }
+ if(f->aprev)
+ f->aprev->anext = f;
+ if(f->anext)
+ f->anext->aprev = f;
if(a->floating) {
f->snext = a->stack;
a->stack = f;
+ if(f->snext)
+ f->snext->sprev = f;
}
}
@@ -268,19 +273,21 @@ set_frame_cursor(Frame *f, Point pt) {
Bool
frame_to_top(Frame *f) {
- Frame **tf;
Area *a;
a = f->area;
if(!a->floating || f == a->stack)
return False;
- for(tf=&a->stack; *tf; tf=&(*tf)->snext)
- if(*tf == f) break;
- *tf = f->snext;
+ if(f->sprev)
+ f->sprev = f->snext;
+ if(f->snext)
+ f->snext = f->sprev;
f->snext = a->stack;
a->stack = f;
+ if(f->snext)
+ f->snext->sprev = f;
return True;
}
@@ -289,38 +296,26 @@ swap_frames(Frame *fa, Frame *fb) {
swap_frames(Frame *fa, Frame *fb) {
Rectangle trect;
Area *a;
- Frame **fp_a, **fp_b, *ft;
+ Frame *an, *ap, *bn, *bp;
if(fa == fb) return;
- a = fa->area;
- for(fp_a = &a->frame; *fp_a; fp_a = &(*fp_a)->anext)
- if(*fp_a == fa) break;
- a = fb->area;
- for(fp_b = &a->frame; *fp_b; fp_b = &(*fp_b)->anext)
- if(*fp_b == fb) break;
-
- if(fa->anext == fb) {
- *fp_a = fb;
- fa->anext = fb->anext;
- fb->anext = fa;
- } else if(fb->anext == fa) {
- *fp_b = fa;
- fb->anext = fa->anext;
- fa->anext = fb;
- } else {
- *fp_a = fb;
- *fp_b = fa;
- ft = fb->anext;
- fb->anext = fa->anext;
- fa->anext = ft;
- }
+ an = fa->anext;
+ ap = fa->aprev;
+ bn = fb->anext;
+ bp = fb->aprev;
+
+ fb->anext = an;
+ fb->aprev = ap;
+ fa->anext = bn;
+ fa->aprev = bp;
if(fb->area->sel == fb)
fb->area->sel = fa;
if(fa->area->sel == fa)
fa->area->sel = fb;
+ a = fb->area;
fb->area = fa->area;
fa->area = a;
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/mouse.c Tue Apr 17 00:28:43 2007 -0400
@@ -8,6 +8,7 @@
#include <util.h>
#include "dat.h"
#include "fns.h"
+#include "printevent.h"
enum {
ButtonMask =
@@ -341,9 +342,8 @@ mouse_resizecolframe(Frame *f, Align ali
XEvent ev;
Window *cwin, *hwin;
Divide *d;
- Frame *fp;
View *v;
- Area *a, *ap;
+ Area *a;
Rectangle r;
uint minw, minh;
int x, y;
@@ -352,29 +352,21 @@ mouse_resizecolframe(Frame *f, Align ali
assert((align&(NORTH|SOUTH)) != (NORTH|SOUTH));
v = screen->sel;
- for(a = v->area->next, d = divs; a; a = a->next, d = d->next) {
- if(a->next == f->area)
- ap = a;
- if(a == f->area)
- break;
- }
- for(fp = a->frame; fp; fp = fp->anext)
- if(fp->anext == f) break;
+ for(a = v->area->next, d = divs; a; a = a->next, d = d->next)
+ if(a == f->area) break;
+
if(align&EAST)
d = d->next;
- if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
- return;
-
if(align&NORTH) {
- r.min.y = (fp ? fp->rect.min.y : screen->rect.min.y);
+ r.min.y = (f->aprev ? f->aprev->rect.min.y : screen->rect.min.y);
r.max.y = f->rect.max.y;
}else {
r.min.y = f->rect.min.y;
r.max.y = (f->anext ? f->anext->rect.max.y : a->rect.max.y);
}
if(align&WEST) {
- r.min.x = (ap ? ap->rect.min.x : screen->rect.min.x);
+ r.min.x = (a->prev ? a->prev->rect.min.x : screen->rect.min.x);
r.max.x = a->rect.max.x;
}else {
r.min.x = a->rect.min.x;
@@ -398,6 +390,9 @@ mouse_resizecolframe(Frame *f, Align ali
r.max.y = r.min.y + 2;
hwin = gethsep(r);
+
+ if(!grabpointer(&scr.root, cwin, cursor[CurSizing], MouseMask))
+ goto done;
x = ((align&WEST) ? f->rect.min.x : f->rect.max.x);
y = ((align&NORTH) ? f->rect.min.y : f->rect.max.y);
@@ -478,9 +473,6 @@ mouse_resizecol(Divide *d) {
if(a == nil || a->next == nil)
return;
- if(!grabpointer(&scr.root, cwin, cursor[CurInvisible], MouseMask))
- return;
-
querypointer(&scr.root, &x, &y);
minw = Dx(screen->rect)/NCOL;
@@ -488,8 +480,12 @@ mouse_resizecol(Divide *d) {
r.max.x = a->next->rect.max.x - minw;
r.min.y = y;
r.max.y = y+1;
+
cwin = createwindow(&scr.root, r, 0, InputOnly, &wa, 0);
mapwin(cwin);
+
+ if(!grabpointer(&scr.root, cwin, cursor[CurInvisible], MouseMask))
+ goto done;
for(;;) {
XMaskEvent(display, MouseMask | ExposureMask, &ev);
diff -r 0d7f136f4a38 -r 7231b60eafd9 cmd/wmii/view.c
--- a/cmd/wmii/view.c Mon Apr 16 22:47:32 2007 -0400
+++ b/cmd/wmii/view.c Tue Apr 17 00:28:43 2007 -0400
@@ -70,7 +70,8 @@ create_view(const char *name) {
new_column(v, v->area, 0);
for(i=&view; *i; i=&(*i)->next)
- if(strcmp((*i)->name, name) < 0) break;
+ if(strcmp((*i)->name, name) < 0)
+ break;
v->next = *i;
*i = v;
@@ -84,10 +85,9 @@ destroy_view(View *v) {
Area *a;
View **i, *tv;
- while((a = v->area)) {
- v->area = a->next;
+ while((a = v->area->next))
destroy_area(a);
- }
+ destroy_area(v->area);
for(i=&view; *i; i=&(*i)->next)
if(*i == v) break;
@@ -469,9 +469,10 @@ update_views() {
for(v=view; v; v=n) {
n=v->next;
if(v != old) {
- found = True;
if(is_empty(v))
destroy_view(v);
+ else
+ found = True;
}
}
Received on Fri Jun 01 2007 - 03:09:19 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:56 UTC