sites

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

dwm-focusmaster-return-20210729-138b405.diff (1789B)


      1 From 36c4e246ad47333f2b8a82610ba2adebeb2043b2 Mon Sep 17 00:00:00 2001
      2 From: Jack Bird <jack.bird@durham.ac.uk>
      3 Date: Thu, 29 Jul 2021 21:39:33 +0100
      4 Subject: [PATCH] Able to switch to master from anywhere in the stack and can
      5  also return to the previously selected client from the master
      6 
      7 ---
      8  dwm.c | 28 ++++++++++++++++++++++++++++
      9  1 file changed, 28 insertions(+)
     10 
     11 diff --git a/dwm.c b/dwm.c
     12 index 5e4d494..eab8d57 100644
     13 --- a/dwm.c
     14 +++ b/dwm.c
     15 @@ -127,6 +127,7 @@ struct Monitor {
     16  	Client *clients;
     17  	Client *sel;
     18  	Client *stack;
     19 +	Client *stackfocused;
     20  	Monitor *next;
     21  	Window barwin;
     22  	const Layout *lt[2];
     23 @@ -167,6 +168,7 @@ static void enternotify(XEvent *e);
     24  static void expose(XEvent *e);
     25  static void focus(Client *c);
     26  static void focusin(XEvent *e);
     27 +static void focusmaster(const Arg *arg);
     28  static void focusmon(const Arg *arg);
     29  static void focusstack(const Arg *arg);
     30  static Atom getatomprop(Client *c, Atom prop);
     31 @@ -660,6 +662,9 @@ detach(Client *c)
     32  {
     33  	Client **tc;
     34  
     35 +	if (c == c->mon->stackfocused)
     36 +		c->mon->stackfocused = NULL;
     37 +
     38  	for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
     39  	*tc = c->next;
     40  }
     41 @@ -816,6 +821,28 @@ focusin(XEvent *e)
     42  		setfocus(selmon->sel);
     43  }
     44  
     45 +void
     46 +focusmaster(const Arg *arg)
     47 +{
     48 +	Client *master;
     49 +
     50 +	if (selmon->nmaster > 1)
     51 +		return;
     52 +
     53 +	master = nexttiled(selmon->clients);
     54 +
     55 +	if (!master)
     56 +		return;
     57 +
     58 +	if (selmon->sel == master) {
     59 +		if (master->mon->stackfocused)
     60 +			focus(master->mon->stackfocused);
     61 +	} else {
     62 +		master->mon->stackfocused = master->mon->sel;
     63 +		focus(master);
     64 +	}
     65 +}
     66 +
     67  void
     68  focusmon(const Arg *arg)
     69  {
     70 @@ -1203,6 +1230,7 @@ nexttiled(Client *c)
     71  void
     72  pop(Client *c)
     73  {
     74 +	c->mon->stackfocused = nexttiled(c->mon->clients);
     75  	detach(c);
     76  	attach(c);
     77  	focus(c);
     78 -- 
     79 2.32.0
     80