dwm-moveresize-6.2.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dwm-moveresize-6.2.diff (4355B) | |
--- | |
1 From 0ac50d43c5a48de34a53db8240143e4fb39239d3 Mon Sep 17 00:00:00 2001 | |
2 From: bakkeby <[email protected]> | |
3 Date: Fri, 22 May 2020 13:51:06 +0200 | |
4 Subject: [PATCH] The moveresize patch allows floating windows to be resi… | |
5 and moved using keyboard shortcuts. | |
6 | |
7 This example keybinding reduces the y position with 25 pixels. | |
8 | |
9 { MODKEY, XK_Up, moveresize, {.v =… | |
10 | |
11 Use capital letters to specify absolute size and position should you nee… | |
12 | |
13 { MODKEY, XK_Up, moveresize, {.v = "0x… | |
14 | |
15 The above example would set the size of the client to 300x500 pixels, bu… | |
16 | |
17 Refer to: | |
18 https://dwm.suckless.org/patches/moveresize/ | |
19 --- | |
20 config.def.h | 8 +++++++ | |
21 dwm.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
22 2 files changed, 74 insertions(+) | |
23 | |
24 diff --git a/config.def.h b/config.def.h | |
25 index 1c0b587..ff863c9 100644 | |
26 --- a/config.def.h | |
27 +++ b/config.def.h | |
28 @@ -78,6 +78,14 @@ static Key keys[] = { | |
29 { MODKEY, XK_m, setlayout, {.v … | |
30 { MODKEY, XK_space, setlayout, {0} … | |
31 { MODKEY|ShiftMask, XK_space, togglefloating, {0} … | |
32 + { MODKEY, XK_Down, moveresize, {.v … | |
33 + { MODKEY, XK_Up, moveresize, {.v … | |
34 + { MODKEY, XK_Right, moveresize, {.v … | |
35 + { MODKEY, XK_Left, moveresize, {.v … | |
36 + { MODKEY|ShiftMask, XK_Down, moveresize, {.v … | |
37 + { MODKEY|ShiftMask, XK_Up, moveresize, {.v … | |
38 + { MODKEY|ShiftMask, XK_Right, moveresize, {.v … | |
39 + { MODKEY|ShiftMask, XK_Left, moveresize, {.v … | |
40 { MODKEY, XK_0, view, {.ui… | |
41 { MODKEY|ShiftMask, XK_0, tag, {.ui… | |
42 { MODKEY, XK_comma, focusmon, {.i … | |
43 diff --git a/dwm.c b/dwm.c | |
44 index 4465af1..89483c1 100644 | |
45 --- a/dwm.c | |
46 +++ b/dwm.c | |
47 @@ -182,6 +182,7 @@ static void mappingnotify(XEvent *e); | |
48 static void maprequest(XEvent *e); | |
49 static void monocle(Monitor *m); | |
50 static void motionnotify(XEvent *e); | |
51 +static void moveresize(const Arg *arg); | |
52 static void movemouse(const Arg *arg); | |
53 static Client *nexttiled(Client *c); | |
54 static void pop(Client *); | |
55 @@ -1192,6 +1193,71 @@ movemouse(const Arg *arg) | |
56 } | |
57 } | |
58 | |
59 +void | |
60 +moveresize(const Arg *arg) { | |
61 + /* only floating windows can be moved */ | |
62 + Client *c; | |
63 + c = selmon->sel; | |
64 + int x, y, w, h, nx, ny, nw, nh, ox, oy, ow, oh; | |
65 + char xAbs, yAbs, wAbs, hAbs; | |
66 + int msx, msy, dx, dy, nmx, nmy; | |
67 + unsigned int dui; | |
68 + Window dummy; | |
69 + | |
70 + if (!c || !arg) | |
71 + return; | |
72 + if (selmon->lt[selmon->sellt]->arrange && !c->isfloating) | |
73 + return; | |
74 + if (sscanf((char *)arg->v, "%d%c %d%c %d%c %d%c", &x, &xAbs, &y… | |
75 + return; | |
76 + | |
77 + /* compute new window position; prevent window from be position… | |
78 + nw = c->w + w; | |
79 + if (wAbs == 'W') | |
80 + nw = w < selmon->mw - 2 * c->bw ? w : selmon->mw - 2 * … | |
81 + | |
82 + nh = c->h + h; | |
83 + if (hAbs == 'H') | |
84 + nh = h < selmon->mh - 2 * c->bw ? h : selmon->mh - 2 * … | |
85 + | |
86 + nx = c->x + x; | |
87 + if (xAbs == 'X') { | |
88 + if (x < selmon->mx) | |
89 + nx = selmon->mx; | |
90 + else if (x > selmon->mx + selmon->mw) | |
91 + nx = selmon->mx + selmon->mw - nw - 2 * c->bw; | |
92 + else | |
93 + nx = x; | |
94 + } | |
95 + | |
96 + ny = c->y + y; | |
97 + if (yAbs == 'Y') { | |
98 + if (y < selmon->my) | |
99 + ny = selmon->my; | |
100 + else if (y > selmon->my + selmon->mh) | |
101 + ny = selmon->my + selmon->mh - nh - 2 * c->bw; | |
102 + else | |
103 + ny = y; | |
104 + } | |
105 + | |
106 + ox = c->x; | |
107 + oy = c->y; | |
108 + ow = c->w; | |
109 + oh = c->h; | |
110 + | |
111 + XRaiseWindow(dpy, c->win); | |
112 + Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy,… | |
113 + resize(c, nx, ny, nw, nh, True); | |
114 + | |
115 + /* move cursor along with the window to avoid problems caused b… | |
116 + if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + … | |
117 + { | |
118 + nmx = c->x - ox + c->w - ow; | |
119 + nmy = c->y - oy + c->h - oh; | |
120 + XWarpPointer(dpy, None, None, 0, 0, 0, 0, nmx, nmy); | |
121 + } | |
122 +} | |
123 + | |
124 Client * | |
125 nexttiled(Client *c) | |
126 { | |
127 -- | |
128 2.19.1 | |
129 |