dwm-canfocusfloating-20210724-b914109.diff (4256B)
1 From b9141091994ba657af534453ab913663a8258f9a Mon Sep 17 00:00:00 2001 2 From: oxinosg <georgios.oxinos.extern@elinvar.de> 3 Date: Sat, 24 Jul 2021 23:31:30 +0200 4 Subject: [PATCH] [dwm][cantogglefloating] patch that allows disabling focus on 5 floating clients 6 7 --- 8 config.def.h | 1 + 9 dwm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++---- 10 2 files changed, 63 insertions(+), 5 deletions(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 1c0b587..005fb5d 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -70,6 +70,7 @@ static Key keys[] = { 17 { MODKEY, XK_d, incnmaster, {.i = -1 } }, 18 { MODKEY, XK_h, setmfact, {.f = -0.05} }, 19 { MODKEY, XK_l, setmfact, {.f = +0.05} }, 20 + { MODKEY, XK_s, togglecanfocusfloating, {0} }, 21 { MODKEY, XK_Return, zoom, {0} }, 22 { MODKEY, XK_Tab, view, {0} }, 23 { MODKEY|ShiftMask, XK_c, killclient, {0} }, 24 diff --git a/dwm.c b/dwm.c 25 index 4465af1..ae0a0ea 100644 26 --- a/dwm.c 27 +++ b/dwm.c 28 @@ -92,7 +92,7 @@ struct Client { 29 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 30 int bw, oldbw; 31 unsigned int tags; 32 - int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; 33 + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, cantfocus; 34 Client *next; 35 Client *snext; 36 Monitor *mon; 37 @@ -191,6 +191,7 @@ static Monitor *recttomon(int x, int y, int w, int h); 38 static void resize(Client *c, int x, int y, int w, int h, int interact); 39 static void resizeclient(Client *c, int x, int y, int w, int h); 40 static void resizemouse(const Arg *arg); 41 +static void resetcanfocusfloating(); 42 static void restack(Monitor *m); 43 static void run(void); 44 static void scan(void); 45 @@ -211,6 +212,7 @@ static void tagmon(const Arg *arg); 46 static void tile(Monitor *); 47 static void togglebar(const Arg *arg); 48 static void togglefloating(const Arg *arg); 49 +static void togglecanfocusfloating(const Arg *arg); 50 static void toggletag(const Arg *arg); 51 static void toggleview(const Arg *arg); 52 static void unfocus(Client *c, int setfocus); 53 @@ -788,6 +790,8 @@ focus(Client *c) 54 if (selmon->sel && selmon->sel != c) 55 unfocus(selmon->sel, 0); 56 if (c) { 57 + if (c->cantfocus) 58 + return; 59 if (c->mon != selmon) 60 selmon = c->mon; 61 if (c->isurgent) 62 @@ -837,16 +841,16 @@ focusstack(const Arg *arg) 63 if (!selmon->sel) 64 return; 65 if (arg->i > 0) { 66 - for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); 67 + for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->cantfocus); c = c->next); 68 if (!c) 69 - for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); 70 + for (c = selmon->clients; c && (!ISVISIBLE(c) || c->cantfocus); c = c->next); 71 } else { 72 for (i = selmon->clients; i != selmon->sel; i = i->next) 73 - if (ISVISIBLE(i)) 74 + if (ISVISIBLE(i) && !i->cantfocus) 75 c = i; 76 if (!c) 77 for (; i; i = i->next) 78 - if (ISVISIBLE(i)) 79 + if (ISVISIBLE(i) && !i->cantfocus) 80 c = i; 81 } 82 if (c) { 83 @@ -1716,6 +1720,59 @@ togglefloating(const Arg *arg) 84 if (selmon->sel->isfloating) 85 resize(selmon->sel, selmon->sel->x, selmon->sel->y, 86 selmon->sel->w, selmon->sel->h, 0); 87 + 88 + resetcanfocusfloating(); 89 + 90 + arrange(selmon); 91 +} 92 + 93 +void 94 +resetcanfocusfloating() 95 +{ 96 + unsigned int i, n; 97 + Client *c; 98 + 99 + for (n = 0, c = selmon->clients; c; c = c->next, n++); 100 + if (n == 0) 101 + return; 102 + 103 + for (i = 0, c = selmon->clients; c; c = c->next, i++) 104 + if (c->isfloating) 105 + c->cantfocus = 0; 106 + 107 + arrange(selmon); 108 +} 109 + 110 +void 111 +togglecanfocusfloating(const Arg *arg) 112 +{ 113 + unsigned int n; 114 + Client *c, *cf = NULL; 115 + 116 + if (!selmon->sel) 117 + return; 118 + 119 + for (c = selmon->clients; c; c = c->next) 120 + if (c->cantfocus == 1) { 121 + cf = c; 122 + } 123 + 124 + if (cf) { 125 + resetcanfocusfloating(); 126 + focus(cf); 127 + } else { 128 + for (n = 0, c = selmon->clients; c; c = c->next) 129 + if (c->isfloating) 130 + c->cantfocus = !c->cantfocus; 131 + else 132 + n++; 133 + 134 + if (n && selmon->sel->isfloating) { 135 + c = nexttiled(selmon->clients); 136 + focus(c); 137 + } 138 + } 139 + 140 arrange(selmon); 141 } 142 143 -- 144 2.27.0 145