wmii

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

commit 5a6da3e7cf97414f00222ee7b294ed7b93ca38f0
parent 72c0efea9e4aac99159fb8a467ce5622cfd49ccf
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Mon, 10 Apr 2006 15:48:27 +0200

added intelligent placement for floating layer, changed Makefile as discussed with Maxi


Diffstat:
cmd/wm/Makefile | 2+-
cmd/wm/area.c | 111+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
cmd/wm/tag.c | 11++++-------
cmd/wm/view.c | 13++++++-------
config.mk | 6+++---
5 files changed, 78 insertions(+), 65 deletions(-)

diff --git a/cmd/wm/Makefile b/cmd/wm/Makefile @@ -4,7 +4,7 @@ include ../../config.mk CFLAGS += -I../../liblitz -I../../libixp -I../../libcext -LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext +LDFLAGS += -L../../liblitz -llitz -L../../libixp -lixp -L../../libcext -lcext -lm # Solaris # LDFLAGS += -lsocket diff --git a/cmd/wm/area.c b/cmd/wm/area.c @@ -134,61 +134,78 @@ frame2vector(FrameVector *fv) return (Vector *) fv; } -typedef struct { - int x; - int y; -} Gravity; - void place_client(Area *a, Client *c) { -#if 0 - static Gravity gravity[] = - { - {0, 0}, /* CENTER */ - {-1, -1}, /* NW */ - {0, -1}, /* N */ - {1, -1}, /* NE */ - {1, 0}, /* E */ - {1, 1}, /* SE */ - {0, 1}, /* S */ - {-1, 1}, /* SW */ - {-1, 0} /* W */ - }; - unsigned int dx = rect.width / 3, dy = rect.height / 3; -#endif + static unsigned int mx, my; + static Bool *field = nil; + unsigned int i, j, k, x, y, maxx, maxy, dx, dy; + XPoint p1 = {0, 0}, p2 = {0, 0}; Frame *f = c->frame.data[c->sel]; + if(c->trans) return; - /* first of all, caculate center */ - f->rect.x = (rect.width - f->rect.width) / 2; - f->rect.y = (rect.height - f->rect.height) / 2; + if(!field) { + mx = rect.width / 8; + my = rect.height / 8; + field = cext_emallocz(my * mx * sizeof(Bool)); + } - - switch(a->frame.size) { - case 0: return; break; - case 1: - f->rect.x = 0; - f->rect.y = 0; - break; - case 2: - f->rect.x = a->rect.x + a->rect.width - f->rect.width; - f->rect.y = 0; - break; - case 3: - f->rect.x = 0; - f->rect.y = a->rect.y + a->rect.height - f->rect.height; - break; - case 4: - f->rect.x = a->rect.x + a->rect.width - f->rect.width; - f->rect.y = a->rect.y + a->rect.height - f->rect.height; - break; - default: - f->rect.x = (a->frame.size - 4) * def.snap; - f->rect.y = (a->frame.size - 4) * def.snap; - break; + for(y = 0; y < my; y++) + for(x = 0; x < mx; x++) + field[y*mx + x] = True; + + dx = rect.width / mx; + dy = rect.height / my; + for(k = 0; k < a->frame.size; k++) { + Frame *f = a->frame.data[k]; + if(f->client == c) + continue; + x = f->rect.x / dx; + y = f->rect.y / dy; + maxx = x + f->rect.width / dx; + maxy = y + f->rect.height / dy; + for(j = y; j < maxy; j++) + for(i = x; i < maxx; i++) + field[j*mx + i] = False; } + + /* + for(y = 0; y < my; y++) { + for(x = 0; x < mx; x++) + putchar(field[y*mx + x] + '0'); + putchar('\n'); + } + fflush(stdout); + */ + + for(y = 0; y < my; y++) + for(x = 0; x < mx; x++) { + if(field[y*mx + x]) { + for(i = x; field[y*mx + i] && (i < mx); i++); + for(j = y; field[j*mx + x] && (j < my); j++); + if((i - x) * (j - y) > (p2.x - p1.x) * (p2.y - p1.y)) { + p1.x = x; + p1.y = y; + p2.x = i; + p2.y = j; + } + } + } + + p1.x *= dx; + p1.y *= dy; + + if(p1.x + f->rect.width < a->rect.x + a->rect.width) + f->rect.x = p1.x; + else + f->rect.x = p1.x + f->rect.width - (a->rect.x + a->rect.width); + + if(p1.y + f->rect.height < a->rect.y + a->rect.height) + f->rect.y = p1.y; + else + f->rect.y = p1.y + f->rect.height - (a->rect.y + a->rect.height); } void @@ -218,7 +235,7 @@ attach_toarea(Area *a, Client *c) arrange_column(a, False); } else { /* floating */ - /*place_client(a, c);*/ + place_client(a, c); resize_client(c, &f->rect, False); } } diff --git a/cmd/wm/tag.c b/cmd/wm/tag.c @@ -73,15 +73,12 @@ update_tags() organize_client(view.data[sel], client.data[i]); } - if(view.size && !hasclient(view.data[sel])) { + if(view.size && !hasclient(view.data[sel])) destroy_view(view.data[sel]); - if(view.size) - focus_view(view.data[sel]); - else - update_bar_tags(); - } - if(!view.size && tag.size) + if(view.size) + focus_view(view.data[sel]); + else if(tag.size) select_view(tag.data[0]); else update_bar_tags(); diff --git a/cmd/wm/view.c b/cmd/wm/view.c @@ -70,7 +70,6 @@ focus_view(View *v) Client *c; unsigned int i; - fprintf(stderr, "%d\n", view.size); /* cleanup other empty views */ for(i = 0; i < view.size; i++) if(!hasclient(view.data[i])) { @@ -84,6 +83,8 @@ focus_view(View *v) update_frame_selectors(v); /* gives all(!) clients proper geometry (for use of different tags) */ + if((c = sel_client_of_view(v))) + focus_client(c); for(i = 0; i < client.size; i++) if(client.data[i]->frame.size) { Frame *f = client.data[i]->frame.data[client.data[i]->sel]; @@ -97,8 +98,6 @@ focus_view(View *v) XMoveWindow(dpy, client.data[i]->framewin, 2 * rect.width + f->rect.x, f->rect.y); } - if((c = sel_client_of_view(v))) - focus_client(c); update_bar_tags(); XSync(dpy, False); XUngrabServer(dpy); @@ -252,21 +251,21 @@ sel_client_of_view(View *v) void restack_view(View *v) { - unsigned int i, j, n = 0; + unsigned int i, n = 0; + int j; static Window *wins = nil; static unsigned int winssz = 0; if(client.size > winssz) { winssz = 2 * client.size; - free(wins); - wins = cext_emallocz(sizeof(Window) * winssz); + wins = realloc(wins, sizeof(Window) * winssz); } for(i = 0; i < v->area.size; i++) { Area *a = v->area.data[i]; if(a->frame.size) { wins[n++] = a->frame.data[a->sel]->client->framewin; - for(j = 0; j < a->frame.size; j++) { + for(j = a->frame.size - 1; j >= 0; j--) { Client *c = a->frame.data[j]->client; if((v->sel == i) && (a->sel == j)) { ungrab_mouse(c->framewin, AnyModifier, AnyButton); diff --git a/config.mk b/config.mk @@ -11,12 +11,12 @@ X11LIB = /usr/X11R6/lib VERSION = 3-current # includes and libs -LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 +LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 # Linux/BSD -CFLAGS = -ggdb -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ +CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ -DVERSION=\"${VERSION}\" -LDFLAGS = -ggdb ${LIBS} +LDFLAGS = -g -Wl,--as-needed ${LIBS} # Solaris #CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\"