sites

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

dwm-rotatestack-20161021-ab9571b.diff (2549B)


      1 diff --git a/config.def.h b/config.def.h
      2 index fd77a07..09737d7 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -64,6 +64,8 @@ static Key keys[] = {
      6  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
      7  	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
      8  	{ MODKEY,                       XK_b,      togglebar,      {0} },
      9 +	{ MODKEY|ShiftMask,             XK_j,      rotatestack,    {.i = +1 } },
     10 +	{ MODKEY|ShiftMask,             XK_k,      rotatestack,    {.i = -1 } },
     11  	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     12  	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     13  	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
     14 diff --git a/dwm.c b/dwm.c
     15 index 421bf27..1ec8b10 100644
     16 --- a/dwm.c
     17 +++ b/dwm.c
     18 @@ -165,6 +165,8 @@ static void detachstack(Client *c);
     19  static Monitor *dirtomon(int dir);
     20  static void drawbar(Monitor *m);
     21  static void drawbars(void);
     22 +static void enqueue(Client *c);
     23 +static void enqueuestack(Client *c);
     24  static void enternotify(XEvent *e);
     25  static void expose(XEvent *e);
     26  static void focus(Client *c);
     27 @@ -194,6 +196,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact);
     28  static void resizeclient(Client *c, int x, int y, int w, int h);
     29  static void resizemouse(const Arg *arg);
     30  static void restack(Monitor *m);
     31 +static void rotatestack(const Arg *arg);
     32  static void run(void);
     33  static void scan(void);
     34  static int sendevent(Client *c, Atom proto);
     35 @@ -765,6 +768,28 @@ drawbars(void)
     36  }
     37  
     38  void
     39 +enqueue(Client *c)
     40 +{
     41 +	Client *l;
     42 +	for (l = c->mon->clients; l && l->next; l = l->next);
     43 +	if (l) {
     44 +		l->next = c;
     45 +		c->next = NULL;
     46 +	}
     47 +}
     48 +
     49 +void
     50 +enqueuestack(Client *c)
     51 +{
     52 +	Client *l;
     53 +	for (l = c->mon->stack; l && l->snext; l = l->snext);
     54 +	if (l) {
     55 +		l->snext = c;
     56 +		c->snext = NULL;
     57 +	}
     58 +}
     59 +
     60 +void
     61  enternotify(XEvent *e)
     62  {
     63  	Client *c;
     64 @@ -1390,6 +1415,38 @@ restack(Monitor *m)
     65  }
     66  
     67  void
     68 +rotatestack(const Arg *arg)
     69 +{
     70 +	Client *c = NULL, *f;
     71 +
     72 +	if (!selmon->sel)
     73 +		return;
     74 +	f = selmon->sel;
     75 +	if (arg->i > 0) {
     76 +		for (c = nexttiled(selmon->clients); c && nexttiled(c->next); c = nexttiled(c->next));
     77 +		if (c){
     78 +			detach(c);
     79 +			attach(c);
     80 +			detachstack(c);
     81 +			attachstack(c);
     82 +		}
     83 +	} else {
     84 +		if ((c = nexttiled(selmon->clients))){
     85 +			detach(c);
     86 +			enqueue(c);
     87 +			detachstack(c);
     88 +			enqueuestack(c);
     89 +		}
     90 +	}
     91 +	if (c){
     92 +		arrange(selmon);
     93 +		//unfocus(f, 1);
     94 +		focus(f);
     95 +		restack(selmon);
     96 +	}
     97 +}
     98 +
     99 +void
    100  run(void)
    101  {
    102  	XEvent ev;