sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit dad01159fc8234ccdda079f191d6fcf796dc3bd3
parent dab67914a2350e07bc2c2c04c9385feef13fbb14
Author: Stein Bakkeby <bakkeby@gmail.com>
Date:   Fri, 22 May 2020 14:45:16 +0200

Added 6.2 patch for moveresize.

The older patches did not include default keybindings and the examples
listed on the page are incompatible with any of the patches listed.
They are only for the inline function listed on the same page.

The later versions of the moveresize patch also support setting
absolute position and/or size.

Adding this primarily to avoid having other people waste time working
out what the keybindings should look like.

Diffstat:
Adwm.suckless.org/patches/moveresize/dwm-moveresize-6.2.diff | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdwm.suckless.org/patches/moveresize/index.md | 21+++++++++++----------
2 files changed, 140 insertions(+), 10 deletions(-)

diff --git a/dwm.suckless.org/patches/moveresize/dwm-moveresize-6.2.diff b/dwm.suckless.org/patches/moveresize/dwm-moveresize-6.2.diff @@ -0,0 +1,129 @@ +From 0ac50d43c5a48de34a53db8240143e4fb39239d3 Mon Sep 17 00:00:00 2001 +From: bakkeby <bakkeby@gmail.com> +Date: Fri, 22 May 2020 13:51:06 +0200 +Subject: [PATCH] The moveresize patch allows floating windows to be resized + and moved using keyboard shortcuts. + +This example keybinding reduces the y position with 25 pixels. + + { MODKEY, XK_Up, moveresize, {.v = "0x -25y 0w 0h" } }, + +Use capital letters to specify absolute size and position should you need it. + + { MODKEY, XK_Up, moveresize, {.v = "0x 0y 500W 300H" } }, + +The above example would set the size of the client to 300x500 pixels, but leave the position as-is. + +Refer to: +https://dwm.suckless.org/patches/moveresize/ +--- + config.def.h | 8 +++++++ + dwm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 74 insertions(+) + +diff --git a/config.def.h b/config.def.h +index 1c0b587..ff863c9 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -78,6 +78,14 @@ 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, 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..89483c1 100644 +--- a/dwm.c ++++ b/dwm.c +@@ -182,6 +182,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 *); +@@ -1192,6 +1193,71 @@ 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); ++ } ++} ++ + Client * + nexttiled(Client *c) + { +-- +2.19.1 + diff --git a/dwm.suckless.org/patches/moveresize/index.md b/dwm.suckless.org/patches/moveresize/index.md @@ -10,30 +10,30 @@ Usage ----- 1. Put the following `moveresize()` function somewhere in your `dwm.c`, **after** the line which includes the config.h file: - + static void moveresize(const Arg *arg) { XEvent ev; Monitor *m = selmon; - + if(!(m->sel && arg && arg->v && m->sel->isfloating)) return; - + resize(m->sel, m->sel->x + ((int *)arg->v)[0], m->sel->y + ((int *)arg->v)[1], m->sel->w + ((int *)arg->v)[2], m->sel->h + ((int *)arg->v)[3], True); - + while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } - + 2. Add a moveresize() function definition in dwm.c below the line: static void movemouse(const Arg *arg); - + static void moveresize(const Arg *arg); - + 3. Insert the bindings into the keys list. Here is an example which uses the arrow keys to move (mod+arrow) or resize (mod+shift+arrow) the selected client: @@ -48,11 +48,11 @@ Usage { MODKEY|ShiftMask, XK_Left, moveresize, {.v = (int []){ 0, 0, -25, 0 }}}, If you want to automatically toggle the client floating when move/resize, -replace the `if()` statement above with this code: +then replace the second if statement in the moveresize function with this code: - if(!(m->sel && arg && arg->v)) + if (!(m->sel && arg && arg->v)) return; - if(m->lt[m->sellt]->arrange && !m->sel->isfloating) + if (m->lt[m->sellt]->arrange && !m->sel->isfloating) togglefloating(NULL); Multi-head @@ -62,6 +62,7 @@ sizes in a multi monitor setup. A second patch allows you to maximize windows. Download -------- +* [dwm-moveresize-6.2.diff](dwm-moveresize-6.2.diff) * [dwm-moveresize-20160731-56a31dc.diff](dwm-moveresize-20160731-56a31dc.diff) * [dwm-moveresize-6.1.diff](dwm-moveresize-6.1.diff) (2095b) (20140209) * [dwm-moveresize-6.0.diff](dwm-moveresize-6.0.diff) (2025b) (20120406)