[hackers] [dwm] [PATCH] focusonclick

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Wed, 4 Jan 2017 20:33:12 +0100

---
Heyho,
while fixing the focusonclick patch I noticed that the latest version on the
wiki[0] breaks some mouse-bindings. After applying the patch to the current git
master, I could not move or resize floating windows with the mouse anymore. I
tried removing the line `XAllowEvents(dpy, ReplayPointer, CurrentTime);` and it
seems to work. I tried to understand why this call was needed in the first
place, but could not figure it out. It would be nice if anyone with more X
knowledge could approve that the removal of this call (as done in my attached
version) is actually the correct solution.
0: http://dwm.suckless.org/patches/dwm-focusonclick-6.0.diff
--Markus
 config.def.h |  1 +
 dwm.c        | 50 ++++++--------------------------------------------
 2 files changed, 7 insertions(+), 44 deletions(-)
diff --git a/config.def.h b/config.def.h
index ab00f4c..897e852 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -5,6 +5,7 @@ static const unsigned int borderpx  = 1;        /* border pixel of windows */
 static const unsigned int snap      = 32;       /* snap pixel */
 static const int showbar            = 1;        /* 0 means no bar */
 static const int topbar             = 1;        /* 0 means bottom bar */
+static const int focusonwheel       = 0;
 static const char *fonts[]          = { "monospace:size=10" };
 static const char dmenufont[]       = "monospace:size=10";
 static const char col_gray1[]       = "#222222";
diff --git a/dwm.c b/dwm.c
index 7cd8d18..897e0fe 100644
--- a/dwm.c
+++ b/dwm.c
_AT_@ -164,7 +164,6 @@ static void detachstack(Client *c);
 static Monitor *dirtomon(int dir);
 static void drawbar(Monitor *m);
 static void drawbars(void);
-static void enternotify(XEvent *e);
 static void expose(XEvent *e);
 static void focus(Client *c);
 static void focusin(XEvent *e);
_AT_@ -182,7 +181,6 @@ static void manage(Window w, XWindowAttributes *wa);
 static void mappingnotify(XEvent *e);
 static void maprequest(XEvent *e);
 static void monocle(Monitor *m);
-static void motionnotify(XEvent *e);
 static void movemouse(const Arg *arg);
 static Client *nexttiled(Client *c);
 static void pop(Client *);
_AT_@ -252,13 +250,11 @@ static void (*handler[LASTEvent]) (XEvent *) = {
 	[ConfigureRequest] = configurerequest,
 	[ConfigureNotify] = configurenotify,
 	[DestroyNotify] = destroynotify,
-	[EnterNotify] = enternotify,
 	[Expose] = expose,
 	[FocusIn] = focusin,
 	[KeyPress] = keypress,
 	[MappingNotify] = mappingnotify,
 	[MapRequest] = maprequest,
-	[MotionNotify] = motionnotify,
 	[PropertyNotify] = propertynotify,
 	[UnmapNotify] = unmapnotify
 };
_AT_@ -427,7 +423,8 @@ buttonpress(XEvent *e)
 
 	click = ClkRootWin;
 	/* focus monitor if necessary */
-	if ((m = wintomon(ev->window)) && m != selmon) {
+	if ((m = wintomon(ev->window)) && m != selmon
+	    && (focusonwheel || (ev->button != Button4 && ev->button != Button5))) {
 		unfocus(selmon->sel, 1);
 		selmon = m;
 		focus(NULL);
_AT_@ -447,7 +444,8 @@ buttonpress(XEvent *e)
 		else
 			click = ClkWinTitle;
 	} else if ((c = wintoclient(ev->window))) {
-		focus(c);
+		if (focusonwheel || (ev->button != Button4 && ev->button != Button5))
+			focus(c);
 		click = ClkClientWin;
 	}
 	for (i = 0; i < LENGTH(buttons); i++)
_AT_@ -755,25 +753,6 @@ drawbars(void)
 }
 
 void
-enternotify(XEvent *e)
-{
-	Client *c;
-	Monitor *m;
-	XCrossingEvent *ev = &e->xcrossing;
-
-	if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
-		return;
-	c = wintoclient(ev->window);
-	m = c ? c->mon : wintomon(ev->window);
-	if (m != selmon) {
-		unfocus(selmon->sel, 1);
-		selmon = m;
-	} else if (!c || c == selmon->sel)
-		return;
-	focus(c);
-}
-
-void
 expose(XEvent *e)
 {
 	Monitor *m;
_AT_@ -945,10 +924,10 @@ grabbuttons(Client *c, int focused)
 						XGrabButton(dpy, buttons[i].button,
 						            buttons[i].mask | modifiers[j],
 						            c->win, False, BUTTONMASK,
-						            GrabModeAsync, GrabModeSync, None, None);
+						            GrabModeSync, GrabModeSync, None, None);
 		} else
 			XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
-			            BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
+			            BUTTONMASK, GrabModeSync, GrabModeSync, None, None);
 	}
 }
 
_AT_@ -1123,23 +1102,6 @@ monocle(Monitor *m)
 }
 
 void
-motionnotify(XEvent *e)
-{
-	static Monitor *mon = NULL;
-	Monitor *m;
-	XMotionEvent *ev = &e->xmotion;
-
-	if (ev->window != root)
-		return;
-	if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
-		unfocus(selmon->sel, 1);
-		selmon = m;
-		focus(NULL);
-	}
-	mon = m;
-}
-
-void
 movemouse(const Arg *arg)
 {
 	int x, y, ocx, ocy, nx, ny;
-- 
2.10.2
Received on Wed Jan 04 2017 - 20:33:12 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 04 2017 - 20:36:16 CET