sites

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

dwm-cantogglefloating-20210205-f42c25c.diff (4369B)


      1 From f42c25cf04c10cd042f36346423256aae4e4b80c Mon Sep 17 00:00:00 2001
      2 From: Georgios Oxinos <georgios.oxinos.extern@elinvar.de>
      3 Date: Fri, 5 Feb 2021 21:06:04 +0100
      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 664c527..a80f7b6 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 @@ -138,6 +138,7 @@ typedef struct {
     38  	const char *title;
     39  	unsigned int tags;
     40  	int isfloating;
     41 +  int cantfocus;
     42  	int monitor;
     43  } Rule;
     44  
     45 @@ -192,6 +193,7 @@ static Monitor *recttomon(int x, int y, int w, int h);
     46  static void resize(Client *c, int x, int y, int w, int h, int interact);
     47  static void resizeclient(Client *c, int x, int y, int w, int h);
     48  static void resizemouse(const Arg *arg);
     49 +static void resetcanfocusfloating();
     50  static void restack(Monitor *m);
     51  static void run(void);
     52  static void scan(void);
     53 @@ -212,6 +214,7 @@ static void tagmon(const Arg *arg);
     54  static void tile(Monitor *);
     55  static void togglebar(const Arg *arg);
     56  static void togglefloating(const Arg *arg);
     57 +static void togglecanfocusfloating(const Arg *arg);
     58  static void toggletag(const Arg *arg);
     59  static void toggleview(const Arg *arg);
     60  static void unfocus(Client *c, int setfocus);
     61 @@ -789,6 +792,8 @@ focus(Client *c)
     62  	if (selmon->sel && selmon->sel != c)
     63  		unfocus(selmon->sel, 0);
     64  	if (c) {
     65 +		if (c->cantfocus)
     66 +			return;
     67  		if (c->mon != selmon)
     68  			selmon = c->mon;
     69  		if (c->isurgent)
     70 @@ -838,16 +843,16 @@ focusstack(const Arg *arg)
     71  	if (!selmon->sel)
     72  		return;
     73  	if (arg->i > 0) {
     74 -		for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
     75 +		for (c = selmon->sel->next; c && (!ISVISIBLE(c) || c->cantfocus); c = c->next);
     76  		if (!c)
     77 -			for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
     78 +			for (c = selmon->clients; c && (!ISVISIBLE(c) || c->cantfocus); c = c->next);
     79  	} else {
     80  		for (i = selmon->clients; i != selmon->sel; i = i->next)
     81 -			if (ISVISIBLE(i))
     82 +      if (ISVISIBLE(i) && !i->cantfocus)
     83  				c = i;
     84  		if (!c)
     85  			for (; i; i = i->next)
     86 -				if (ISVISIBLE(i))
     87 +        if (ISVISIBLE(i) && !i->cantfocus)
     88  					c = i;
     89  	}
     90  	if (c) {
     91 @@ -1719,6 +1724,58 @@ togglefloating(const Arg *arg)
     92  	if (selmon->sel->isfloating)
     93  		resize(selmon->sel, selmon->sel->x, selmon->sel->y,
     94  			selmon->sel->w, selmon->sel->h, 0);
     95 +
     96 +  resetcanfocusfloating();
     97 +
     98 +	arrange(selmon);
     99 +}
    100 +
    101 +void
    102 +resetcanfocusfloating()
    103 +{
    104 +	unsigned int i, n;
    105 +	Client *c;
    106 +
    107 +	for (n = 0, c = selmon->clients; c; c = c->next, n++);
    108 +	if (n == 0)
    109 +		return;
    110 +
    111 +	for (i = 0, c = selmon->clients; c; c = c->next, i++)
    112 +    if (c->isfloating)
    113 +      c->cantfocus = 0;
    114 +
    115 +	arrange(selmon);
    116 +}
    117 +
    118 +void
    119 +togglecanfocusfloating(const Arg *arg)
    120 +{
    121 +	unsigned int i, n, y;
    122 +	Client *c, *tmp;
    123 +
    124 +	for (n = 0, c = selmon->clients; c; c = c->next)
    125 +		if (c && !c->isfloating)
    126 +			n++;
    127 +	if (n == 0) {
    128 +		resetcanfocusfloating();
    129 +		return;
    130 +	}
    131 +
    132 +	for (i = 0, y = 0, c = selmon->clients; c; c = c->next, i++)
    133 +    if (c->isfloating) {
    134 +      c->cantfocus = !c->cantfocus;
    135 +      y++;
    136 +    }
    137 +
    138 +  if (y && selmon->sel->isfloating) {
    139 +    tmp = selmon->clients;
    140 +    while (!tmp || tmp->isfloating) {
    141 +      tmp = tmp->next;
    142 +    }
    143 +
    144 +    focus(tmp);
    145 +  }
    146 +
    147  	arrange(selmon);
    148  }
    149  
    150 -- 
    151 2.27.0
    152