X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=8dbe83baead81e6224016e8b05c639a73c378024;hp=76bca3839435162ad83c594ac262df22469e99f3;hb=5ccd42f80752be8f5152e09ecd250ba42739bf6d;hpb=d5c5c52b306be5509422d7074d7416df0d425d08 diff --git a/dwm.c b/dwm.c index 76bca38..8dbe83b 100644 --- a/dwm.c +++ b/dwm.c @@ -125,6 +125,7 @@ typedef struct { struct Monitor { char ltsymbol[16]; float mfact; + int nmaster; int num; int by; /* bar geometry */ int mx, my, mw, mh; /* screen size */ @@ -189,6 +190,7 @@ static long getstate(Window w); static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, Bool focused); static void grabkeys(void); +static void incnmaster(const Arg *arg); static void initfont(const char *fontstr); static void keypress(XEvent *e); static void killclient(const Arg *arg); @@ -289,31 +291,31 @@ applyrules(Client *c) { unsigned int i; const Rule *r; Monitor *m; - XClassHint ch = { 0 }; + XClassHint ch = { NULL, NULL }; /* rule matching */ c->isfloating = c->tags = 0; - if(XGetClassHint(dpy, c->win, &ch)) { - class = ch.res_class ? ch.res_class : broken; - instance = ch.res_name ? ch.res_name : broken; - for(i = 0; i < LENGTH(rules); i++) { - r = &rules[i]; - if((!r->title || strstr(c->name, r->title)) - && (!r->class || strstr(class, r->class)) - && (!r->instance || strstr(instance, r->instance))) - { - c->isfloating = r->isfloating; - c->tags |= r->tags; - for(m = mons; m && m->num != r->monitor; m = m->next); - if(m) - c->mon = m; - } + XGetClassHint(dpy, c->win, &ch); + class = ch.res_class ? ch.res_class : broken; + instance = ch.res_name ? ch.res_name : broken; + + for(i = 0; i < LENGTH(rules); i++) { + r = &rules[i]; + if((!r->title || strstr(c->name, r->title)) + && (!r->class || strstr(class, r->class)) + && (!r->instance || strstr(instance, r->instance))) + { + c->isfloating = r->isfloating; + c->tags |= r->tags; + for(m = mons; m && m->num != r->monitor; m = m->next); + if(m) + c->mon = m; } - if(ch.res_class) - XFree(ch.res_class); - if(ch.res_name) - XFree(ch.res_name); } + if(ch.res_class) + XFree(ch.res_class); + if(ch.res_name) + XFree(ch.res_name); c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; } @@ -349,7 +351,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) { *h = bh; if(*w < bh) *w = bh; - if(resizehints || c->isfloating) { + if(resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { /* see last two sentences in ICCCM 4.1.2.3 */ baseismin = c->basew == c->minw && c->baseh == c->minh; if(!baseismin) { /* temporarily remove base dimensions */ @@ -389,7 +391,6 @@ arrange(Monitor *m) { showhide(m->stack); else for(m = mons; m; m = m->next) showhide(m->stack); - focus(NULL); if(m) arrangemon(m); else for(m = mons; m; m = m->next) @@ -433,9 +434,9 @@ buttonpress(XEvent *e) { } if(ev->window == selmon->barwin) { i = x = 0; - do { + do x += TEXTW(tags[i]); - } while(ev->x >= x && ++i < LENGTH(tags)); + while(ev->x >= x && ++i < LENGTH(tags)); if(i < LENGTH(tags)) { click = ClkTagBar; arg.ui = 1 << i; @@ -598,6 +599,7 @@ configurenotify(XEvent *e) { updatebars(); for(m = mons; m; m = m->next) XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); + focus(NULL); arrange(NULL); } } @@ -664,6 +666,7 @@ createmon(void) { die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; m->mfact = mfact; + m->nmaster = nmaster; m->showbar = showbar; m->topbar = topbar; m->lt[0] = &layouts[0]; @@ -720,12 +723,10 @@ dirtomon(int dir) { if(!(m = selmon->next)) m = mons; } - else { - if(selmon == mons) - for(m = mons; m->next; m = m->next); - else - for(m = mons; m->next != selmon; m = m->next); - } + else if(selmon == mons) + for(m = mons; m->next; m = m->next); + else + for(m = mons; m->next != selmon; m = m->next); return m; } @@ -1017,21 +1018,25 @@ grabkeys(void) { KeyCode code; XUngrabKey(dpy, AnyKey, AnyModifier, root); - for(i = 0; i < LENGTH(keys); i++) { + for(i = 0; i < LENGTH(keys); i++) if((code = XKeysymToKeycode(dpy, keys[i].keysym))) for(j = 0; j < LENGTH(modifiers); j++) XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, GrabModeAsync, GrabModeAsync); - } } } void +incnmaster(const Arg *arg) { + selmon->nmaster = MAX(selmon->nmaster + arg->i, 1); + arrange(selmon); +} + +void initfont(const char *fontstr) { char *def, **missing; int n; - missing = NULL; dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); if(missing) { while(n--) @@ -1127,7 +1132,7 @@ manage(Window w, XWindowAttributes *wa) { c->h = c->oldh = wa->height; c->oldbw = wa->border_width; if(c->w == c->mon->mw && c->h == c->mon->mh) { - c->isfloating = True; + c->isfloating = True; // regression with flash, XXXX c->x = c->mon->mx; c->y = c->mon->my; c->bw = 0; @@ -1158,9 +1163,13 @@ manage(Window w, XWindowAttributes *wa) { attach(c); attachstack(c); XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ - XMapWindow(dpy, c->win); setclientstate(c, NormalState); + if (c->mon == selmon) + unfocus(selmon->sel, False); + c->mon->sel = c; arrange(c->mon); + XMapWindow(dpy, c->win); + focus(NULL); } void @@ -1311,6 +1320,7 @@ ptrtomon(int x, int y) { return m; return selmon; } + void quit(const Arg *arg) { running = False; @@ -1415,10 +1425,9 @@ run(void) { XEvent ev; /* main event loop */ XSync(dpy, False); - while(running && !XNextEvent(dpy, &ev)) { + while(running && !XNextEvent(dpy, &ev)) if(handler[ev.type]) handler[ev.type](&ev); /* call handler */ - } } void @@ -1597,7 +1606,7 @@ showhide(Client *c) { } else { /* hide clients bottom up */ showhide(c->snext); - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); } } @@ -1625,6 +1634,7 @@ void tag(const Arg *arg) { if(selmon->sel && arg->ui & TAGMASK) { selmon->sel->tags = arg->ui & TAGMASK; + focus(NULL); arrange(selmon); } } @@ -1649,32 +1659,26 @@ textnw(const char *text, unsigned int len) { void tile(Monitor *m) { - int x, y, h, w, mw; - unsigned int i, n; + unsigned int i, n, h, mw, my, ty; Client *c; for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if(n == 0) return; - /* master */ - c = nexttiled(m->clients); - mw = m->mfact * m->ww; - resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw, False); - if(--n == 0) - return; - /* tile stack */ - x = (m->wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : m->wx + mw; - y = m->wy; - w = (m->wx + mw > c->x + c->w) ? m->wx + m->ww - x : m->ww - mw; - h = m->wh / n; - if(h < bh) - h = m->wh; - for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) { - resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n) - ? m->wy + m->wh - y - 2 * c->bw : h - 2 * c->bw), False); - if(h != m->wh) - y = c->y + HEIGHT(c); - } + + mw = (n > m->nmaster) ? m->ww * m->mfact : m->ww; + + for(i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if(i < m->nmaster) { + h = (m->wh - my) / (MIN(n, m->nmaster) - i); + resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), False); + my += HEIGHT(c); + } + else { + h = (m->wh - ty) / (n - i); + resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), False); + ty += HEIGHT(c); + } } void @@ -1705,6 +1709,7 @@ toggletag(const Arg *arg) { newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); if(newtags) { selmon->sel->tags = newtags; + focus(NULL); arrange(selmon); } } @@ -1715,6 +1720,7 @@ toggleview(const Arg *arg) { if(newtagset) { selmon->tagset[selmon->seltags] = newtagset; + focus(NULL); arrange(selmon); } } @@ -1758,8 +1764,12 @@ unmapnotify(XEvent *e) { Client *c; XUnmapEvent *ev = &e->xunmap; - if((c = wintoclient(ev->window))) - unmanage(c, False); + if((c = wintoclient(ev->window))) { + if(ev->send_event) + setclientstate(c, WithdrawnState); + else + unmanage(c, False); + } } void @@ -1980,6 +1990,7 @@ view(const Arg *arg) { selmon->seltags ^= 1; /* toggle sel tagset */ if(arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; + focus(NULL); arrange(selmon); }