X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=235365b47176cf660098db4e69af90e84b54bace;hb=32c5046635da102dd3b6789462234e3147b190ab;hp=483641c221ca1d2b6b885e2eefa1d4c4aebd295e;hpb=0a9ef560c0b18e95298964a2d482bc64f48b6330;p=dwm.git diff --git a/dwm.c b/dwm.c index 483641c..235365b 100644 --- a/dwm.c +++ b/dwm.c @@ -52,6 +52,8 @@ #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 */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ @@ -70,7 +72,7 @@ struct Client { int minax, maxax, minay, maxay; long flags; int bw, oldbw; - Bool isbanned, isfixed, isfloating, isurgent; + Bool isbanned, isfixed, isfloating, ismax, isurgent; uint tags; Client *next; Client *prev; @@ -103,7 +105,6 @@ typedef struct { typedef struct { const char *symbol; void (*arrange)(void); - void (*updategeom)(void); } Layout; typedef struct { @@ -119,7 +120,6 @@ void applyrules(Client *c); void arrange(void); void attach(Client *c); void attachstack(Client *c); -void ban(Client *c); void buttonpress(XEvent *e); void checkotherwm(void); void cleanup(void); @@ -149,7 +149,6 @@ void initfont(const char *fontstr); Bool isoccupied(uint t); Bool isprotodel(Client *c); Bool isurgent(uint t); -Bool isvisible(Client *c); void keypress(XEvent *e); void killclient(const void *arg); void manage(Window w, XWindowAttributes *wa); @@ -170,21 +169,18 @@ 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); +void togglemax(const void *arg); void toggletag(const void *arg); void toggleview(const void *arg); -void unban(Client *c); void unmanage(Client *c); 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,8 +193,7 @@ void zoom(const void *arg); /* variables */ 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; +int by, bh, blw, wx, wy, ww, wh; uint seltags = 0; int (*xerrorxlib)(Display *, XErrorEvent *); uint numlockmask = 0; @@ -217,6 +212,7 @@ void (*handler[LASTEvent]) (XEvent *) = { [UnmapNotify] = unmapnotify }; Atom wmatom[WMLast], netatom[NetLast]; +Bool ismax = False; Bool otherwm, readin; Bool running = True; uint tagset[] = {1, 1}; /* after start, first tag is selected */ @@ -267,16 +263,17 @@ arrange(void) { Client *c; for(c = clients; c; c = c->next) - if(isvisible(c)) { - unban(c); + if(VISIBLE(c)) { if(!lt->arrange || c->isfloating) resize(c, c->x, c->y, c->w, c->h, True); } - else - ban(c); + else if(!c->isbanned) { + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + c->isbanned = True; + } focus(NULL); - if(lt->arrange) + if(lt->arrange && !ismax) lt->arrange(); restack(); } @@ -296,14 +293,6 @@ attachstack(Client *c) { } void -ban(Client *c) { - if(c->isbanned) - return; - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - c->isbanned = True; -} - -void buttonpress(XEvent *e) { uint i, x, mask; Client *c; @@ -312,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) { @@ -330,23 +319,23 @@ buttonpress(XEvent *e) { return; } } - if((ev->x < x + blw) && ev->button == Button1) - togglelayout(NULL); + if(ev->x < x + blw) { + if(ev->button == Button1) + togglelayout(NULL); + else if(ev->button == Button3) + togglemax(NULL); + } } else if((c = getclient(ev->window))) { focus(c); - if(CLEANMASK(ev->state) != MODKEY) + if(CLEANMASK(ev->state) != MODKEY || ismax) return; - if(ev->button == Button1) { - restack(); + if(ev->button == Button1) movemouse(c); - } else if(ev->button == Button2) togglefloating(NULL); - else if(ev->button == Button3 && !c->isfixed) { - restack(); + else if(ev->button == Button3 && !c->isfixed) resizemouse(c); - } } } @@ -369,10 +358,9 @@ checkotherwm(void) { void cleanup(void) { close(STDIN_FILENO); - while(stack) { - unban(stack); + view(NULL); + while(stack) unmanage(stack); - } if(dc.font.set) XFreeFontSet(dpy, dc.font.set); else @@ -444,7 +432,7 @@ configurerequest(XEvent *e) { if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) configure(c); - if(isvisible(c)) + if(VISIBLE(c)) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else @@ -497,9 +485,9 @@ drawbar(void) { Client *c; dc.x = 0; - for(c = stack; c && !isvisible(c); c = c->snext); + 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); @@ -512,16 +500,16 @@ drawbar(void) { } if(blw > 0) { dc.w = blw; - drawtext(lt->symbol, dc.norm, False); + drawtext(lt->symbol, dc.norm, ismax); x = dc.x + dc.w; } else x = dc.x; - dc.w = textw(stext); - dc.x = bw - dc.w; + dc.w = TEXTW(stext); + dc.x = ww - dc.w; if(dc.x < x) { dc.x = x; - dc.w = bw - x; + dc.w = ww - x; } drawtext(stext, dc.norm, False); if((dc.w = dc.x - x) > bh) { @@ -533,7 +521,7 @@ drawbar(void) { else drawtext(NULL, dc.norm, False); } - XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); + XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0); XSync(dpy, False); } @@ -628,8 +616,8 @@ expose(XEvent *e) { void focus(Client *c) { - if(!c || (c && !isvisible(c))) - for(c = stack; c && !isvisible(c); c = c->snext); + if(!c || (c && !VISIBLE(c))) + for(c = stack; c && !VISIBLE(c); c = c->snext); if(sel && sel != c) { grabbuttons(sel, False); XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]); @@ -641,6 +629,10 @@ focus(Client *c) { } sel = c; if(c) { + if(ismax) { + XMoveResizeWindow(dpy, c->win, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw); + c->ismax = True; + } XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); } @@ -663,9 +655,9 @@ focusnext(const void *arg) { if(!sel) return; - for(c = sel->next; c && !isvisible(c); c = c->next); + for(c = sel->next; c && !VISIBLE(c); c = c->next); if(!c) - for(c = clients; c && !isvisible(c); c = c->next); + for(c = clients; c && !VISIBLE(c); c = c->next); if(c) { focus(c); restack(); @@ -678,10 +670,10 @@ focusprev(const void *arg) { if(!sel) return; - for(c = sel->prev; c && !isvisible(c); c = c->prev); + for(c = sel->prev; c && !VISIBLE(c); c = c->prev); if(!c) { for(c = clients; c && c->next; c = c->next); - for(; c && !isvisible(c); c = c->prev); + for(; c && !VISIBLE(c); c = c->prev); } if(c) { focus(c); @@ -873,11 +865,6 @@ isurgent(uint t) { return False; } -Bool -isvisible(Client *c) { - return c->tags & tagset[seltags]; -} - void keypress(XEvent *e) { uint i; @@ -965,7 +952,6 @@ manage(Window w, XWindowAttributes *wa) { attach(c); attachstack(c); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ - ban(c); XMapWindow(dpy, c->win); setclientstate(c, NormalState); arrange(); @@ -1000,6 +986,7 @@ movemouse(Client *c) { Window dummy; XEvent ev; + restack(); ocx = nx = c->x; ocy = ny = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, @@ -1043,7 +1030,7 @@ movemouse(Client *c) { Client * nexttiled(Client *c) { - for(; c && (c->isfloating || !isvisible(c)); c = c->next); + for(; c && (c->isfloating || !VISIBLE(c)); c = c->next); return c; } @@ -1135,7 +1122,12 @@ 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(c->x != x || c->y != y || c->w != w || c->h != h) { + 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; c->y = wc.y = y; c->w = wc.width = w; @@ -1154,6 +1146,7 @@ resizemouse(Client *c) { int nw, nh; XEvent ev; + restack(); ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, @@ -1201,13 +1194,13 @@ restack(void) { drawbar(); if(!sel) return; - if(sel->isfloating || !lt->arrange) + if(ismax || sel->isfloating || !lt->arrange) XRaiseWindow(dpy, sel->win); - if(lt->arrange) { + if(!ismax && lt->arrange) { wc.stack_mode = Below; wc.sibling = barwin; for(c = stack; c; c = c->snext) - if(!c->isfloating && isvisible(c)) { + if(!c->isfloating && VISIBLE(c)) { XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); wc.sibling = c->win; } @@ -1322,7 +1315,6 @@ setmfact(const void *arg) { if(d < 0.1 || d > 0.9) return; mfact = d; - updatetilegeom(); arrange(); } @@ -1372,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); } @@ -1380,7 +1372,7 @@ setup(void) { wa.background_pixmap = ParentRelative; wa.event_mask = ButtonPressMask|ExposureMask; - barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), + barwin = XCreateWindow(dpy, root, wx, by, ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); XDefineCursor(dpy, barwin, cursor[CurNormal]); @@ -1444,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; @@ -1461,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(); @@ -1537,6 +1511,12 @@ togglelayout(const void *arg) { } void +togglemax(const void *arg) { + ismax = !ismax; + arrange(); +} + +void toggletag(const void *arg) { if(sel && (sel->tags ^ ((*(int *)arg) & TAGMASK))) { sel->tags ^= (*(int *)arg) & TAGMASK; @@ -1553,14 +1533,6 @@ toggleview(const void *arg) { } void -unban(Client *c) { - if(!c->isbanned) - return; - XMoveWindow(dpy, c->win, c->x, c->y); - c->isbanned = False; -} - -void unmanage(Client *c) { XWindowChanges wc; @@ -1595,8 +1567,8 @@ void updatebar(void) { if(dc.drawable != 0) XFreePixmap(dpy, dc.drawable); - dc.drawable = XCreatePixmap(dpy, root, bw, bh, DefaultDepth(dpy, screen)); - XMoveResizeWindow(dpy, barwin, bx, by, bw, bh); + dc.drawable = XCreatePixmap(dpy, root, ww, bh, DefaultDepth(dpy, screen)); + XMoveResizeWindow(dpy, barwin, wx, by, ww, bh); } void @@ -1623,15 +1595,8 @@ updategeom(void) { wh = showbar ? sh - bh : sh; } - /* bar geometry */ - bx = wx; + /* bar position */ 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 @@ -1687,21 +1652,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);