X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=c1749941faf2df7d110804a3c76cadb0dcfee2e7;hp=e1c8c200c2baa6038277e14da39fa92609232507;hb=5fa559dbfc6238a911c210ae4124586c6886df23;hpb=20cd3360876f551c0f3b4c9c5a827a64b829e6ef diff --git a/dwm.c b/dwm.c index e1c8c20..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; @@ -329,7 +330,7 @@ buttonpress(XEvent *e) { 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]); @@ -804,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 @@ -1085,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); } @@ -1195,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 */ @@ -1205,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; } @@ -1463,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; @@ -1478,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 */ @@ -1514,9 +1517,6 @@ setup(void) { prevtags = emallocz(TAGSZ); seltags[0] = prevtags[0] = True; - /* init layouts */ - lt = &layouts[0]; - /* init bar */ for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { w = textw(layouts[i].symbol); @@ -1929,3 +1929,4 @@ main(int argc, char *argv[]) { XCloseDisplay(dpy); return 0; } +