sites

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

dwm-scratchtagwins-6.5.diff (7432B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 9efa774..ac40b35 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -21,14 +21,26 @@ static const char *colors[][3]      = {
      6  /* tagging */
      7  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
      8  
      9 +#include "scratchtagwins.c"
     10 +
     11  static const Rule rules[] = {
     12  	/* xprop(1):
     13  	 *	WM_CLASS(STRING) = instance, class
     14  	 *	WM_NAME(STRING) = title
     15  	 */
     16 -	/* class      instance    title       tags mask     isfloating   monitor */
     17 -	{ "Gimp",     NULL,       NULL,       0,            1,           -1 },
     18 -	{ "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
     19 +	/* class      instance    title       tags mask     isfloating   monitor    scratch key */
     20 +	{ "Gimp",     NULL,       NULL,       0,            1,           -1,        0  },
     21 +	{ "firefox",  NULL,       NULL,       1 << 8,       0,           -1,        0  },
     22 +	{ NULL,       NULL,   "scratchpad",   0,            1,           -1,       's' },
     23 +	SCRATCHTAGWIN_RULE (scratchtagwin1, 1),
     24 +	SCRATCHTAGWIN_RULE (scratchtagwin2, 2),
     25 +	SCRATCHTAGWIN_RULE (scratchtagwin3, 3),
     26 +	SCRATCHTAGWIN_RULE (scratchtagwin4, 4),
     27 +	SCRATCHTAGWIN_RULE (scratchtagwin5, 5),
     28 +	SCRATCHTAGWIN_RULE (scratchtagwin6, 6),
     29 +	SCRATCHTAGWIN_RULE (scratchtagwin7, 7),
     30 +	SCRATCHTAGWIN_RULE (scratchtagwin8, 8),
     31 +	SCRATCHTAGWIN_RULE (scratchtagwin9, 9),
     32  };
     33  
     34  /* layout(s) */
     35 @@ -60,10 +72,35 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
     36  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
     37  static const char *termcmd[]  = { "st", NULL };
     38  
     39 +SCRATCHTAGWIN (scratchtagwin1, 1);
     40 +SCRATCHTAGWIN (scratchtagwin2, 2);
     41 +SCRATCHTAGWIN (scratchtagwin3, 3);
     42 +SCRATCHTAGWIN (scratchtagwin4, 4);
     43 +SCRATCHTAGWIN (scratchtagwin5, 5);
     44 +SCRATCHTAGWIN (scratchtagwin6, 6);
     45 +SCRATCHTAGWIN (scratchtagwin7, 7);
     46 +SCRATCHTAGWIN (scratchtagwin8, 8);
     47 +SCRATCHTAGWIN (scratchtagwin9, 9);
     48 +
     49 +/*First arg only serves to match against key in rules*/
     50 +static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL};
     51 +
     52  static const Key keys[] = {
     53  	/* modifier                     key        function        argument */
     54  	{ MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
     55  	{ MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
     56 +	{ MODKEY,                       XK_grave,  togglescratch,  {.v = scratchpadcmd } },
     57 +	SCRATCHTAGWIN_KEY (scratchtagwin1, 1)
     58 +	SCRATCHTAGWIN_KEY (scratchtagwin2, 2)
     59 +	SCRATCHTAGWIN_KEY (scratchtagwin3, 3)
     60 +	SCRATCHTAGWIN_KEY (scratchtagwin4, 4)
     61 +	SCRATCHTAGWIN_KEY (scratchtagwin5, 5)
     62 +	SCRATCHTAGWIN_KEY (scratchtagwin6, 6)
     63 +	SCRATCHTAGWIN_KEY (scratchtagwin7, 7)
     64 +	SCRATCHTAGWIN_KEY (scratchtagwin8, 8)
     65 +	SCRATCHTAGWIN_KEY (scratchtagwin9, 9)
     66 +	{ MODKEY|Mod1Mask|ShiftMask,     XK_0,  makescratchtagwin,  {.i = 0} },
     67 +	{ MODKEY|Mod1Mask|ShiftMask,     XK_s,  makescratchtagwin,  {.i = 's'} },
     68  	{ MODKEY,                       XK_b,      togglebar,      {0} },
     69  	{ MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
     70  	{ MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
     71 diff --git a/dwm.c b/dwm.c
     72 index f1d86b2..be6a754 100644
     73 --- a/dwm.c
     74 +++ b/dwm.c
     75 @@ -93,6 +93,7 @@ struct Client {
     76  	int bw, oldbw;
     77  	unsigned int tags;
     78  	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
     79 +	char scratchkey;
     80  	Client *next;
     81  	Client *snext;
     82  	Monitor *mon;
     83 @@ -139,6 +140,7 @@ typedef struct {
     84  	unsigned int tags;
     85  	int isfloating;
     86  	int monitor;
     87 +	const char scratchkey;
     88  } Rule;
     89  
     90  /* function declarations */
     91 @@ -206,11 +208,13 @@ static void setup(void);
     92  static void seturgent(Client *c, int urg);
     93  static void showhide(Client *c);
     94  static void spawn(const Arg *arg);
     95 +static void spawnscratch(const Arg *arg);
     96  static void tag(const Arg *arg);
     97  static void tagmon(const Arg *arg);
     98  static void tile(Monitor *m);
     99  static void togglebar(const Arg *arg);
    100  static void togglefloating(const Arg *arg);
    101 +static void togglescratch(const Arg *arg);
    102  static void toggletag(const Arg *arg);
    103  static void toggleview(const Arg *arg);
    104  static void unfocus(Client *c, int setfocus);
    105 @@ -287,6 +291,7 @@ applyrules(Client *c)
    106  	/* rule matching */
    107  	c->isfloating = 0;
    108  	c->tags = 0;
    109 +	c->scratchkey = 0;
    110  	XGetClassHint(dpy, c->win, &ch);
    111  	class    = ch.res_class ? ch.res_class : broken;
    112  	instance = ch.res_name  ? ch.res_name  : broken;
    113 @@ -299,6 +304,7 @@ applyrules(Client *c)
    114  		{
    115  			c->isfloating = r->isfloating;
    116  			c->tags |= r->tags;
    117 +			c->scratchkey = r->scratchkey;
    118  			for (m = mons; m && m->num != r->monitor; m = m->next);
    119  			if (m)
    120  				c->mon = m;
    121 @@ -308,6 +314,7 @@ applyrules(Client *c)
    122  		XFree(ch.res_class);
    123  	if (ch.res_name)
    124  		XFree(ch.res_name);
    125 +
    126  	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
    127  }
    128  
    129 @@ -1666,6 +1673,27 @@ spawn(const Arg *arg)
    130  	}
    131  }
    132  
    133 +void spawnscratch(const Arg *arg)
    134 +{
    135 +	struct sigaction sa;
    136 +
    137 +	if (fork() == 0) {
    138 +		if (dpy)
    139 +			close(ConnectionNumber(dpy));
    140 +		setsid();
    141 +
    142 +		sigemptyset(&sa.sa_mask);
    143 +		sa.sa_flags = 0;
    144 +		sa.sa_handler = SIG_DFL;
    145 +		sigaction(SIGCHLD, &sa, NULL);
    146 +
    147 +		execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
    148 +		fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
    149 +		perror(" failed");
    150 +		exit(EXIT_SUCCESS);
    151 +	}
    152 +}
    153 +
    154  void
    155  tag(const Arg *arg)
    156  {
    157 @@ -1735,6 +1763,28 @@ togglefloating(const Arg *arg)
    158  	arrange(selmon);
    159  }
    160  
    161 +void
    162 +togglescratch(const Arg *arg)
    163 +{
    164 +	Client *c;
    165 +	unsigned int found = 0;
    166 +
    167 +	for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next);
    168 +	if (found) {
    169 +		c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags];
    170 +		focus(NULL);
    171 +		arrange(selmon);
    172 +
    173 +		if (ISVISIBLE(c)) {
    174 +			focus(c);
    175 +			restack(selmon);
    176 +		}
    177 +
    178 +	} else{
    179 +		spawnscratch(arg);
    180 +	}
    181 +}
    182 +
    183  void
    184  toggletag(const Arg *arg)
    185  {
    186 diff --git a/scratchtagwins.c b/scratchtagwins.c
    187 new file mode 100644
    188 index 0000000..f51be3b
    189 --- /dev/null
    190 +++ b/scratchtagwins.c
    191 @@ -0,0 +1,53 @@
    192 +#include <stdio.h>
    193 +#include <stdlib.h>
    194 +#include <string.h>
    195 +
    196 +#include <X11/XF86keysym.h>
    197 +
    198 +# define SCRATCHTAGWIN(name, id)								\
    199 +	static const char * name [] = { # id,						\
    200 +		"tabbed",												\
    201 +			"-p", "s+1",										\
    202 +			"-n", # name,										\
    203 +			"-g", "1195x672",									\
    204 +			"-c", "st", "-w",									\
    205 +		NULL													\
    206 +	}															\
    207 +
    208 +# define SCRATCHTAGWIN_RULE(name, id)																	\
    209 +	{ NULL,       # name, NULL,       0,            1,           -1,      '0' + id }		\
    210 +
    211 +# define SCRATCHTAGWIN_KEY(name, id)														\
    212 +	{ MODKEY|Mod1Mask,          XK_ ## id,      togglescratch,  {.v = name } },				\
    213 +	{ MODKEY|Mod1Mask|ShiftMask,XK_ ## id,      makescratchtagwin,{.i = '0' + id } },		\
    214 +
    215 +static void makescratchtagwin (const Arg * arg)
    216 +{
    217 +	if (selmon -> sel)
    218 +	{
    219 +		if (arg -> i != 0)
    220 +		{
    221 +			_Bool exists = 0;
    222 +
    223 +			for (Client * c = selmon -> clients; c; c = c -> next)
    224 +				if (c -> scratchkey == arg -> i)
    225 +				{
    226 +					exists = 1;
    227 +					break;
    228 +				}
    229 +
    230 +			if (exists) return;
    231 +		}
    232 +
    233 +		selmon -> sel -> scratchkey = arg -> i;
    234 +		if (arg -> i != 0)
    235 +		{
    236 +			selmon -> sel -> tags = 0,
    237 +			selmon -> sel -> isfloating = 1;
    238 +		}
    239 +		else
    240 +			selmon -> sel -> tags = selmon -> tagset [selmon -> seltags];
    241 +		focus (selmon -> sel);
    242 +		arrange (selmon);
    243 +	}
    244 +}