diff options
Diffstat (limited to '')
-rw-r--r-- | dwm.c | 248 |
1 files changed, 46 insertions, 202 deletions
@@ -189,8 +189,6 @@ static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); -static void moveresize(const Arg *arg); -static void moveresizeedge(const Arg *arg); static void movemouse(const Arg *arg); static Client *nexttagged(Client *c); static Client *nexttiled(Client *c); @@ -215,8 +213,6 @@ static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void sigchld(int unused); -static void sighup(int unused); -static void sigterm(int unused); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -276,7 +272,6 @@ static void (*handler[LASTEvent]) (XEvent *) = { [UnmapNotify] = unmapnotify }; static Atom wmatom[WMLast], netatom[NetLast]; -static int restart = 0; static int running = 1; static Cur *cursor[CurLast]; static Clr **scheme; @@ -294,6 +289,7 @@ struct Pertag { float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */ const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */ + int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ }; /* compile-time check if all tags fit into an unsigned int bit array. */ @@ -498,10 +494,10 @@ buttonpress(XEvent *e) else click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { - if (focusonwheel || (ev->button != Button4 && ev->button != Button5)) - focus(c); - XAllowEvents(dpy, ReplayPointer, CurrentTime); - click = ClkClientWin; + if (focusonwheel || (ev->button != Button4 && ev->button != Button5)) + focus(c); + XAllowEvents(dpy, ReplayPointer, CurrentTime); + click = ClkClientWin; } for (i = 0; i < LENGTH(buttons); i++) if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button @@ -685,7 +681,7 @@ Monitor * createmon(void) { Monitor *m; - int i; + unsigned int i; m = ecalloc(1, sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; @@ -696,21 +692,20 @@ createmon(void) m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); - if (!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag)))) - die("fatal: could not malloc() %u bytes\n", sizeof(Pertag)); + m->pertag = ecalloc(1, sizeof(Pertag)); m->pertag->curtag = m->pertag->prevtag = 1; - for (i=0; i <= LENGTH(tags); i++) { - /* init nmaster */ - m->pertag->nmasters[i] = m->nmaster; - /* init mfacts */ + for (i = 0; i <= LENGTH(tags); i++) { + m->pertag->nmasters[i] = m->nmaster; m->pertag->mfacts[i] = m->mfact; - /* init layouts */ m->pertag->ltidxs[i][0] = m->lt[0]; m->pertag->ltidxs[i][1] = m->lt[1]; m->pertag->sellts[i] = m->sellt; + + m->pertag->showbars[i] = m->showbar; } + return m; } @@ -771,6 +766,9 @@ drawbar(Monitor *m) unsigned int i, occ = 0, urg = 0; Client *c; + if (!m->showbar) + return; + /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ drw_setscheme(drw, scheme[SchemeNorm]); @@ -885,7 +883,7 @@ focusstack(const Arg *arg) { Client *c = NULL, *i; - if (!selmon->sel || selmon->sel->isfullscreen) + if (!selmon->sel || (selmon->sel->isfullscreen && lockfullscreen)) return; if (arg->i > 0) { for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); @@ -992,7 +990,7 @@ grabbuttons(Client *c, int focused) XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, - GrabModeSync, GrabModeSync, None, None); + GrabModeAsync, GrabModeSync, None, None); } } @@ -1014,12 +1012,12 @@ grabkeys(void) } } -/* void */ -/* incnmaster(const Arg *arg) */ -/* { */ -/* selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0); */ -/* arrange(selmon); */ -/* } */ +void +incnmaster(const Arg *arg) +{ + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0); + arrange(selmon); +} #ifdef XINERAMA static int @@ -1113,6 +1111,7 @@ manage(Window w, XWindowAttributes *wa) c->sfy = c->y; c->sfw = c->w; c->sfh = c->h; + XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); if (!c->isfloating) @@ -1232,153 +1231,6 @@ movemouse(const Arg *arg) } } -void -moveresize(const Arg *arg) { - /* only floating windows can be moved */ - Client *c; - c = selmon->sel; - int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh; - char xAbs, yAbs, wAbs, hAbs; - int msx, msy, dx, dy, nmx, nmy; - unsigned int dui; - Window dummy; - - if (!c || !arg) - return; - if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) - return; - if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y, &yAbs, &w, &wAbs, &h, &hAbs) != 8) - return; - - /* compute new window position; prevent window from be positioned outside the current monitor */ - nw = c->w + w; - if (wAbs == 'W') - nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * c->bw; - - nh = c->h + h; - if (hAbs == 'H') - nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * c->bw; - - nx = c->x + x; - if (xAbs == 'X') { - if (x < selmon->mx) - nx = selmon->mx; - else if (x > selmon->mx + selmon->mw) - nx = selmon->mx + selmon->mw - nw - 2 * c->bw; - else - nx = x; - } - - ny = c->y + y; - if (yAbs == 'Y') { - if (y < selmon->my) - ny = selmon->my; - else if (y > selmon->my + selmon->mh) - ny = selmon->my + selmon->mh - nh - 2 * c->bw; - else - ny = y; - } - - ox = c->x; - oy = c->y; - ow = c->w; - oh = c->h; - - XRaiseWindow(dpy, c->win); - Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui); - resize(c, nx, ny, nw, nh, True); - - /* move cursor along with the window to avoid problems caused by the sloppy focus */ - if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy) - { - nmx = c->x - ox + c->w - ow; - nmy = c->y - oy + c->h - oh; - XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy); - } -} - -void -moveresizeedge(const Arg *arg) { - /* move or resize floating window to edge of screen */ - Client *c; - c = selmon->sel; - char e; - int nx, ny, nw, nh, ox, oy, ow, oh; - int msx, msy, dx, dy, nmx, nmy; - int starty; - unsigned int dui; - Window dummy; - - nx = c->x; - ny = c->y; - nw = c->w; - nh = c->h; - - starty = selmon->showbar ? bh : 0; - - if (!c || !arg) - return; - if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) - return; - if(sscanf((char *)arg->v, "%c", &e) != 1) - return; - - if(e == 't') - ny = starty; - - if(e == 'b') - ny = c->h > selmon->mh - 2 * c->bw ? c->h : selmon->mh - c->h - 2 * c->bw; - - if(e == 'l') - nx = 0; - - if(e == 'r') - nx = c->w > selmon->mw - 2 * c->bw ? c->w : selmon->mw - c->w - 2 * c->bw; - - if(e == 'T') { - /* if you click to resize again, it will return to old size/position */ - if(c->h + starty == c->oldh + c->oldy) { - nh = c->oldh; - ny = c->oldy; - } else { - nh = c->h + c->y - starty; - ny = starty; - } - } - - if(e == 'B') - nh = c->h + c->y + 2 * c->bw == selmon->mh ? c->oldh : selmon->mh - c->y - 2 * c->bw; - - if(e == 'L') { - if(c->w == c->oldw + c->oldx) { - nw = c->oldw; - nx = c->oldx; - } else { - nw = c->w + c->x; - nx = 0; - } - } - - if(e == 'R') - nw = c->w + c->x + 2 * c->bw == selmon->mw ? c->oldw : selmon->mw - c->x - 2 * c->bw; - - ox = c->x; - oy = c->y; - ow = c->w; - oh = c->h; - - XRaiseWindow(dpy, c->win); - Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui); - resize(c, nx, ny, nw, nh, True); - - /* move cursor along with the window to avoid problems caused by the sloppy focus */ - if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy) { - nmx = c->x - ox + c->w - ow; - nmy = c->y - oy + c->h - oh; - XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy); - } -} - Client * nexttagged(Client *c) { Client *walked = c->mon->clients; @@ -1445,7 +1297,6 @@ propertynotify(XEvent *e) void quit(const Arg *arg) { - if(arg->i) restart = 1; running = 0; } @@ -1705,13 +1556,10 @@ setfullscreen(Client *c, int fullscreen) void setlayout(const Arg *arg) { - if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) { - selmon->pertag->sellts[selmon->pertag->curtag] ^= 1; - selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; - } + if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1; if (arg && arg->v) - selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v; - selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v; strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); if (selmon->sel) arrange(selmon); @@ -1744,9 +1592,6 @@ setup(void) /* clean up any zombies immediately */ sigchld(0); - signal(SIGHUP, sighup); - signal(SIGTERM, sigterm); - /* init screen */ screen = DefaultScreen(dpy); sw = DisplayWidth(dpy, screen); @@ -1848,22 +1693,10 @@ sigchld(int unused) } void -sighup(int unused) -{ - Arg a = {.i = 1}; - quit(&a); -} - -void -sigterm(int unused) -{ - Arg a = {.i = 0}; - quit(&a); -} - -void spawn(const Arg *arg) { + if (arg->v == dmenucmd) + dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); @@ -1954,7 +1787,7 @@ tile(Monitor *m) void togglebar(const Arg *arg) { - selmon->showbar = !selmon->showbar; + selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar; updatebarpos(selmon); XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); arrange(selmon); @@ -2011,17 +1844,19 @@ toggleview(const Arg *arg) int i; if (newtagset) { + selmon->tagset[selmon->seltags] = newtagset; + if (newtagset == ~0) { selmon->pertag->prevtag = selmon->pertag->curtag; selmon->pertag->curtag = 0; } + /* test if the user did not select the same tag */ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) { selmon->pertag->prevtag = selmon->pertag->curtag; - for (i=0; !(newtagset & 1 << i); i++) ; + for (i = 0; !(newtagset & 1 << i); i++) ; selmon->pertag->curtag = i + 1; } - selmon->tagset[selmon->seltags] = newtagset; /* apply settings for this view */ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; @@ -2029,6 +1864,10 @@ toggleview(const Arg *arg) selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) + togglebar(NULL); + focus(NULL); arrange(selmon); } @@ -2342,12 +2181,13 @@ view(const Arg *arg) return; selmon->seltags ^= 1; /* toggle sel tagset */ if (arg->ui & TAGMASK) { - selmon->pertag->prevtag = selmon->pertag->curtag; selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; + selmon->pertag->prevtag = selmon->pertag->curtag; + if (arg->ui == ~0) selmon->pertag->curtag = 0; else { - for (i=0; !(arg->ui & 1 << i); i++) ; + for (i = 0; !(arg->ui & 1 << i); i++) ; selmon->pertag->curtag = i + 1; } } else { @@ -2355,11 +2195,16 @@ view(const Arg *arg) selmon->pertag->prevtag = selmon->pertag->curtag; selmon->pertag->curtag = tmptag; } + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; + + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) + togglebar(NULL); + focus(NULL); arrange(selmon); } @@ -2463,7 +2308,6 @@ main(int argc, char *argv[]) #endif /* __OpenBSD__ */ scan(); run(); - if(restart) execvp(argv[0], argv); cleanup(); XCloseDisplay(dpy); return EXIT_SUCCESS; |