sites

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

dwm-stacker-6.2.diff (6584B)


      1 From d04f2d00688c8b0969d4f10f460c980dd91dac37 Mon Sep 17 00:00:00 2001
      2 From: MLquest8 <miskuzius@gmail.com>
      3 Date: Fri, 12 Jun 2020 16:04:18 +0400
      4 Subject: [PATCH] stacker updated for version 6.2
      5 
      6 ---
      7  config.def.h | 14 +++++++--
      8  dwm.c        | 88 ++++++++++++++++++++++++++++++++++++++++------------
      9  2 files changed, 80 insertions(+), 22 deletions(-)
     10 
     11 diff --git a/config.def.h b/config.def.h
     12 index 1c0b587..d28f8fc 100644
     13 --- a/config.def.h
     14 +++ b/config.def.h
     15 @@ -50,6 +50,14 @@ static const Layout layouts[] = {
     16  	{ MODKEY|ControlMask,           KEY,      toggleview,     {.ui = 1 << TAG} }, \
     17  	{ MODKEY|ShiftMask,             KEY,      tag,            {.ui = 1 << TAG} }, \
     18  	{ MODKEY|ControlMask|ShiftMask, KEY,      toggletag,      {.ui = 1 << TAG} },
     19 +#define STACKKEYS(MOD,ACTION) \
     20 +	{ MOD, XK_j,     ACTION##stack, {.i = INC(+1) } }, \
     21 +	{ MOD, XK_k,     ACTION##stack, {.i = INC(-1) } }, \
     22 +	{ MOD, XK_grave, ACTION##stack, {.i = PREVSEL } }, \
     23 +	{ MOD, XK_q,     ACTION##stack, {.i = 0 } }, \
     24 +	{ MOD, XK_a,     ACTION##stack, {.i = 1 } }, \
     25 +	{ MOD, XK_z,     ACTION##stack, {.i = 2 } }, \
     26 +	{ MOD, XK_x,     ACTION##stack, {.i = -1 } },
     27  
     28  /* helper for spawning shell commands in the pre dwm-5.0 fashion */
     29  #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
     30 @@ -64,8 +72,8 @@ static Key keys[] = {
     31  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     32  	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     33  	{ MODKEY,                       XK_b,      togglebar,      {0} },
     34 -	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     35 -	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     36 +	STACKKEYS(MODKEY,                          focus)
     37 +	STACKKEYS(MODKEY|ShiftMask,                push)
     38  	{ MODKEY,                       XK_i,      incnmaster,     {.i = +1 } },
     39  	{ MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
     40  	{ MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
     41 @@ -93,7 +101,7 @@ static Key keys[] = {
     42  	TAGKEYS(                        XK_7,                      6)
     43  	TAGKEYS(                        XK_8,                      7)
     44  	TAGKEYS(                        XK_9,                      8)
     45 -	{ MODKEY|ShiftMask,             XK_q,      quit,           {0} },
     46 +	{ MODKEY|ShiftMask,             XK_BackSpace, quit,        {0} },
     47  };
     48  
     49  /* button definitions */
     50 diff --git a/dwm.c b/dwm.c
     51 index 9fd0286..6c302c3 100644
     52 --- a/dwm.c
     53 +++ b/dwm.c
     54 @@ -47,15 +47,21 @@
     55  /* macros */
     56  #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
     57  #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
     58 +#define GETINC(X)               ((X) - 2000)
     59 +#define INC(X)                  ((X) + 2000)
     60  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
     61                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
     62 +#define ISINC(X)                ((X) > 1000 && (X) < 3000)
     63  #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
     64 +#define PREVSEL                 3000
     65  #define LENGTH(X)               (sizeof X / sizeof X[0])
     66 +#define MOD(N,M)                ((N)%(M) < 0 ? (N)%(M) + (M) : (N)%(M))
     67  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
     68  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
     69  #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
     70  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
     71  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
     72 +#define TRUNC(X,A,B)            (MAX((A), MIN((X), (B))))
     73  
     74  /* enums */
     75  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     76 @@ -187,6 +193,7 @@ static void movemouse(const Arg *arg);
     77  static Client *nexttiled(Client *c);
     78  static void pop(Client *);
     79  static void propertynotify(XEvent *e);
     80 +static void pushstack(const Arg *arg);
     81  static void quit(const Arg *arg);
     82  static Monitor *recttomon(int x, int y, int w, int h);
     83  static void resize(Client *c, int x, int y, int w, int h, int interact);
     84 @@ -207,6 +214,7 @@ static void seturgent(Client *c, int urg);
     85  static void showhide(Client *c);
     86  static void sigchld(int unused);
     87  static void spawn(const Arg *arg);
     88 +static int stackpos(const Arg *arg);
     89  static void tag(const Arg *arg);
     90  static void tagmon(const Arg *arg);
     91  static void tile(Monitor *);
     92 @@ -833,27 +841,16 @@ focusmon(const Arg *arg)
     93  void
     94  focusstack(const Arg *arg)
     95  {
     96 -	Client *c = NULL, *i;
     97 +	int i = stackpos(arg);
     98 +	Client *c, *p;
     99  
    100 -	if (!selmon->sel)
    101 +	if(i < 0)
    102  		return;
    103 -	if (arg->i > 0) {
    104 -		for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
    105 -		if (!c)
    106 -			for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
    107 -	} else {
    108 -		for (i = selmon->clients; i != selmon->sel; i = i->next)
    109 -			if (ISVISIBLE(i))
    110 -				c = i;
    111 -		if (!c)
    112 -			for (; i; i = i->next)
    113 -				if (ISVISIBLE(i))
    114 -					c = i;
    115 -	}
    116 -	if (c) {
    117 -		focus(c);
    118 -		restack(selmon);
    119 -	}
    120 +
    121 +	for(p = NULL, c = selmon->clients; c && (i || !ISVISIBLE(c));
    122 +	    i -= ISVISIBLE(c) ? 1 : 0, p = c, c = c->next);
    123 +	focus(c ? c : p);
    124 +	restack(selmon);
    125  }
    126  
    127  Atom
    128 @@ -1246,6 +1243,29 @@ propertynotify(XEvent *e)
    129  	}
    130  }
    131  
    132 +void
    133 +pushstack(const Arg *arg) {
    134 +	int i = stackpos(arg);
    135 +	Client *sel = selmon->sel, *c, *p;
    136 +
    137 +	if(i < 0)
    138 +		return;
    139 +	else if(i == 0) {
    140 +		detach(sel);
    141 +		attach(sel);
    142 +	}
    143 +	else {
    144 +		for(p = NULL, c = selmon->clients; c; p = c, c = c->next)
    145 +			if(!(i -= (ISVISIBLE(c) && c != sel)))
    146 +				break;
    147 +		c = c ? c : p;
    148 +		detach(sel);
    149 +		sel->next = c->next;
    150 +		c->next = sel;
    151 +	}
    152 +	arrange(selmon);
    153 +}
    154 +
    155  void
    156  quit(const Arg *arg)
    157  {
    158 @@ -1653,6 +1673,36 @@ spawn(const Arg *arg)
    159  	}
    160  }
    161  
    162 +int
    163 +stackpos(const Arg *arg) {
    164 +	int n, i;
    165 +	Client *c, *l;
    166 +
    167 +	if(!selmon->clients)
    168 +		return -1;
    169 +
    170 +	if(arg->i == PREVSEL) {
    171 +		for(l = selmon->stack; l && (!ISVISIBLE(l) || l == selmon->sel); l = l->snext);
    172 +		if(!l)
    173 +			return -1;
    174 +		for(i = 0, c = selmon->clients; c != l; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
    175 +		return i;
    176 +	}
    177 +	else if(ISINC(arg->i)) {
    178 +		if(!selmon->sel)
    179 +			return -1;
    180 +		for(i = 0, c = selmon->clients; c != selmon->sel; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
    181 +		for(n = i; c; n += ISVISIBLE(c) ? 1 : 0, c = c->next);
    182 +		return MOD(i + GETINC(arg->i), n);
    183 +	}
    184 +	else if(arg->i < 0) {
    185 +		for(i = 0, c = selmon->clients; c; i += ISVISIBLE(c) ? 1 : 0, c = c->next);
    186 +		return MAX(i + arg->i, 0);
    187 +	}
    188 +	else
    189 +		return arg->i;
    190 +}
    191 +
    192  void
    193  tag(const Arg *arg)
    194  {
    195 -- 
    196 2.26.2
    197