-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdwm-tagicons-6.5.diff
274 lines (258 loc) · 8.53 KB
/
dwm-tagicons-6.5.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
From 529379046812733537e0c165bc2d8d3488350fb8 Mon Sep 17 00:00:00 2001
From: Bakkeby <[email protected]>
Date: Wed, 26 Jun 2024 22:53:19 +0200
Subject: [PATCH] tagicons patch
Refer to:
https://github.com/bakkeby/patches/wiki/tagicons
---
config.def.h | 13 +++++--
dwm.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 99 insertions(+), 12 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9efa774..7953203 100644
--- a/config.def.h
+++ b/config.def.h
@@ -18,8 +18,13 @@ static const char *colors[][3] = {
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
};
-/* tagging */
-static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+/* tagging: refer to https://github.com/bakkeby/patches/wiki/tagicons */
+static const char *tags[NUMTAGS] = { NULL }; /* left for compatibility reasons, i.e. code that checks LENGTH(tags) */
+static char *tagicons[][NUMTAGS] = {
+ [IconsDefault] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" },
+ [IconsVacant] = { NULL },
+ [IconsOccupied] = { NULL },
+};
static const Rule rules[] = {
/* xprop(1):
@@ -85,6 +90,8 @@ static const Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
+// { MODKEY|ShiftMask, XK_a, seticonset, {.i = 0 } },
+// { MODKEY|ShiftMask, XK_b, seticonset, {.i = 1 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
@@ -112,5 +119,7 @@ static const Button buttons[] = {
{ ClkTagBar, 0, Button3, toggleview, {0} },
{ ClkTagBar, MODKEY, Button1, tag, {0} },
{ ClkTagBar, MODKEY, Button3, toggletag, {0} },
+ { ClkTagBar, 0, Button4, cycleiconset, {.i = +1 } },
+ { ClkTagBar, 0, Button5, cycleiconset, {.i = -1 } },
};
diff --git a/dwm.c b/dwm.c
index f1d86b2..bb48a4e 100644
--- a/dwm.c
+++ b/dwm.c
@@ -45,6 +45,7 @@
#include "util.h"
/* macros */
+#define NUMTAGS 9 /* the number of tags per monitor */
#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
#define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
@@ -54,7 +55,7 @@
#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
-#define TAGMASK ((1 << LENGTH(tags)) - 1)
+#define TAGMASK ((1 << NUMTAGS) - 1)
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
@@ -66,6 +67,12 @@ enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
+enum {
+ IconsDefault,
+ IconsVacant,
+ IconsOccupied,
+ IconsLast
+}; /* icon sets */
typedef union {
int i;
@@ -124,6 +131,7 @@ struct Monitor {
unsigned int tagset[2];
int showbar;
int topbar;
+ int iconset;
Client *clients;
Client *sel;
Client *stack;
@@ -157,6 +165,7 @@ static void configure(Client *c);
static void configurenotify(XEvent *e);
static void configurerequest(XEvent *e);
static Monitor *createmon(void);
+static void cycleiconset(const Arg *arg);
static void destroynotify(XEvent *e);
static void detach(Client *c);
static void detachstack(Client *c);
@@ -170,6 +179,7 @@ static void focusin(XEvent *e);
static void focusmon(const Arg *arg);
static void focusstack(const Arg *arg);
static Atom getatomprop(Client *c, Atom prop);
+static char * geticon(Monitor *m, int tag, int iconset);
static int getrootptr(int *x, int *y);
static long getstate(Window w);
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
@@ -200,6 +210,7 @@ static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
+static void seticonset(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
static void setup(void);
@@ -207,6 +218,7 @@ static void seturgent(Client *c, int urg);
static void showhide(Client *c);
static void spawn(const Arg *arg);
static void tag(const Arg *arg);
+static char * tagicon(Monitor *m, int tag);
static void tagmon(const Arg *arg);
static void tile(Monitor *m);
static void togglebar(const Arg *arg);
@@ -272,7 +284,7 @@ static Window root, wmcheckwin;
#include "config.h"
/* compile-time check if all tags fit into an unsigned int bit array. */
-struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+struct NumTags { char limitexceeded[NUMTAGS > 31 ? -1 : 1]; };
/* function implementations */
void
@@ -418,7 +430,7 @@ attachstack(Client *c)
void
buttonpress(XEvent *e)
{
- unsigned int i, x, click;
+ unsigned int i, x, tw, click;
Arg arg = {0};
Client *c;
Monitor *m;
@@ -433,10 +445,13 @@ buttonpress(XEvent *e)
}
if (ev->window == selmon->barwin) {
i = x = 0;
- do
- x += TEXTW(tags[i]);
- while (ev->x >= x && ++i < LENGTH(tags));
- if (i < LENGTH(tags)) {
+ do {
+ tw = TEXTW(tagicon(selmon, i));
+ if (tw <= lrpad)
+ continue;
+ x += tw;
+ } while (ev->x >= x && ++i < NUMTAGS);
+ if (i < NUMTAGS) {
click = ClkTagBar;
arg.ui = 1 << i;
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
@@ -647,6 +662,24 @@ createmon(void)
return m;
}
+void
+cycleiconset(const Arg *arg)
+{
+ Monitor *m = selmon;
+ if (arg->i == 0)
+ return;
+ if (arg->i > 0) {
+ for (++m->iconset; m->iconset < IconsLast && tagicons[m->iconset][0] == NULL; ++m->iconset);
+ if (m->iconset >= IconsLast)
+ m->iconset = 0;
+ } else if (arg->i < 0) {
+ for (--m->iconset; m->iconset > 0 && tagicons[m->iconset][0] == NULL; --m->iconset);
+ if (m->iconset < 0)
+ for (m->iconset = IconsLast - 1; m->iconset > 0 && tagicons[m->iconset][0] == NULL; --m->iconset);
+ }
+ drawbar(m);
+}
+
void
destroynotify(XEvent *e)
{
@@ -702,6 +735,7 @@ drawbar(Monitor *m)
int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
+ char *icon;
Client *c;
if (!m->showbar)
@@ -720,10 +754,13 @@ drawbar(Monitor *m)
urg |= c->tags;
}
x = 0;
- for (i = 0; i < LENGTH(tags); i++) {
- w = TEXTW(tags[i]);
+ for (i = 0; i < NUMTAGS; i++) {
+ icon = tagicon(m, i);
+ w = TEXTW(icon);
+ if (w <= lrpad)
+ continue;
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, icon, urg & 1 << i);
if (occ & 1 << i)
drw_rect(drw, x + boxs, boxs, boxw, boxw,
m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
@@ -877,6 +914,20 @@ getatomprop(Client *c, Atom prop)
return atom;
}
+char *
+geticon(Monitor *m, int tag, int iconset)
+{
+ int i;
+ int tagindex = tag + NUMTAGS * m->num;
+ for (i = 0; i < LENGTH(tagicons[iconset]) && tagicons[iconset][i] != NULL; ++i);
+ if (i == 0)
+ tagindex = 0;
+ else if (tagindex >= i)
+ tagindex = tagindex % i;
+
+ return tagicons[iconset][tagindex];
+}
+
int
getrootptr(int *x, int *y)
{
@@ -1507,6 +1558,15 @@ setfullscreen(Client *c, int fullscreen)
}
}
+void
+seticonset(const Arg *arg)
+{
+ if (arg->i >= 0 && arg->i < IconsLast) {
+ selmon->iconset = arg->i;
+ drawbar(selmon);
+ }
+}
+
void
setlayout(const Arg *arg)
{
@@ -1676,6 +1736,24 @@ tag(const Arg *arg)
}
}
+char *
+tagicon(Monitor *m, int tag)
+{
+ Client *c;
+ char *icon;
+ for (c = m->clients; c && (!(c->tags & 1 << tag)); c = c->next);
+ // for (c = m->clients; c && (!(c->tags & 1 << tag) || HIDDEN(c)); c = c->next); // awesomebar / wintitleactions compatibility
+ if (c && tagicons[IconsOccupied][0] != NULL)
+ icon = geticon(m, tag, IconsOccupied);
+ else {
+ icon = geticon(m, tag, m->iconset);
+ if (TEXTW(icon) <= lrpad && m->tagset[m->seltags] & 1 << tag)
+ icon = geticon(m, tag, IconsVacant);
+ }
+
+ return icon;
+}
+
void
tagmon(const Arg *arg)
{
--
2.45.2