From 13ebf171dd7c7cf3fdba6d89c184a644fc37ac38 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 7 Jun 2020 12:15:12 -0700 Subject: dwm fork working (marginally) --- sys/cmd/dwm/config.h | 6 +- sys/cmd/dwm/dwm.c | 4 +- sys/cmd/dwm/hook.c | 369 ++++++++++++++++++++++++++++++++++++++++++++++++++ sys/cmd/term/config.h | 2 +- 4 files changed, 375 insertions(+), 6 deletions(-) create mode 100644 sys/cmd/dwm/hook.c (limited to 'sys/cmd') diff --git a/sys/cmd/dwm/config.h b/sys/cmd/dwm/config.h index 47ee371..2f58151 100644 --- a/sys/cmd/dwm/config.h +++ b/sys/cmd/dwm/config.h @@ -31,9 +31,9 @@ static Rule rules[] = { * WM_NAME(STRING) = title */ /* class instance title tags mask isfloating isterminal noswallow monitor */ - { "Gimp", nil, nil, 0, 1, 0, 0, -1 }, - { "qutebrowser", nil, nil, 1 << 8, 0, 0, -1, -1 }, - { "term", nil, nil, 0, 0, 0, -1, -1 }, + { "Gimp", nil, nil, 1 << 8, 1, 0, 0, -1 }, + { "qutebrowser", nil, nil, 0, 0, 0, 0, -1 }, + { "term", nil, nil, 0, 0, 0, -1, -1 }, }; /* layout(s) */ diff --git a/sys/cmd/dwm/dwm.c b/sys/cmd/dwm/dwm.c index 8e8d44c..a3b01bd 100644 --- a/sys/cmd/dwm/dwm.c +++ b/sys/cmd/dwm/dwm.c @@ -864,8 +864,8 @@ tile(Monitor *m) } else { h = (m->wh - ty) / (n - i) - m->gapx; resize(c, m->wx + mw + m->gapx, m->wy + ty, m->ww - mw - (2*c->bw) - (2*m->gapx), h - (2*c->bw), 0); - if (ty + HEIGHT(c) < m->wh) - ty += HEIGHT(c); + if (ty + HEIGHT(c) + m->gapx < m->wh) + ty += HEIGHT(c) + m->gapx; } } diff --git a/sys/cmd/dwm/hook.c b/sys/cmd/dwm/hook.c new file mode 100644 index 0000000..71bb160 --- /dev/null +++ b/sys/cmd/dwm/hook.c @@ -0,0 +1,369 @@ +#include "dwm.h" + +void +focusmon(Arg *arg) +{ + Monitor *m; + + if (!mons->next) + return; + if ((m = dirtomon(arg->i)) == selmon) + return; + unfocus(selmon->sel, 0); + selmon = m; + focus(nil); +} + +void +focusstack(Arg *arg) +{ + Client *c = nil, *i; + + if (!selmon->sel) + return; + if (arg->i > 0) { + for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); + if (!c) + for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); + } else { + for (i = selmon->clients; i != selmon->sel; i = i->next) + if (ISVISIBLE(i)) + c = i; + if (!c) + for (; i; i = i->next) + if (ISVISIBLE(i)) + c = i; + } + if (c) { + focus(c); + restack(selmon); + } +} + +void +rotatestack(Arg *arg) +{ + Client *c = nil, *f; + + if (!selmon->sel) + return; + + f = selmon->sel; + if (arg->i > 0) { + for (c = nexttiled(selmon->clients); c && nexttiled(c->next); c = nexttiled(c->next)) + ; + + if (c) { + detach(c); + attach(c); + detachstack(c); + attachstack(c); + } + } else { + if ((c = nexttiled(selmon->clients))) { + detach(c); + enqueue(c); + detachstack(c); + enqueuestack(c); + } + } + + if (c) { + arrange(selmon); + focus(f); + restack(selmon); + } +} + + +void +incnmaster(Arg *arg) +{ + selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); + arrange(selmon); +} + +void +killclient(Arg *arg) +{ + if (!selmon->sel) + return; + if (!sendevent(selmon->sel, wmatom[WMDelete])) { + XGrabServer(dpy); + XSetErrorHandler(xerrordummy); + XSetCloseDownMode(dpy, DestroyAll); + XKillClient(dpy, selmon->sel->win); + XSync(dpy, False); + XSetErrorHandler(xerror); + XUngrabServer(dpy); + } +} + +void +movemouse(Arg *arg) +{ + int x, y, ocx, ocy, nx, ny; + Client *c; + Monitor *m; + XEvent ev; + Time lasttime = 0; + + if (!(c = selmon->sel)) + return; + if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ + return; + restack(selmon); + ocx = c->x; + ocy = c->y; + if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + None, cursor[MouseMove]->cursor, CurrentTime) != GrabSuccess) + return; + if (!getrootptr(&x, &y)) + return; + do { + XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); + switch(ev.type) { + case ConfigureRequest: + case Expose: + case MapRequest: + handler[ev.type](&ev); + break; + case MotionNotify: + if ((ev.xmotion.time - lasttime) <= (1000 / 60)) + continue; + lasttime = ev.xmotion.time; + + nx = ocx + (ev.xmotion.x - x); + ny = ocy + (ev.xmotion.y - y); + if (abs(selmon->wx - nx) < snap) + nx = selmon->wx; + else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) + nx = selmon->wx + selmon->ww - WIDTH(c); + if (abs(selmon->wy - ny) < snap) + ny = selmon->wy; + else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) + ny = selmon->wy + selmon->wh - HEIGHT(c); + if (!c->isfloating && selmon->lt[selmon->sellt]->arrange + && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) + togglefloating(nil); + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) + resize(c, nx, ny, c->w, c->h, 1); + break; + } + } while (ev.type != ButtonRelease); + XUngrabPointer(dpy, CurrentTime); + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendtomon(c, m); + selmon = m; + focus(nil); + } +} + +void +quit(Arg *arg) +{ + running = 0; +} + +void +resizemouse(Arg *arg) +{ + int ocx, ocy, nw, nh; + Client *c; + Monitor *m; + XEvent ev; + Time lasttime = 0; + + if (!(c = selmon->sel)) + return; + if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ + return; + restack(selmon); + ocx = c->x; + ocy = c->y; + if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, + None, cursor[MouseResize]->cursor, CurrentTime) != GrabSuccess) + return; + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); + do { + XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); + switch(ev.type) { + case ConfigureRequest: + case Expose: + case MapRequest: + handler[ev.type](&ev); + break; + case MotionNotify: + if ((ev.xmotion.time - lasttime) <= (1000 / 60)) + continue; + lasttime = ev.xmotion.time; + + nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); + nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); + if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww + && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) + { + if (!c->isfloating && selmon->lt[selmon->sellt]->arrange + && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) + togglefloating(nil); + } + if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) + resize(c, c->x, c->y, nw, nh, 1); + break; + } + } while (ev.type != ButtonRelease); + XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); + XUngrabPointer(dpy, CurrentTime); + while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); + if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { + sendtomon(c, m); + selmon = m; + focus(nil); + } +} + +void +setlayout(Arg *arg) +{ + if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) + selmon->sellt ^= 1; + if (arg && arg->v) + selmon->lt[selmon->sellt] = (Layout *)arg->v; + strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); + if (selmon->sel) + arrange(selmon); + else + drawbar(selmon); +} + +/* arg > 1.0 will set mfact absolutely */ +void +setmfact(Arg *arg) +{ + float f; + + if (!arg || !selmon->lt[selmon->sellt]->arrange) + return; + f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; + if (f < 0.05 || f > 0.95) + return; + selmon->mfact = f; + arrange(selmon); +} + +void +spawn(Arg *arg) +{ + if (arg->v == dmenucmd) + dmenumon[0] = '0' + selmon->num; + if (fork() == 0) { + if (dpy) + close(ConnectionNumber(dpy)); + setsid(); + execvp(((char **)arg->v)[0], (char **)arg->v); + fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); + perror(" failed"); + exit(EXIT_SUCCESS); + } +} + +void +tag(Arg *arg) +{ + if (selmon->sel && arg->ui & TAGMASK) { + selmon->sel->tags = arg->ui & TAGMASK; + focus(nil); + arrange(selmon); + } +} + +void +tagmon(Arg *arg) +{ + if (!selmon->sel || !mons->next) + return; + sendtomon(selmon->sel, dirtomon(arg->i)); +} + +void +togglebar(Arg *arg) +{ + selmon->showbar = !selmon->showbar; + updatebarpos(selmon); + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); + arrange(selmon); +} + +void +togglefloating(Arg *arg) +{ + if (!selmon->sel) + return; + if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ + return; + selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; + if (selmon->sel->isfloating) + resize(selmon->sel, selmon->sel->x, selmon->sel->y, + selmon->sel->w, selmon->sel->h, 0); + arrange(selmon); +} + +void +toggletag(Arg *arg) +{ + uint newtags; + + if (!selmon->sel) + return; + newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); + if (newtags) { + selmon->sel->tags = newtags; + focus(nil); + arrange(selmon); + } +} + +void +togglefocus(Arg *arg) +{ + if (selmon->sel) + setfullscreen(selmon->sel, !selmon->sel->isfullscreen); +} + +void +toggleview(Arg *arg) +{ + uint newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); + + if (newtagset) { + selmon->tagset[selmon->seltags] = newtagset; + focus(nil); + arrange(selmon); + } +} + +void +view(Arg *arg) +{ + if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) + return; + selmon->seltags ^= 1; /* toggle sel tagset */ + if (arg->ui & TAGMASK) + selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; + focus(nil); + arrange(selmon); +} + +void +zoom(Arg *arg) +{ + Client *c = selmon->sel; + + if (!selmon->lt[selmon->sellt]->arrange + || (selmon->sel && selmon->sel->isfloating)) + return; + if (c == nexttiled(selmon->clients)) + if (!c || !(c = nexttiled(c->next))) + return; + pop(c); +} diff --git a/sys/cmd/term/config.h b/sys/cmd/term/config.h index fcbe775..2b35a74 100644 --- a/sys/cmd/term/config.h +++ b/sys/cmd/term/config.h @@ -6,7 +6,7 @@ * * font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html */ -static char *font = "consolas:pixelsize=14:antialias=true"; +static char *font = "consolas:pixelsize=16:antialias=true"; static int borderpx = 2; /* -- cgit v1.2.1