dwm-namedscratchpads-6.5.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-namedscratchpads-6.5.diff (4568B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 9efa774..c3e236e 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -26,9 +26,10 @@ static const Rule rules[] = {
6 * WM_CLASS(STRING) = instance, class
7 * WM_NAME(STRING) = title
8 */
9 - /* class instance title tags mask isfloating monitor */
10 - { "Gimp", NULL, NULL, 0, 1, -1 },
11 - { "Firefox", NULL, NULL, 1 << 8, 0, -1 },
12 + /* class instance title tags mask isfloating monitor scratch key */
13 + { "Gimp", NULL, NULL, 0, 1, -1, 0 },
14 + { "firefox", NULL, NULL, 1 << 8, 0, -1, 0 },
15 + { NULL, NULL, "scratchpad", 0, 1, -1, 's' },
16 };
17
18 /* layout(s) */
19 @@ -60,10 +61,14 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
20 static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
21 static const char *termcmd[] = { "st", NULL };
22
23 +/*First arg only serves to match against key in rules*/
24 +static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL};
25 +
26 static const Key keys[] = {
27 /* modifier key function argument */
28 { MODKEY, XK_p, spawn, {.v = dmenucmd } },
29 { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
30 + { MODKEY, XK_grave, togglescratch, {.v = scratchpadcmd } },
31 { MODKEY, XK_b, togglebar, {0} },
32 { MODKEY, XK_j, focusstack, {.i = +1 } },
33 { MODKEY, XK_k, focusstack, {.i = -1 } },
34 diff --git a/dwm.c b/dwm.c
35 index f1d86b2..be6a754 100644
36 --- a/dwm.c
37 +++ b/dwm.c
38 @@ -93,6 +93,7 @@ struct Client {
39 int bw, oldbw;
40 unsigned int tags;
41 int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
42 + char scratchkey;
43 Client *next;
44 Client *snext;
45 Monitor *mon;
46 @@ -139,6 +140,7 @@ typedef struct {
47 unsigned int tags;
48 int isfloating;
49 int monitor;
50 + const char scratchkey;
51 } Rule;
52
53 /* function declarations */
54 @@ -206,11 +208,13 @@ static void setup(void);
55 static void seturgent(Client *c, int urg);
56 static void showhide(Client *c);
57 static void spawn(const Arg *arg);
58 +static void spawnscratch(const Arg *arg);
59 static void tag(const Arg *arg);
60 static void tagmon(const Arg *arg);
61 static void tile(Monitor *m);
62 static void togglebar(const Arg *arg);
63 static void togglefloating(const Arg *arg);
64 +static void togglescratch(const Arg *arg);
65 static void toggletag(const Arg *arg);
66 static void toggleview(const Arg *arg);
67 static void unfocus(Client *c, int setfocus);
68 @@ -287,6 +291,7 @@ applyrules(Client *c)
69 /* rule matching */
70 c->isfloating = 0;
71 c->tags = 0;
72 + c->scratchkey = 0;
73 XGetClassHint(dpy, c->win, &ch);
74 class = ch.res_class ? ch.res_class : broken;
75 instance = ch.res_name ? ch.res_name : broken;
76 @@ -299,6 +304,7 @@ applyrules(Client *c)
77 {
78 c->isfloating = r->isfloating;
79 c->tags |= r->tags;
80 + c->scratchkey = r->scratchkey;
81 for (m = mons; m && m->num != r->monitor; m = m->next);
82 if (m)
83 c->mon = m;
84 @@ -308,6 +314,7 @@ applyrules(Client *c)
85 XFree(ch.res_class);
86 if (ch.res_name)
87 XFree(ch.res_name);
88 +
89 c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
90 }
91
92 @@ -1666,6 +1673,27 @@ spawn(const Arg *arg)
93 }
94 }
95
96 +void spawnscratch(const Arg *arg)
97 +{
98 + struct sigaction sa;
99 +
100 + if (fork() == 0) {
101 + if (dpy)
102 + close(ConnectionNumber(dpy));
103 + setsid();
104 +
105 + sigemptyset(&sa.sa_mask);
106 + sa.sa_flags = 0;
107 + sa.sa_handler = SIG_DFL;
108 + sigaction(SIGCHLD, &sa, NULL);
109 +
110 + execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
111 + fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
112 + perror(" failed");
113 + exit(EXIT_SUCCESS);
114 + }
115 +}
116 +
117 void
118 tag(const Arg *arg)
119 {
120 @@ -1735,6 +1763,28 @@ togglefloating(const Arg *arg)
121 arrange(selmon);
122 }
123
124 +void
125 +togglescratch(const Arg *arg)
126 +{
127 + Client *c;
128 + unsigned int found = 0;
129 +
130 + for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next);
131 + if (found) {
132 + c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags];
133 + focus(NULL);
134 + arrange(selmon);
135 +
136 + if (ISVISIBLE(c)) {
137 + focus(c);
138 + restack(selmon);
139 + }
140 +
141 + } else{
142 + spawnscratch(arg);
143 + }
144 +}
145 +
146 void
147 toggletag(const Arg *arg)
148 {