summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMouad Alami <mouad@alami.xyz>2024-05-14 15:52:18 +0100
committerMouad Alami <mouad@alami.xyz>2024-05-14 15:52:18 +0100
commit34978144156716e3b27fb512b80ffdd985966d69 (patch)
treeb80bcde6ad25b610410a1a4dfe78fa99f9aa16ea
parent17c480441a4dc4c0c0312b9cd32799274f587238 (diff)
Added moveresize patch
-rw-r--r--README2
-rw-r--r--config.h9
-rw-r--r--dwm.c68
3 files changed, 78 insertions, 1 deletions
diff --git a/README b/README
index 7cab161..e3e2782 100644
--- a/README
+++ b/README
@@ -49,4 +49,4 @@ and (re)compiling the source code.
Patches applied
---------------
-zoomswap - scratchpad - sticky - statuscmd - pertag - noborder - movestack - hide vacant tags - actualfullscreen - bar height - alpha monocle layout - alternativetags - bidi - togglefakefullscreen - swallow
+zoomswap - scratchpad - sticky - statuscmd - pertag - noborder - movestack - hide vacant tags - actualfullscreen - bar height - alpha monocle layout - alternativetags - bidi - togglefakefullscreen - swallow - moveresize
diff --git a/config.h b/config.h
index 2878abb..0bb42cd 100644
--- a/config.h
+++ b/config.h
@@ -138,6 +138,15 @@ static const Key keys[] = {
{ControlMask, XK_space, spawn, SHCMD("dunstctl close")},
{ControlMask | ShiftMask, XK_space, spawn, SHCMD("dunstctl close-all")},
+ { Mod1Mask|ControlMask, XK_j, moveresize, {.v = "0x 25y 0w 0h" } },
+ { Mod1Mask|ControlMask, XK_k, moveresize, {.v = "0x -25y 0w 0h" } },
+ { Mod1Mask|ControlMask, XK_l, moveresize, {.v = "25x 0y 0w 0h" } },
+ { Mod1Mask|ControlMask, XK_h, moveresize, {.v = "-25x 0y 0w 0h" } },
+ { Mod1Mask|ShiftMask, XK_j, moveresize, {.v = "0x 0y 0w 25h" } },
+ { Mod1Mask|ShiftMask, XK_k, moveresize, {.v = "0x 0y 0w -25h" } },
+ { Mod1Mask|ShiftMask, XK_l, moveresize, {.v = "0x 0y 25w 0h" } },
+ { Mod1Mask|ShiftMask, XK_h, moveresize, {.v = "0x 0y -25w 0h" } },
+
{0, XF86XK_MonBrightnessUp, spawn, {.v = inc_bright}},
{0, XF86XK_MonBrightnessDown, spawn, {.v = dec_bright}},
diff --git a/dwm.c b/dwm.c
index f1addcc..cfda678 100644
--- a/dwm.c
+++ b/dwm.c
@@ -200,6 +200,7 @@ 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 movemouse(const Arg *arg);
static Client *nexttiled(Client *c);
/* static void pop(Client *c); */
@@ -2759,3 +2760,70 @@ main(int argc, char *argv[])
XCloseDisplay(dpy);
return EXIT_SUCCESS;
}
+
+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;
+ /* make sure the cursor stays inside the window */
+ if ((msx + nmx) > c->x && (msy + nmy) > c->y)
+ XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy);
+ }
+}