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