| dwm-moveresize-20221210-7ac106c.diff - sites - public wiki contents of suckless… | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| dwm-moveresize-20221210-7ac106c.diff (6719B) | |
| --- | |
| 1 From 7ac106cad72c909fbb05d302f84191cdec8f2ac0 Mon Sep 17 00:00:00 2001 | |
| 2 From: oxinosg <[email protected]> | |
| 3 Date: Sat, 10 Dec 2022 15:24:14 +0100 | |
| 4 Subject: [PATCH] [dwm][moveresize]: fix for resize to edge | |
| 5 | |
| 6 --- | |
| 7 config.def.h | 16 ++++++ | |
| 8 dwm.c | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ | |
| 9 2 files changed, 170 insertions(+) | |
| 10 | |
| 11 diff --git a/config.def.h b/config.def.h | |
| 12 index 9efa774..99049e7 100644 | |
| 13 --- a/config.def.h | |
| 14 +++ b/config.def.h | |
| 15 @@ -79,6 +79,22 @@ static const Key keys[] = { | |
| 16 { MODKEY, XK_m, setlayout, {.v … | |
| 17 { MODKEY, XK_space, setlayout, {0} … | |
| 18 { MODKEY|ShiftMask, XK_space, togglefloating, {0} … | |
| 19 + { MODKEY, XK_Down, moveresize, {.v … | |
| 20 + { MODKEY, XK_Up, moveresize, {.v … | |
| 21 + { MODKEY, XK_Right, moveresize, {.v … | |
| 22 + { MODKEY, XK_Left, moveresize, {.v … | |
| 23 + { MODKEY|ShiftMask, XK_Down, moveresize, {.v … | |
| 24 + { MODKEY|ShiftMask, XK_Up, moveresize, {.v … | |
| 25 + { MODKEY|ShiftMask, XK_Right, moveresize, {.v … | |
| 26 + { MODKEY|ShiftMask, XK_Left, moveresize, {.v … | |
| 27 + { MODKEY|ControlMask, XK_Up, moveresizeedge, {.v … | |
| 28 + { MODKEY|ControlMask, XK_Down, moveresizeedge, {.v … | |
| 29 + { MODKEY|ControlMask, XK_Left, moveresizeedge, {.v … | |
| 30 + { MODKEY|ControlMask, XK_Right, moveresizeedge, {.v … | |
| 31 + { MODKEY|ControlMask|ShiftMask, XK_Up, moveresizeedge, {.v … | |
| 32 + { MODKEY|ControlMask|ShiftMask, XK_Down, moveresizeedge, {.v … | |
| 33 + { MODKEY|ControlMask|ShiftMask, XK_Left, moveresizeedge, {.v … | |
| 34 + { MODKEY|ControlMask|ShiftMask, XK_Right, moveresizeedge, {.v … | |
| 35 { MODKEY, XK_0, view, {.ui… | |
| 36 { MODKEY|ShiftMask, XK_0, tag, {.ui… | |
| 37 { MODKEY, XK_comma, focusmon, {.i … | |
| 38 diff --git a/dwm.c b/dwm.c | |
| 39 index 03baf42..89ec70d 100644 | |
| 40 --- a/dwm.c | |
| 41 +++ b/dwm.c | |
| 42 @@ -183,6 +183,8 @@ static void mappingnotify(XEvent *e); | |
| 43 static void maprequest(XEvent *e); | |
| 44 static void monocle(Monitor *m); | |
| 45 static void motionnotify(XEvent *e); | |
| 46 +static void moveresize(const Arg *arg); | |
| 47 +static void moveresizeedge(const Arg *arg); | |
| 48 static void movemouse(const Arg *arg); | |
| 49 static Client *nexttiled(Client *c); | |
| 50 static void pop(Client *c); | |
| 51 @@ -1203,6 +1205,158 @@ movemouse(const Arg *arg) | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 +void | |
| 56 +moveresize(const Arg *arg) { | |
| 57 + /* only floating windows can be moved */ | |
| 58 + Client *c; | |
| 59 + c = selmon->sel; | |
| 60 + int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh; | |
| 61 + char xAbs, yAbs, wAbs, hAbs; | |
| 62 + int msx, msy, dx, dy, nmx, nmy; | |
| 63 + unsigned int dui; | |
| 64 + Window dummy; | |
| 65 + | |
| 66 + if (!c || !arg) | |
| 67 + return; | |
| 68 + if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) | |
| 69 + return; | |
| 70 + if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y… | |
| 71 + return; | |
| 72 + | |
| 73 + /* compute new window position; prevent window from be position… | |
| 74 + nw = c->w + w; | |
| 75 + if (wAbs == 'W') | |
| 76 + nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * … | |
| 77 + | |
| 78 + nh = c->h + h; | |
| 79 + if (hAbs == 'H') | |
| 80 + nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * … | |
| 81 + | |
| 82 + nx = c->x + x; | |
| 83 + if (xAbs == 'X') { | |
| 84 + if (x < selmon->mx) | |
| 85 + nx = selmon->mx; | |
| 86 + else if (x > selmon->mx + selmon->mw) | |
| 87 + nx = selmon->mx + selmon->mw - nw - 2 * c->bw; | |
| 88 + else | |
| 89 + nx = x; | |
| 90 + } | |
| 91 + | |
| 92 + ny = c->y + y; | |
| 93 + if (yAbs == 'Y') { | |
| 94 + if (y < selmon->my) | |
| 95 + ny = selmon->my; | |
| 96 + else if (y > selmon->my + selmon->mh) | |
| 97 + ny = selmon->my + selmon->mh - nh - 2 * c->bw; | |
| 98 + else | |
| 99 + ny = y; | |
| 100 + } | |
| 101 + | |
| 102 + ox = c->x; | |
| 103 + oy = c->y; | |
| 104 + ow = c->w; | |
| 105 + oh = c->h; | |
| 106 + | |
| 107 + XRaiseWindow(dpy, c->win); | |
| 108 + Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy,… | |
| 109 + resize(c, nx, ny, nw, nh, True); | |
| 110 + | |
| 111 + /* move cursor along with the window to avoid problems caused b… | |
| 112 + if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + … | |
| 113 + { | |
| 114 + nmx = c->x - ox + c->w - ow; | |
| 115 + nmy = c->y - oy + c->h - oh; | |
| 116 + /* make sure the cursor stays inside the window */ | |
| 117 + if ((msx + nmx) > c->x && (msy + nmy) > c->y) | |
| 118 + XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, … | |
| 119 + } | |
| 120 +} | |
| 121 + | |
| 122 +void | |
| 123 +moveresizeedge(const Arg *arg) { | |
| 124 + /* move or resize floating window to edge of screen */ | |
| 125 + Client *c; | |
| 126 + c = selmon->sel; | |
| 127 + char e; | |
| 128 + int nx, ny, nw, nh, ox, oy, ow, oh, bp; | |
| 129 + int msx, msy, dx, dy, nmx, nmy; | |
| 130 + int starty; | |
| 131 + unsigned int dui; | |
| 132 + Window dummy; | |
| 133 + | |
| 134 + nx = c->x; | |
| 135 + ny = c->y; | |
| 136 + nw = c->w; | |
| 137 + nh = c->h; | |
| 138 + | |
| 139 + starty = selmon->showbar && topbar ? bh : 0; | |
| 140 + bp = selmon->showbar && !topbar ? bh : 0; | |
| 141 + | |
| 142 + if (!c || !arg) | |
| 143 + return; | |
| 144 + if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) | |
| 145 + return; | |
| 146 + if(sscanf((char *)arg->v, "%c", &e) != 1) | |
| 147 + return; | |
| 148 + | |
| 149 + if(e == 't') | |
| 150 + ny = starty; | |
| 151 + | |
| 152 + if(e == 'b') | |
| 153 + ny = c->h > selmon->mh - 2 * c->bw ? c->h - bp : selmon… | |
| 154 + | |
| 155 + if(e == 'l') | |
| 156 + nx = selmon->mx; | |
| 157 + | |
| 158 + if(e == 'r') | |
| 159 + nx = c->w > selmon->mw - 2 * c->bw ? selmon->mx + c->w … | |
| 160 + | |
| 161 + if(e == 'T') { | |
| 162 + /* if you click to resize again, it will return to old … | |
| 163 + if(c->h + starty == c->oldh + c->oldy) { | |
| 164 + nh = c->oldh; | |
| 165 + ny = c->oldy; | |
| 166 + } else { | |
| 167 + nh = c->h + c->y - starty; | |
| 168 + ny = starty; | |
| 169 + } | |
| 170 + } | |
| 171 + | |
| 172 + if(e == 'B') | |
| 173 + nh = c->h + c->y + 2 * c->bw + bp == selmon->mh ? c->ol… | |
| 174 + | |
| 175 + if(e == 'L') { | |
| 176 + if(selmon->mx + c->w == c->oldw + c->oldx) { | |
| 177 + nw = c->oldw; | |
| 178 + nx = c->oldx; | |
| 179 + } else { | |
| 180 + nw = c->w + c->x - selmon->mx; | |
| 181 + nx = selmon->mx; | |
| 182 + } | |
| 183 + } | |
| 184 + | |
| 185 + if(e == 'R') | |
| 186 + nw = c->w + c->x + 2 * c->bw == selmon->mx + selmon->mw… | |
| 187 + | |
| 188 + ox = c->x; | |
| 189 + oy = c->y; | |
| 190 + ow = c->w; | |
| 191 + oh = c->h; | |
| 192 + | |
| 193 + XRaiseWindow(dpy, c->win); | |
| 194 + Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy,… | |
| 195 + resizeclient(c, nx, ny, nw, nh); | |
| 196 + | |
| 197 + /* move cursor along with the window to avoid problems caused b… | |
| 198 + if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + … | |
| 199 + nmx = c->x - ox + c->w - ow; | |
| 200 + nmy = c->y - oy + c->h - oh; | |
| 201 + /* make sure the cursor stays inside the window */ | |
| 202 + if ((msx + nmx) > c->x && (msy + nmy) > c->y) | |
| 203 + XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, … | |
| 204 + } | |
| 205 +} | |
| 206 + | |
| 207 Client * | |
| 208 nexttiled(Client *c) | |
| 209 { | |
| 210 -- | |
| 211 2.34.1 | |
| 212 |