sites

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

dwm-cantogglefloating-20210124-e752d68.diff (4322B)


      1 From e752d6806ff8bb4fa23435b448affce3b0a40838 Mon Sep 17 00:00:00 2001
      2 From: Georgios Oxinos <georgios.oxinos.extern@elinvar.de>
      3 Date: Sun, 24 Jan 2021 16:05:58 +0100
      4 Subject: [PATCH] [dwm][patch] patch that allows disabling focus on floating
      5  clients
      6 
      7 ---
      8  config.def.h |  1 +
      9  dwm.c        | 63 +++++++++++++++++++++++++++++++++++++++++++++++-----
     10  2 files changed, 59 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..426262e 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 @@ -191,6 +192,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 @@ -211,6 +213,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 @@ -788,6 +791,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 @@ -837,16 +842,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 @@ -1716,6 +1721,54 @@ 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->next; c; c = c->next, n++);
    108 +	if (n == 0)
    109 +		return;
    110 +
    111 +	for (i = 0, c = selmon->clients->next; 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->next; c; c = c->next, n++);
    125 +	if (n == 0)
    126 +		return;
    127 +
    128 +	for (i = 0, y = 0, c = selmon->clients->next; c; c = c->next, i++)
    129 +    if (c->isfloating) {
    130 +      c->cantfocus = !c->cantfocus;
    131 +      y++;
    132 +    }
    133 +
    134 +  if (y && selmon->sel->isfloating) {
    135 +    tmp = selmon->clients;
    136 +    while (!tmp || tmp->isfloating) {
    137 +      tmp = tmp->next;
    138 +    }
    139 +
    140 +    focus(tmp);
    141 +  }
    142 +
    143  	arrange(selmon);
    144  }
    145  
    146 -- 
    147 2.27.0
    148