mirror of https://github.com/bakkeby/patches
Adding placemouse patch
parent
69f8fa9d89
commit
5851c0b014
@ -0,0 +1,216 @@
|
||||
From 543d8a53c84b95ee379285725001425a6e719f7d Mon Sep 17 00:00:00 2001
|
||||
From: bakkeby <bakkeby@gmail.com>
|
||||
Date: Thu, 21 Jan 2021 11:08:15 +0100
|
||||
Subject: [PATCH] Adding placemouse patch
|
||||
|
||||
---
|
||||
config.def.h | 1 +
|
||||
dwm.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 143 insertions(+)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1c0b587..852707f 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -105,6 +105,7 @@ static Button buttons[] = {
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
+ { ClkClientWin, MODKEY|ControlMask, Button1, placemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
{ ClkTagBar, 0, Button1, view, {0} },
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 4465af1..40e24f0 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -49,6 +49,8 @@
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
|
||||
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
|
||||
* MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
|
||||
+#define INTERSECTC(x,y,w,h,z) (MAX(0, MIN((x)+(w),(z)->x+(z)->w) - MAX((x),(z)->x)) \
|
||||
+ * MAX(0, MIN((y)+(h),(z)->y+(z)->h) - MAX((y),(z)->y)))
|
||||
#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]))
|
||||
#define LENGTH(X) (sizeof X / sizeof X[0])
|
||||
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
|
||||
@@ -93,6 +95,7 @@ struct Client {
|
||||
int bw, oldbw;
|
||||
unsigned int tags;
|
||||
int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
|
||||
+ int beingmoved;
|
||||
Client *next;
|
||||
Client *snext;
|
||||
Monitor *mon;
|
||||
@@ -184,9 +187,11 @@ static void monocle(Monitor *m);
|
||||
static void motionnotify(XEvent *e);
|
||||
static void movemouse(const Arg *arg);
|
||||
static Client *nexttiled(Client *c);
|
||||
+static void placemouse(const Arg *arg);
|
||||
static void pop(Client *);
|
||||
static void propertynotify(XEvent *e);
|
||||
static void quit(const Arg *arg);
|
||||
+static Client *recttoclient(int x, int y, int w, int h);
|
||||
static Monitor *recttomon(int x, int y, int w, int h);
|
||||
static void resize(Client *c, int x, int y, int w, int h, int interact);
|
||||
static void resizeclient(Client *c, int x, int y, int w, int h);
|
||||
@@ -1199,6 +1204,124 @@ nexttiled(Client *c)
|
||||
return c;
|
||||
}
|
||||
|
||||
+void
|
||||
+placemouse(const Arg *arg)
|
||||
+{
|
||||
+ int x, y, ocx, ocy, nx = -9999, ny = -9999, freemove = 0;
|
||||
+ Client *c, *r = NULL, *at, *prevr;
|
||||
+ Monitor *m;
|
||||
+ XEvent ev;
|
||||
+ XWindowAttributes wa;
|
||||
+ Time lasttime = 0;
|
||||
+ int attachmode, prevattachmode;
|
||||
+ attachmode = prevattachmode = -1;
|
||||
+
|
||||
+ if (!(c = selmon->sel) || !c->mon->lt[c->mon->sellt]->arrange) /* no support for placemouse when floating layout is used */
|
||||
+ return;
|
||||
+ if (c->isfullscreen) /* no support placing fullscreen windows by mouse */
|
||||
+ return;
|
||||
+ restack(selmon);
|
||||
+ prevr = c;
|
||||
+ if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||
+ None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
|
||||
+ return;
|
||||
+ if (!getrootptr(&x, &y))
|
||||
+ return;
|
||||
+
|
||||
+ c->isfloating = 0;
|
||||
+ c->beingmoved = 1;
|
||||
+
|
||||
+ XGetWindowAttributes(dpy, c->win, &wa);
|
||||
+ ocx = wa.x;
|
||||
+ ocy = wa.y;
|
||||
+
|
||||
+ do {
|
||||
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
|
||||
+ switch (ev.type) {
|
||||
+ case ConfigureRequest:
|
||||
+ case Expose:
|
||||
+ case MapRequest:
|
||||
+ handler[ev.type](&ev);
|
||||
+ break;
|
||||
+ case MotionNotify:
|
||||
+ if ((ev.xmotion.time - lasttime) <= (1000 / 60))
|
||||
+ continue;
|
||||
+ lasttime = ev.xmotion.time;
|
||||
+
|
||||
+ nx = ocx + (ev.xmotion.x - x);
|
||||
+ ny = ocy + (ev.xmotion.y - y);
|
||||
+
|
||||
+ if (!freemove && (abs(nx - ocx) > snap || abs(ny - ocy) > snap))
|
||||
+ freemove = 1;
|
||||
+
|
||||
+ if (freemove)
|
||||
+ XMoveWindow(dpy, c->win, nx, ny);
|
||||
+
|
||||
+ if ((m = recttomon(ev.xmotion.x, ev.xmotion.y, 1, 1)) && m != selmon)
|
||||
+ selmon = m;
|
||||
+
|
||||
+ r = recttoclient(ev.xmotion.x, ev.xmotion.y, 1, 1);
|
||||
+
|
||||
+ if (!r || r == c)
|
||||
+ break;
|
||||
+
|
||||
+ attachmode = 0; // below
|
||||
+ if (((float)(r->y + r->h - ev.xmotion.y) / r->h) > ((float)(r->x + r->w - ev.xmotion.x) / r->w)) {
|
||||
+ if (abs(r->y - ev.xmotion.y) < r->h / 2)
|
||||
+ attachmode = 1; // above
|
||||
+ } else if (abs(r->x - ev.xmotion.x) < r->w / 2)
|
||||
+ attachmode = 1; // above
|
||||
+
|
||||
+ if ((r && r != prevr) || (attachmode != prevattachmode)) {
|
||||
+ detachstack(c);
|
||||
+ detach(c);
|
||||
+ if (c->mon != r->mon)
|
||||
+ arrangemon(c->mon);
|
||||
+
|
||||
+ c->mon = r->mon;
|
||||
+ r->mon->sel = r;
|
||||
+
|
||||
+ if (attachmode) {
|
||||
+ if (r == r->mon->clients)
|
||||
+ attach(c);
|
||||
+ else {
|
||||
+ for (at = r->mon->clients; at->next != r; at = at->next);
|
||||
+ c->next = at->next;
|
||||
+ at->next = c;
|
||||
+ }
|
||||
+ } else {
|
||||
+ c->next = r->next;
|
||||
+ r->next = c;
|
||||
+ }
|
||||
+
|
||||
+ attachstack(c);
|
||||
+ arrangemon(r->mon);
|
||||
+ prevr = r;
|
||||
+ prevattachmode = attachmode;
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+ } while (ev.type != ButtonRelease);
|
||||
+ XUngrabPointer(dpy, CurrentTime);
|
||||
+
|
||||
+ if ((m = recttomon(ev.xmotion.x, ev.xmotion.y, 1, 1)) && m != c->mon) {
|
||||
+ detach(c);
|
||||
+ detachstack(c);
|
||||
+ arrangemon(c->mon);
|
||||
+ c->mon = m;
|
||||
+ attach(c);
|
||||
+ attachstack(c);
|
||||
+ selmon = m;
|
||||
+ focus(c);
|
||||
+ }
|
||||
+
|
||||
+ c->beingmoved = 0;
|
||||
+
|
||||
+ if (nx != -9999)
|
||||
+ resize(c, nx, ny, c->w, c->h, 0);
|
||||
+ arrangemon(c->mon);
|
||||
+}
|
||||
+
|
||||
void
|
||||
pop(Client *c)
|
||||
{
|
||||
@@ -1251,6 +1374,21 @@ quit(const Arg *arg)
|
||||
running = 0;
|
||||
}
|
||||
|
||||
+Client *
|
||||
+recttoclient(int x, int y, int w, int h)
|
||||
+{
|
||||
+ Client *c, *r = NULL;
|
||||
+ int a, area = 0;
|
||||
+
|
||||
+ for (c = nexttiled(selmon->clients); c; c = nexttiled(c->next)) {
|
||||
+ if ((a = INTERSECTC(x, y, w, h, c)) > area) {
|
||||
+ area = a;
|
||||
+ r = c;
|
||||
+ }
|
||||
+ }
|
||||
+ return r;
|
||||
+}
|
||||
+
|
||||
Monitor *
|
||||
recttomon(int x, int y, int w, int h)
|
||||
{
|
||||
@@ -1281,6 +1419,10 @@ resizeclient(Client *c, int x, int y, int w, int h)
|
||||
c->oldy = c->y; c->y = wc.y = y;
|
||||
c->oldw = c->w; c->w = wc.width = w;
|
||||
c->oldh = c->h; c->h = wc.height = h;
|
||||
+
|
||||
+ if (c->beingmoved)
|
||||
+ return;
|
||||
+
|
||||
wc.border_width = c->bw;
|
||||
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
|
||||
configure(c);
|
||||
--
|
||||
2.30.0
|
||||
|
Loading…
Reference in New Issue