X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=2fe70e448d22b8e89b2d055f831fba8fa1cdbffa;hb=9189f7a12dce4e3b38341e0704cca257994ab2ba;hp=352e9dbaab802f203711e6bcb3344ad859374f19;hpb=0fe2e783e9e6b097bc6529dc286b4b697f7e1fde;p=dwm.git diff --git a/dwm.c b/dwm.c index 352e9db..2fe70e4 100644 --- a/dwm.c +++ b/dwm.c @@ -52,6 +52,7 @@ #define MAXTAGLEN 16 #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define TAGMASK ((int)((1LL << LENGTH(tags)) - 1)) +#define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height) #define VISIBLE(x) ((x)->tags & tagset[seltags]) /* enums */ @@ -104,7 +105,6 @@ typedef struct { typedef struct { const char *symbol; void (*arrange)(void); - void (*updategeom)(void); } Layout; typedef struct { @@ -169,9 +169,7 @@ void setup(void); void spawn(const void *arg); void tag(const void *arg); uint textnw(const char *text, uint len); -uint textw(const char *text); void tile(void); -void tileresize(Client *c, int x, int y, int w, int h); void togglebar(const void *arg); void togglefloating(const void *arg); void togglelayout(const void *arg); @@ -183,7 +181,6 @@ void unmapnotify(XEvent *e); void updatebar(void); void updategeom(void); void updatesizehints(Client *c); -void updatetilegeom(void); void updatetitle(Client *c); void updatewmhints(Client *c); void view(const void *arg); @@ -197,7 +194,6 @@ void zoom(const void *arg); char stext[256]; int screen, sx, sy, sw, sh; int bx, by, bw, bh, blw, wx, wy, ww, wh; -int mx, my, mw, mh, tx, ty, tw, th; uint seltags = 0; int (*xerrorxlib)(Display *, XErrorEvent *); uint numlockmask = 0; @@ -305,7 +301,7 @@ buttonpress(XEvent *e) { if(ev->window == barwin) { x = 0; for(i = 0; i < LENGTH(tags); i++) { - x += textw(tags[i]); + x += TEXTW(tags[i]); if(ev->x < x) { mask = 1 << i; if(ev->button == Button1) { @@ -491,7 +487,7 @@ drawbar(void) { dc.x = 0; for(c = stack; c && !VISIBLE(c); c = c->snext); for(i = 0; i < LENGTH(tags); i++) { - dc.w = textw(tags[i]); + dc.w = TEXTW(tags[i]); if(tagset[seltags] & 1 << i) { drawtext(tags[i], dc.sel, isurgent(i)); drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel); @@ -509,7 +505,7 @@ drawbar(void) { } else x = dc.x; - dc.w = textw(stext); + dc.w = TEXTW(stext); dc.x = bw - dc.w; if(dc.x < x) { dc.x = x; @@ -1126,6 +1122,10 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { x = sx; if(y + h + 2 * c->bw < sy) y = sy; + if(h < bh) + h = bh; + if(w < bh) + w = bh; if(c->x != x || c->y != y || c->w != w || c->h != h || c->isbanned || c->ismax) { c->isbanned = c->ismax = False; c->x = wc.x = x; @@ -1315,7 +1315,6 @@ setmfact(const void *arg) { if(d < 0.1 || d > 0.9) return; mfact = d; - updatetilegeom(); arrange(); } @@ -1365,7 +1364,7 @@ setup(void) { /* init bar */ for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { - w = textw(layouts[i].symbol); + w = TEXTW(layouts[i].symbol); blw = MAX(blw, w); } @@ -1437,14 +1436,9 @@ textnw(const char *text, uint len) { return XTextWidth(dc.font.xfont, text, len); } -uint -textw(const char *text) { - return textnw(text, strlen(text)) + dc.font.height; -} - void tile(void) { - int x, y, h, w; + int x, y, h, w, mw; uint i, n; Client *c; @@ -1454,42 +1448,29 @@ tile(void) { /* master */ c = nexttiled(clients); - - if(n == 1) - tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); - else - tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw); + mw = mfact * ww; + resize(c, wx, wy, ((n == 1) ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints); if(--n == 0) return; /* tile stack */ - x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw; - y = ty; - w = (tx > c->x + c->w) ? wx + ww - x : tw; - h = th / n; + x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : ww - mw; + y = wy; + w = (wx + mw > c->x + c->w) ? wx + ww - x : ww - mw; + h = wh / n; if(h < bh) - h = th; + h = wh; for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { - if(i + 1 == n) /* remainder */ - tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw); - else - tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw); - if(h != th) + resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) + ? (wy + wh) - y : h) - 2 * c->bw, resizehints); + if(h != wh) y = c->y + c->h + 2 * c->bw; } } void -tileresize(Client *c, int x, int y, int w, int h) { - resize(c, x, y, w, h, resizehints); - if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w))) - /* client doesn't accept size constraints */ - resize(c, x, y, w, h, False); -} - -void togglebar(const void *arg) { showbar = !showbar; updategeom(); @@ -1618,11 +1599,6 @@ updategeom(void) { bx = wx; by = showbar ? (topbar ? wy - bh : wy + wh) : -bh; bw = ww; - - /* update layout geometries */ - for(i = 0; i < LENGTH(layouts); i++) - if(layouts[i].updategeom) - layouts[i].updategeom(); } void @@ -1678,21 +1654,6 @@ updatesizehints(Client *c) { } void -updatetilegeom(void) { - /* master area geometry */ - mx = wx; - my = wy; - mw = mfact * ww; - mh = wh; - - /* tile area geometry */ - tx = mx + mw; - ty = wy; - tw = ww - mw; - th = wh; -} - -void updatetitle(Client *c) { if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) gettextprop(c->win, wmatom[WMName], c->name, sizeof c->name);