sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-canfocusfloating-20210219-2d308d6.diff (4102B)


      1 From 2d308d6df9c139f85367fefbb905921385074d32 Mon Sep 17 00:00:00 2001
      2 From: Georgios Oxinos <georgios.oxinos.extern@elinvar.de>
      3 Date: Fri, 19 Feb 2021 00:22:24 +0100
      4 Subject: [PATCH] [PATCH] [dwm][cantogglefloating] patch that allows disabling
      5  focus on floating clients
      6 
      7 ---
      8  config.def.h |  1 +
      9  dwm.c        | 57 +++++++++++++++++++++++++++++++++++++++++++++++-----
     10  2 files changed, 53 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 664c527..52854a0 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 @@ -192,6 +192,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 @@ -212,6 +213,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 @@ -789,6 +791,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 @@ -838,16 +842,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 @@ -1719,6 +1723,49 @@ 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;
    115 +
    116 +	for (n = 0, c = selmon->clients; c; c = c->next, n++)
    117 +    if (c->isfloating)
    118 +      c->cantfocus = !c->cantfocus;
    119 +		else
    120 +      n++;
    121 +
    122 +  if (n && selmon->sel->isfloating) {
    123 +		for (c = selmon->sel; c && c->isfloating; c = c->next);
    124 +		if (!c)
    125 +			for (c = selmon->clients; c && c->isfloating; c = c->next);
    126 +
    127 +    focus(c);
    128 +  }
    129 +
    130  	arrange(selmon);
    131  }
    132  
    133 -- 
    134 2.27.0
    135