dwm

my heavily-patched and customized dwm build
git clone git://git.kocotian.pl/dwm.git
Log | Files | Refs | README | LICENSE

commit d2100ff970fd0bc7fc06e8cbe0b1145a41a384f5
parent cb09baf1c9eee01bde9d78b13438d300018c07cd
Author: kocotian <kocotian@kocotian.pl>
Date:   Sat,  2 Jan 2021 16:06:20 +0100

resizing via keyboard and my own patch

Diffstat:
Mconfig.def.h | 51+++++++++++++++++++++++++++++++++++++++++++++------
Mdwm.c | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Apatches/dwm-moveresize-20201206-cce77d8.diff | 195+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 390 insertions(+), 6 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -1,5 +1,8 @@ /* See LICENSE file for copyright and license details. */ +/* functions */ +static void modmove(const Arg *arg); + /* appearance */ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ @@ -144,6 +147,7 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_e, spawn, SHCMD("st -e abook -C ~/.config/abook/abookrc --datafile ~/.config/abook/addressbook") }, { MODKEY, XK_r, reorganizetags, {0} }, { MODKEY|ShiftMask, XK_r, setcfact, {.f = 0.00} }, + { MODKEY, XK_o, incnmaster, {.i = +1 } }, { MODKEY|ShiftMask, XK_o, incnmaster, {.i = -1 } }, { MODKEY, XK_p, spawn, SHCMD("mpc toggle") }, @@ -158,18 +162,27 @@ static Key keys[] = { { MODKEY, XK_d, spawn, {.v = dmenucmd } }, { MODKEY|ShiftMask, XK_d, spawn, SHCMD("dmenize") }, { MODKEY, XK_f, togglefullscr, {0} }, + + /* bits: [hk/jl], [jk/hl], [withControl] */ + + { MODKEY|ShiftMask, XK_j, modmove, {.i = (0 + (0 << 1) + (0 << 2))} }, + { MODKEY|ShiftMask, XK_k, modmove, {.i = (0 + (0 << 1) + (1 << 2))} }, + { MODKEY|ShiftMask, XK_h, modmove, {.i = (0 + (1 << 1) + (0 << 2))} }, + { MODKEY|ShiftMask, XK_l, modmove, {.i = (0 + (1 << 1) + (1 << 2))} }, + { MODKEY|ControlMask, XK_j, modmove, {.i = (1 + (0 << 1) + (0 << 2))} }, + { MODKEY|ControlMask, XK_k, modmove, {.i = (1 + (0 << 1) + (1 << 2))} }, + { MODKEY|ControlMask, XK_h, modmove, {.i = (1 + (1 << 1) + (0 << 2))} }, + { MODKEY|ControlMask, XK_l, modmove, {.i = (1 + (1 << 1) + (1 << 2))} }, + { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, - { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, + { MODKEY, XK_h, setmfact, {.f = -0.05} }, + { MODKEY, XK_l, setmfact, {.f = +0.05} }, { MODKEY|Mod1Mask, XK_j, focusmon, {.i = -1 } }, { MODKEY|Mod1Mask, XK_k, focusmon, {.i = +1 } }, { MODKEY|Mod1Mask|ShiftMask, XK_j, tagmon, {.i = -1 } }, { MODKEY|Mod1Mask|ShiftMask, XK_k, tagmon, {.i = +1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY|ShiftMask, XK_h, setcfact, {.f = -0.25} }, - { MODKEY|ShiftMask, XK_l, setcfact, {.f = +0.25} }, + { MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_z, setlayout, {0} }, @@ -229,3 +242,29 @@ static Button buttons[] = { { ClkTagBar, MODKEY, Button1, tag, {0} }, { ClkTagBar, MODKEY, Button3, toggletag, {0} }, }; + +static void modmove(const Arg *arg) +{ + int f; + f = selmon->sel->isfloating; + Arg a; + + /* bits: [hk/jl], [jk/hl], [withControl] */ + if ((arg->i >> 1) & 1) { /* hl */ + if ((arg->i >> 2) & 1) { /* l */ + if (f) a.v = (arg->i & 1 ? "0x 0y 25w 0h" : "25x 0y 0w 0h"), moveresize(&a); + else a.f = +0.25, setcfact(&a); + } else { /* h */ + if (f) a.v = (arg->i & 1 ? "0x 0y -25w 0h" : "-25x 0y 0w 0h"), moveresize(&a); + else a.f = -0.25, setcfact(&a); + } + } else { /* jk */ + if ((arg->i >> 2) & 1) { /* k */ + if (f) a.v = (arg->i & 1 ? "0x 0y 0w -25h" : "0x -25y 0w 0h"), moveresize(&a); + else a.f = -1, movestack(&a); + } else { /* j */ + if (f) a.v = (arg->i & 1 ? "0x 0y 0w 25h" : "0x 25y 0w 0h"), moveresize(&a); + else a.f = +1, movestack(&a); + } + } +} diff --git a/dwm.c b/dwm.c @@ -221,6 +221,8 @@ static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); +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); @@ -1607,6 +1609,154 @@ nexttagged(Client *c) { return walked; } +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, bp; + 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 && topbar ? bh : 0; + bp = selmon->showbar && !topbar ? 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 - bp : selmon->mh - c->h - 2 * c->bw - bp; + + if(e == 'l') + nx = selmon->mx; + + if(e == 'r') + nx = c->w > selmon->mw - 2 * c->bw ? selmon->mx + c->w : selmon->mx + 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 + bp == selmon->mh ? c->oldh : selmon->mh - c->y - 2 * c->bw - bp; + + if(e == 'L') { + if(selmon->mx + c->w == c->oldw + c->oldx) { + nw = c->oldw; + nx = c->oldx; + } else { + nw = c->w + c->x - selmon->mx; + nx = selmon->mx; + } + } + + if(e == 'R') + nw = c->w + c->x + 2 * c->bw == selmon->mx + selmon->mw ? c->oldw : selmon->mx + 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 * nexttiled(Client *c) { diff --git a/patches/dwm-moveresize-20201206-cce77d8.diff b/patches/dwm-moveresize-20201206-cce77d8.diff @@ -0,0 +1,195 @@ +diff --git a/config.def.h b/config.def.h +index 1c0b587..4195232 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -78,6 +78,22 @@ static Key keys[] = { + { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, + { MODKEY, XK_space, setlayout, {0} }, + { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, ++ { MODKEY, XK_Down, moveresize, {.v = "0x 25y 0w 0h" } }, ++ { MODKEY, XK_Up, moveresize, {.v = "0x -25y 0w 0h" } }, ++ { MODKEY, XK_Right, moveresize, {.v = "25x 0y 0w 0h" } }, ++ { MODKEY, XK_Left, moveresize, {.v = "-25x 0y 0w 0h" } }, ++ { MODKEY|ShiftMask, XK_Down, moveresize, {.v = "0x 0y 0w 25h" } }, ++ { MODKEY|ShiftMask, XK_Up, moveresize, {.v = "0x 0y 0w -25h" } }, ++ { MODKEY|ShiftMask, XK_Right, moveresize, {.v = "0x 0y 25w 0h" } }, ++ { MODKEY|ShiftMask, XK_Left, moveresize, {.v = "0x 0y -25w 0h" } }, ++ { MODKEY|ControlMask, XK_Up, moveresizeedge, {.v = "t"} }, ++ { MODKEY|ControlMask, XK_Down, moveresizeedge, {.v = "b"} }, ++ { MODKEY|ControlMask, XK_Left, moveresizeedge, {.v = "l"} }, ++ { MODKEY|ControlMask, XK_Right, moveresizeedge, {.v = "r"} }, ++ { MODKEY|ControlMask|ShiftMask, XK_Up, moveresizeedge, {.v = "T"} }, ++ { MODKEY|ControlMask|ShiftMask, XK_Down, moveresizeedge, {.v = "B"} }, ++ { MODKEY|ControlMask|ShiftMask, XK_Left, moveresizeedge, {.v = "L"} }, ++ { MODKEY|ControlMask|ShiftMask, XK_Right, moveresizeedge, {.v = "R"} }, + { MODKEY, XK_0, view, {.ui = ~0 } }, + { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, + { MODKEY, XK_comma, focusmon, {.i = -1 } }, +diff --git a/dwm.c b/dwm.c +index 4465af1..c08deaf 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -182,6 +182,8 @@ static void mappingnotify(XEvent *e); + static void maprequest(XEvent *e); + static void monocle(Monitor *m); + static void motionnotify(XEvent *e); ++static void moveresize(const Arg *arg); ++static void moveresizeedge(const Arg *arg); + static void movemouse(const Arg *arg); + static Client *nexttiled(Client *c); + static void pop(Client *); +@@ -1192,6 +1194,154 @@ 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, bp; ++ 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 && topbar ? bh : 0; ++ bp = selmon->showbar && !topbar ? 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 - bp : selmon->mh - c->h - 2 * c->bw - bp; ++ ++ if(e == 'l') ++ nx = selmon->mx; ++ ++ if(e == 'r') ++ nx = c->w > selmon->mw - 2 * c->bw ? selmon->mx + c->w : selmon->mx + 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 + bp == selmon->mh ? c->oldh : selmon->mh - c->y - 2 * c->bw - bp; ++ ++ if(e == 'L') { ++ if(selmon->mx + c->w == c->oldw + c->oldx) { ++ nw = c->oldw; ++ nx = c->oldx; ++ } else { ++ nw = c->w + c->x - selmon->mx; ++ nx = selmon->mx; ++ } ++ } ++ ++ if(e == 'R') ++ nw = c->w + c->x + 2 * c->bw == selmon->mx + selmon->mw ? c->oldw : selmon->mx + 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 * + nexttiled(Client *c) + {