dwm-bartabgroups-20210802-138b405.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-bartabgroups-20210802-138b405.diff (7095B)
---
1 From 653c99b94cc780a2def9c7e50a87703156535f8b Mon Sep 17 00:00:00 2001
2 From: Jack Bird <jack.bird@durham.ac.uk>
3 Date: Mon, 2 Aug 2021 18:50:02 +0100
4 Subject: [PATCH] bartabgroups updated to work with 138b405
5
6 ---
7 config.def.h | 11 +++++
8 dwm.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++-----
9 2 files changed, 112 insertions(+), 11 deletions(-)
10
11 diff --git a/config.def.h b/config.def.h
12 index a2ac963..82accf1 100644
13 --- a/config.def.h
14 +++ b/config.def.h
15 @@ -16,6 +16,8 @@ static const char *colors[][3] = {
16 /* fg bg border */
17 [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
18 [SchemeSel] = { col_gray4, col_cyan, col_cyan },
19 + [SchemeTabActive] = { col_gray2, col_gray3, col_gray2 },
20 + [SchemeTabInactive] = { col_gray1, col_gray3, col_gray1 }
21 };
22
23 /* tagging */
24 @@ -37,6 +39,15 @@ static const int nmaster = 1; /* number of clients in master area */
25 static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
26 static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
27
28 +/* Bartabgroups properties */
29 +#define BARTAB_BORDERS 1 // 0 = off, 1 = on
30 +#define BARTAB_BOTTOMBORDER 1 // 0 = off, 1 = on
31 +#define BARTAB_TAGSINDICATOR 1 // 0 = off, 1 = on if >1 client/view tag, 2 = always on
32 +#define BARTAB_TAGSPX 5 // # pixels for tag grid boxes
33 +#define BARTAB_TAGSROWS 3 // # rows in tag grid (9 tags, e.g. 3x3)
34 +static void (*bartabmonfns[])(Monitor *) = { monocle /* , customlayoutfn */ };
35 +static void (*bartabfloatfns[])(Monitor *) = { NULL /* , customlayoutfn */ };
36 +
37 static const Layout layouts[] = {
38 /* symbol arrange function */
39 { "[]=", tile }, /* first entry is default */
40 diff --git a/dwm.c b/dwm.c
41 index 5e4d494..1839a56 100644
42 --- a/dwm.c
43 +++ b/dwm.c
44 @@ -59,7 +59,7 @@
45
46 /* enums */
47 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
48 -enum { SchemeNorm, SchemeSel }; /* color schemes */
49 +enum { SchemeNorm, SchemeSel, SchemeTabActive, SchemeTabInactive }; /* color schemes */
50 enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
51 NetWMFullscreen, NetActiveWindow, NetWMWindowType,
52 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
53 @@ -378,6 +378,98 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
54 return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
55 }
56
57 +void
58 +bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive) {
59 + if (!c) return;
60 + int i, nclienttags = 0, nviewtags = 0;
61 +
62 + drw_setscheme(drw, scheme[
63 + m->sel == c ? SchemeSel : (groupactive ? SchemeTabActive: SchemeTabInactive)
64 + ]);
65 + drw_text(drw, x, 0, w, bh, lrpad / 2, c->name, 0);
66 +
67 + // Floating win indicator
68 + if (c->isfloating) drw_rect(drw, x + 2, 2, 5, 5, 0, 0);
69 +
70 + // Optional borders between tabs
71 + if (BARTAB_BORDERS) {
72 + XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBorder].pixel);
73 + XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, 0, 1, bh);
74 + XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w, 0, 1, bh);
75 + }
76 +
77 + // Optional tags icons
78 + for (i = 0; i < LENGTH(tags); i++) {
79 + if ((m->tagset[m->seltags] >> i) & 1) { nviewtags++; }
80 + if ((c->tags >> i) & 1) { nclienttags++; }
81 + }
82 + if (BARTAB_TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1) {
83 + for (i = 0; i < LENGTH(tags); i++) {
84 + drw_rect(drw,
85 + ( x + w - 2 - ((LENGTH(tags) / BARTAB_TAGSROWS) * BARTAB_TAGSPX)
86 + - (i % (LENGTH(tags)/BARTAB_TAGSROWS)) + ((i % (LENGTH(tags) / BARTAB_TAGSROWS)) * BARTAB_TAGSPX)
87 + ),
88 + ( 2 + ((i / (LENGTH(tags)/BARTAB_TAGSROWS)) * BARTAB_TAGSPX)
89 + - ((i / (LENGTH(tags)/BARTAB_TAGSROWS)))
90 + ),
91 + BARTAB_TAGSPX, BARTAB_TAGSPX, (c->tags >> i) & 1, 0
92 + );
93 + }
94 + }
95 +}
96 +
97 +void
98 +battabclick(Monitor *m, Client *c, int passx, int x, int w, int unused) {
99 + if (passx >= x && passx <= x + w) {
100 + focus(c);
101 + restack(selmon);
102 + }
103 +}
104 +
105 +void
106 +bartabcalculate(
107 + Monitor *m, int offx, int sw, int passx,
108 + void(*tabfn)(Monitor *, Client *, int, int, int, int)
109 +) {
110 + Client *c;
111 + int
112 + i, clientsnmaster = 0, clientsnstack = 0, clientsnfloating = 0,
113 + masteractive = 0, fulllayout = 0, floatlayout = 0,
114 + x, w, tgactive;
115 +
116 + for (i = 0, c = m->clients; c; c = c->next) {
117 + if (!ISVISIBLE(c)) continue;
118 + if (c->isfloating) { clientsnfloating++; continue; }
119 + if (m->sel == c) { masteractive = i < m->nmaster; }
120 + if (i < m->nmaster) { clientsnmaster++; } else { clientsnstack++; }
121 + i++;
122 + }
123 + for (i = 0; i < LENGTH(bartabfloatfns); i++) if (m ->lt[m->sellt]->arrange == bartabfloatfns[i]) { floatlayout = 1; break; }
124 + for (i = 0; i < LENGTH(bartabmonfns); i++) if (m ->lt[m->sellt]->arrange == bartabmonfns[i]) { fulllayout = 1; break; }
125 + for (c = m->clients, i = 0; c; c = c->next) {
126 + if (!ISVISIBLE(c)) continue;
127 + if (clientsnmaster + clientsnstack == 0 || floatlayout) {
128 + x = offx + (((m->mw - offx - sw) / (clientsnmaster + clientsnstack + clientsnfloating)) * i);
129 + w = (m->mw - offx - sw) / (clientsnmaster + clientsnstack + clientsnfloating);
130 + tgactive = 1;
131 + } else if (!c->isfloating && (fulllayout || ((clientsnmaster == 0) ^ (clientsnstack == 0)))) {
132 + x = offx + (((m->mw - offx - sw) / (clientsnmaster + clientsnstack)) * i);
133 + w = (m->mw - offx - sw) / (clientsnmaster + clientsnstack);
134 + tgactive = 1;
135 + } else if (i < m->nmaster && !c->isfloating) {
136 + x = offx + ((((m->mw * m->mfact) - offx) /clientsnmaster) * i);
137 + w = ((m->mw * m->mfact) - offx) / clientsnmaster;
138 + tgactive = masteractive;
139 + } else if (!c->isfloating) {
140 + x = (m->mw * m->mfact) + ((((m->mw * (1 - m->mfact)) - sw) / clientsnstack) * (i - m->nmaster));
141 + w = ((m->mw * (1 - m->mfact)) - sw) / clientsnstack;
142 + tgactive = !masteractive;
143 + } else continue;
144 + tabfn(m, c, passx, x, w, tgactive);
145 + i++;
146 + }
147 +}
148 +
149 void
150 arrange(Monitor *m)
151 {
152 @@ -442,8 +534,8 @@ buttonpress(XEvent *e)
153 click = ClkLtSymbol;
154 else if (ev->x > selmon->ww - (int)TEXTW(stext))
155 click = ClkStatusText;
156 - else
157 - click = ClkWinTitle;
158 + else // Focus clicked tab bar item
159 + bartabcalculate(selmon, x, TEXTW(stext) - lrpad + 2, ev->x, battabclick);
160 } else if ((c = wintoclient(ev->window))) {
161 focus(c);
162 restack(selmon);
163 @@ -729,15 +821,13 @@ drawbar(Monitor *m)
164 drw_setscheme(drw, scheme[SchemeNorm]);
165 x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
166
167 + // Draw bartabgroups
168 + drw_rect(drw, x, 0, m->ww - tw - x, bh, 1, 1);
169 if ((w = m->ww - tw - x) > bh) {
170 - if (m->sel) {
171 - drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
172 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
173 - if (m->sel->isfloating)
174 - drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
175 - } else {
176 - drw_setscheme(drw, scheme[SchemeNorm]);
177 - drw_rect(drw, x, 0, w, bh, 1, 1);
178 + bartabcalculate(m, x, tw, -1, bartabdraw);
179 + if (BARTAB_BOTTOMBORDER) {
180 + drw_setscheme(drw, scheme[SchemeTabActive]);
181 + drw_rect(drw, 0, bh - 1, m->ww, 1, 1, 0);
182 }
183 }
184 drw_map(drw, m->barwin, 0, 0, m->ww, bh);
185 --
186 2.32.0
187