X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=client.c;h=e37b9e6d65b5e7a36ccf58eecdd240df6357a349;hb=9ed5de00b686ab872caab8525c6845892a1a1ac1;hp=badb8754750ed8a89e3f8b6ff9286e3d365e742c;hpb=a5cb80b86cdedb8cd1f3a02de47f204bd174f649;p=dwm.git diff --git a/client.c b/client.c index badb875..e37b9e6 100644 --- a/client.c +++ b/client.c @@ -7,7 +7,7 @@ #include #include -/* static functions */ +/* static */ static void detachstack(Client *c) { @@ -65,7 +65,7 @@ xerrordummy(Display *dsply, XErrorEvent *ee) { return 0; } -/* extern functions */ +/* extern */ void configure(Client *c) { @@ -120,11 +120,26 @@ getclient(Window w) { return NULL; } +Bool +isprotodel(Client *c) { + int i, n; + Atom *protocols; + Bool ret = False; + + if(XGetWMProtocols(dpy, c->win, &protocols, &n)) { + for(i = 0; !ret && i < n; i++) + if(protocols[i] == wmatom[WMDelete]) + ret = True; + XFree(protocols); + } + return ret; +} + void killclient(Arg *arg) { if(!sel) return; - if(sel->proto & PROTODELWIN) + if(isprotodel(sel)) sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]); else XKillClient(dpy, sel->win); @@ -159,7 +174,6 @@ manage(Window w, XWindowAttributes *wa) { c->y = way; } updatesizehints(c); - c->proto = getproto(c->win); XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XGetTransientForHint(dpy, c->win, &trans); @@ -184,15 +198,12 @@ manage(Window w, XWindowAttributes *wa) { void resize(Client *c, Bool sizehints) { + float actual, dx, dy, max, min; XWindowChanges wc; if(c->w <= 0 || c->h <= 0) return; if(sizehints) { - if(c->incw) - c->w -= (c->w - c->basew) % c->incw; - if(c->inch) - c->h -= (c->h - c->baseh) % c->inch; if(c->minw && c->w < c->minw) c->w = c->minw; if(c->minh && c->h < c->minh) @@ -201,6 +212,32 @@ resize(Client *c, Bool sizehints) { c->w = c->maxw; if(c->maxh && c->h > c->maxh) c->h = c->maxh; + /* inspired by algorithm from fluxbox */ + if(c->minay > 0 && c->maxay && (c->h - c->baseh) > 0) { + dx = (float)(c->w - c->basew); + dy = (float)(c->h - c->baseh); + min = (float)(c->minax) / (float)(c->minay); + max = (float)(c->maxax) / (float)(c->maxay); + actual = dx / dy; + if(max > 0 && min > 0 && actual > 0) { + if(actual < min) { + dy = (dx * min + dy) / (min * min + 1); + dx = dy * min; + c->w = (int)dx + c->basew; + c->h = (int)dy + c->baseh; + } + else if(actual > max) { + dy = (dx * min + dy) / (max * max + 1); + dx = dy * min; + c->w = (int)dx + c->basew; + c->h = (int)dy + c->baseh; + } + } + } + if(c->incw) + c->w -= (c->w - c->basew) % c->incw; + if(c->inch) + c->h -= (c->h - c->baseh) % c->inch; } if(c->w == sw && c->h == sh) c->border = 0; @@ -257,6 +294,14 @@ updatesizehints(Client *c) { } else c->minw = c->minh = 0; + if(c->flags & PAspect) { + c->minax = size.min_aspect.x; + c->minay = size.min_aspect.y; + c->maxax = size.max_aspect.x; + c->maxay = size.max_aspect.y; + } + else + c->minax = c->minay = c->maxax = c->maxay = 0; c->isfixed = (c->maxw && c->minw && c->maxh && c->minh && c->maxw == c->minw && c->maxh == c->minh); }