dwm-focusonclick-20260516-44dbc68.diff (2866B)
1 From 64969395a6bef3581c9d9bef6940d07f9d3ed8b7 Mon Sep 17 00:00:00 2001 2 From: Bakkeby <bakkeby@gmail.com> 3 Date: Sat, 16 May 2026 11:32:00 +0200 4 Subject: [PATCH] focusonclick - removes sloppy focus from dwm 5 6 --- 7 config.def.h | 1 + 8 dwm.c | 13 ++++++------- 9 2 files changed, 7 insertions(+), 7 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index 81c3fc0..a074e07 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ 16 static const unsigned int snap = 32; /* snap pixel */ 17 static const int showbar = 1; /* 0 means no bar */ 18 static const int topbar = 1; /* 0 means bottom bar */ 19 +static const int focusonwheel = 0; /* 0 allows the user to scroll window without changing focus */ 20 static const char *fonts[] = { "monospace:size=10" }; 21 static const char dmenufont[] = "monospace:size=10"; 22 static const char col_gray1[] = "#222222"; 23 diff --git a/dwm.c b/dwm.c 24 index ab3a84c..e9ba431 100644 25 --- a/dwm.c 26 +++ b/dwm.c 27 @@ -162,7 +162,6 @@ static void detachstack(Client *c); 28 static Monitor *dirtomon(int dir); 29 static void drawbar(Monitor *m); 30 static void drawbars(void); 31 -static void enternotify(XEvent *e); 32 static void expose(XEvent *e); 33 static void focus(Client *c); 34 static void focusin(XEvent *e); 35 @@ -181,7 +180,6 @@ static void manage(Window w, XWindowAttributes *wa); 36 static void mappingnotify(XEvent *e); 37 static void maprequest(XEvent *e); 38 static void monocle(Monitor *m); 39 -static void motionnotify(XEvent *e); 40 static void movemouse(const Arg *arg); 41 static Client *nexttiled(Client *c); 42 static void pop(Client *c); 43 @@ -248,13 +246,11 @@ static void (*handler[LASTEvent]) (XEvent *) = { 44 [ConfigureRequest] = configurerequest, 45 [ConfigureNotify] = configurenotify, 46 [DestroyNotify] = destroynotify, 47 - [EnterNotify] = enternotify, 48 [Expose] = expose, 49 [FocusIn] = focusin, 50 [KeyPress] = keypress, 51 [MappingNotify] = mappingnotify, 52 [MapRequest] = maprequest, 53 - [MotionNotify] = motionnotify, 54 [PropertyNotify] = propertynotify, 55 [UnmapNotify] = unmapnotify 56 }; 57 @@ -425,7 +421,8 @@ buttonpress(XEvent *e) 58 59 click = ClkRootWin; 60 /* focus monitor if necessary */ 61 - if ((m = wintomon(ev->window)) && m != selmon) { 62 + if ((m = wintomon(ev->window)) && m != selmon 63 + && (focusonwheel || (ev->button != Button4 && ev->button != Button5))) { 64 unfocus(selmon->sel, 1); 65 selmon = m; 66 focus(NULL); 67 @@ -445,8 +442,10 @@ buttonpress(XEvent *e) 68 else 69 click = ClkWinTitle; 70 } else if ((c = wintoclient(ev->window))) { 71 - focus(c); 72 - restack(selmon); 73 + if (focusonwheel || (ev->button != Button4 && ev->button != Button5)) { 74 + focus(c); 75 + restack(selmon); 76 + } 77 XAllowEvents(dpy, ReplayPointer, CurrentTime); 78 click = ClkClientWin; 79 } 80 -- 81 2.54.0 82