X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=c1749941faf2df7d110804a3c76cadb0dcfee2e7;hp=0e72c47a5d379ff8f2179ff43ecb1914356b7673;hb=5fa559dbfc6238a911c210ae4124586c6886df23;hpb=2c2063bc751d2b0db815c26734f186e64f0b9c12 diff --git a/dwm.c b/dwm.c index 0e72c47..c174994 100644 --- a/dwm.c +++ b/dwm.c @@ -178,6 +178,7 @@ void scan(void); void setclientstate(Client *c, long state); void setgeom(const char *arg); void setlayout(const char *arg); +void setmfact(const char *arg); void setup(void); void spawn(const char *arg); void tag(const char *arg); @@ -211,6 +212,7 @@ char stext[256], buf[256]; int screen, sx, sy, sw, sh; int (*xerrorxlib)(Display *, XErrorEvent *); int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh; +double mfact; unsigned int numlockmask = 0; void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, @@ -237,14 +239,14 @@ Client *stack = NULL; Cursor cursor[CurLast]; Display *dpy; DC dc = {0}; -Geom *geom = NULL; -Layout *lt = NULL; Window root, barwin; /* configuration, allows nested code to access above variables */ #include "config.h" #define TAGSZ (LENGTH(tags) * sizeof(Bool)) -static Bool tmp[LENGTH(tags)]; +Bool tmp[LENGTH(tags)]; +Layout *lt = layouts; +Geom *geom = geoms; /* function implementations */ @@ -259,10 +261,9 @@ applyrules(Client *c) { XGetClassHint(dpy, c->win, &ch); for(i = 0; i < LENGTH(rules); i++) { r = &rules[i]; - if((r->title && strstr(c->name, r->title)) - || (ch.res_class && r->class && strstr(ch.res_class, r->class)) - || (ch.res_name && r->instance && strstr(ch.res_name, r->instance))) - { + if((!r->title || strstr(c->name, r->title)) + && (!r->class || (ch.res_class && strstr(ch.res_class, r->class))) + && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) { c->isfloating = r->isfloating; if(r->tag) { c->tags[idxoftag(r->tag)] = True; @@ -322,10 +323,14 @@ buttonpress(XEvent *e) { XButtonPressedEvent *ev = &e->xbutton; if(ev->window == barwin) { + if((ev->x < bgw) && ev->button == Button1) { + setgeom(NULL); + return; + } x = bgw; for(i = 0; i < LENGTH(tags); i++) { x += textw(tags[i]); - if(ev->x > bgw && ev->x < x) { + if(ev->x >= bgw && ev->x < x) { if(ev->button == Button1) { if(ev->state & MODKEY) tag(tags[i]); @@ -341,6 +346,8 @@ buttonpress(XEvent *e) { return; } } + if((ev->x < x + blw) && ev->button == Button1) + setlayout(NULL); } else if((c = getclient(ev->window))) { focus(c); @@ -426,7 +433,7 @@ configurenotify(XEvent *e) { if(ev->window == root && (ev->width != sw || ev->height != sh)) { sw = ev->width; sh = ev->height; - setgeom(NULL); + setgeom(geom->symbol); } } @@ -517,9 +524,11 @@ drawbar(void) { Client *c; dc.x = 0; - dc.w = bgw; - drawtext(geom->symbol, dc.norm, False); - dc.x += bgw; + if(bgw > 0) { + dc.w = bgw; + drawtext(geom->symbol, dc.norm, False); + dc.x += bgw; + } for(c = stack; c && !isvisible(c); c = c->snext); for(i = 0; i < LENGTH(tags); i++) { dc.w = textw(tags[i]); @@ -533,9 +542,13 @@ drawbar(void) { } dc.x += dc.w; } - dc.w = blw; - drawtext(lt->symbol, dc.norm, False); - x = dc.x + dc.w; + if(blw > 0) { + dc.w = blw; + drawtext(lt->symbol, dc.norm, False); + x = dc.x + dc.w; + } + else + x = dc.x; dc.w = textw(stext); dc.x = bw - dc.w; if(dc.x < x) { @@ -792,39 +805,20 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) { void grabbuttons(Client *c, Bool focused) { - XUngrabButton(dpy, AnyButton, AnyModifier, c->win); + int i, j; + unsigned int buttons[] = { Button1, Button2, Button3 }; + unsigned int modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, + MODKEY|numlockmask|LockMask} ; - if(focused) { - XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - - XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - - XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); - } + XUngrabButton(dpy, AnyButton, AnyModifier, c->win); + if(focused) + for(i = 0; i < LENGTH(buttons); i++) + for(j = 0; j < LENGTH(modifiers); j++) + XGrabButton(dpy, buttons[i], modifiers[j], c->win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); else - XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, - GrabModeAsync, GrabModeSync, None, None); + XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, + BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); } void @@ -1073,7 +1067,7 @@ monocle(void) { Client *c; for(c = clients; c; c = c->next) - if(isvisible(c)) + if((lt->isfloating || !c->isfloating) && isvisible(c)) resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS); } @@ -1183,9 +1177,9 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { if(sizehints) { /* set minimum possible */ - if (w < 1) + if(w < 1) w = 1; - if (h < 1) + if(h < 1) h = 1; /* temporarily remove base dimensions */ @@ -1193,10 +1187,12 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { h -= c->baseh; /* adjust for aspect limits */ - if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) { - if (w * c->maxay > h * c->maxax) + if(c->minax != c->maxax && c->minay != c->maxay + && c->minax > 0 && c->maxax > 0 && c->minay > 0 && c->maxay > 0) + { + if(w * c->maxay > h * c->maxax) w = h * c->maxax / c->maxay; - else if (w * c->minay < h * c->minax) + else if(w * c->minay < h * c->minax) h = w * c->minay / c->minax; } @@ -1411,12 +1407,18 @@ void setgeom(const char *arg) { unsigned int i; - for(i = 0; arg && i < LENGTH(geoms); i++) - if(!strcmp(geoms[i].symbol, arg)) - break; - if(i == LENGTH(geoms)) - return; - geom = &geoms[i]; + if(!arg) { + if(++geom == &geoms[LENGTH(geoms)]) + geom = &geoms[0]; + } + else { + for(i = 0; i < LENGTH(geoms); i++) + if(!strcmp(geoms[i].symbol, arg)) + break; + if(i == LENGTH(geoms)) + return; + geom = &geoms[i]; + } geom->apply(); updatebarpos(); arrange(); @@ -1424,20 +1426,18 @@ setgeom(const char *arg) { void setlayout(const char *arg) { - static Layout *revert = 0; unsigned int i; - if(!arg) - return; - for(i = 0; i < LENGTH(layouts); i++) - if(!strcmp(arg, layouts[i].symbol)) - break; - if(i == LENGTH(layouts)) - return; - if(revert && &layouts[i] == lt) - lt = revert; + if(!arg) { + if(++lt == &layouts[LENGTH(layouts)]) + lt = &layouts[0]; + } else { - revert = lt; + for(i = 0; i < LENGTH(layouts); i++) + if(!strcmp(arg, layouts[i].symbol)) + break; + if(i == LENGTH(layouts)) + return; lt = &layouts[i]; } if(sel) @@ -1447,6 +1447,25 @@ setlayout(const char *arg) { } void +setmfact(const char *arg) { + double d; + + if(lt->isfloating) + return; + if(!arg) + mfact = MFACT; + else { + d = strtod(arg, NULL); + if(arg[0] == '-' || arg[0] == '+') + d += mfact; + if(d < 0.1 || d > 0.9) + return; + mfact = d; + } + setgeom(geom->symbol); +} + +void setup(void) { unsigned int i, w; XSetWindowAttributes wa; @@ -1462,7 +1481,7 @@ setup(void) { sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); bh = dc.font.height + 2; - geom = &geoms[0]; + mfact = MFACT; geom->apply(); /* init atoms */ @@ -1498,16 +1517,13 @@ setup(void) { prevtags = emallocz(TAGSZ); seltags[0] = prevtags[0] = True; - /* init layouts */ - lt = &layouts[0]; - /* init bar */ - for(blw = i = 0; i < LENGTH(layouts); i++) { + for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { w = textw(layouts[i].symbol); if(w > blw) blw = w; } - for(bgw = i = 0; i < LENGTH(geoms); i++) { + for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) { w = textw(geoms[i].symbol); if(w > bgw) bgw = w; @@ -1913,3 +1929,4 @@ main(int argc, char *argv[]) { XCloseDisplay(dpy); return 0; } +