--- cmd/wm/area.c.orig 2006-04-24 22:19:58.000000000 +0200 +++ cmd/wm/area.c 2006-04-24 22:23:12.000000000 +0200 @@ -148,7 +148,7 @@ void place_client(Area *a, Client *c) { - static unsigned int mx, my; + static unsigned int mx, my, offset; static Bool *field = nil; Bool fit = False; unsigned int i, j, k, x, y, maxx, maxy, dx, dy, cx, cy; @@ -218,13 +218,17 @@ if(fit && (p1.x + f->rect.width < a->rect.x + a->rect.width)) f->rect.x = p1.x; - else - f->rect.x = a->rect.x + (random()%(a->rect.width - f->rect.width)); + else { + offset = (a->rect.width - f->rect.width) > 0 ? (a->rect.width - f->rect.width) : 1; + f->rect.x = a->rect.x + (random()%offset); + } if(fit && (p1.y + f->rect.height < a->rect.y + a->rect.height)) f->rect.y = p1.y; - else - f->rect.y = a->rect.y + (random()%(a->rect.height - f->rect.height)); + else { + offset = (a->rect.height - f->rect.height) > 0 ? (a->rect.height - f->rect.height) : 1; + f->rect.y = a->rect.y + (random()%offset); + } } void