dwm-status2d-barpadding-20241018-44e9799.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dwm-status2d-barpadding-20241018-44e9799.diff (8229B)
---
1 From 44e97990dcea2c2866b0c03abbb9372e10cfb185 Mon Sep 17 00:00:00 2001
2 From: elbachir-one <bachiralfa@gmail.com>
3 Date: Fri, 18 Oct 2024 19:22:49 +0100
4 Subject: [PATCH] Status2d + Barpadding
5
6 ---
7 config.def.h | 2 +
8 dwm.c | 143 +++++++++++++++++++++++++++++++++++++++++++++------
9 2 files changed, 130 insertions(+), 15 deletions(-)
10
11 diff --git a/config.def.h b/config.def.h
12 index 4412cb1..63fa9f3 100644
13 --- a/config.def.h
14 +++ b/config.def.h
15 @@ -5,6 +5,8 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
16 static const unsigned int snap = 32; /* snap pixel */
17 static const int showbar = 1; /* 0 means no bar */
18 static const int topbar = 1; /* 0 means bottom bar */
19 +static const int vertpad = 10; /* vertical padding of bar */
20 +static const int sidepad = 10; /* horizontal padding of bar */
21 static const char *fonts[] = { "monospace:size=10" };
22 static const char dmenufont[] = "monospace:size=10";
23 static const char col_gray1[] = "#222222";
24 diff --git a/dwm.c b/dwm.c
25 index 1443802..aa6e2d0 100644
26 --- a/dwm.c
27 +++ b/dwm.c
28 @@ -162,6 +162,7 @@ static void detachstack(Client *c);
29 static Monitor *dirtomon(int dir);
30 static void drawbar(Monitor *m);
31 static void drawbars(void);
32 +static int drawstatusbar(Monitor *m, int bh, char* text);
33 static void enternotify(XEvent *e);
34 static void expose(XEvent *e);
35 static void focus(Client *c);
36 @@ -235,11 +236,13 @@ static void zoom(const Arg *arg);
37
38 /* variables */
39 static const char broken[] = "broken";
40 -static char stext[256];
41 +static char stext[1024];
42 static int screen;
43 static int sw, sh; /* X display screen geometry width, height */
44 static int bh; /* bar height */
45 static int lrpad; /* sum of left and right padding for text */
46 +static int vp; /* vertical padding for bar */
47 +static int sp; /* side padding for bar */
48 static int (*xerrorxlib)(Display *, XErrorEvent *);
49 static unsigned int numlockmask = 0;
50 static void (*handler[LASTEvent]) (XEvent *) = {
51 @@ -485,7 +488,7 @@ cleanup(void)
52 cleanupmon(mons);
53 for (i = 0; i < CurLast; i++)
54 drw_cur_free(drw, cursor[i]);
55 - for (i = 0; i < LENGTH(colors); i++)
56 + for (i = 0; i < LENGTH(colors) + 1; i++)
57 free(scheme[i]);
58 free(scheme);
59 XDestroyWindow(dpy, wmcheckwin);
60 @@ -569,7 +572,7 @@ configurenotify(XEvent *e)
61 for (c = m->clients; c; c = c->next)
62 if (c->isfullscreen)
63 resizeclient(c, m->mx, m->my, m->mw, m->mh);
64 - XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
65 + XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh);
66 }
67 focus(NULL);
68 arrange(NULL);
69 @@ -694,6 +697,114 @@ dirtomon(int dir)
70 return m;
71 }
72
73 +int
74 +drawstatusbar(Monitor *m, int bh, char* stext) {
75 + int ret, i, w, x, len;
76 + short isCode = 0;
77 + char *text;
78 + char *p;
79 +
80 + len = strlen(stext) + 1 ;
81 + if (!(text = (char*) malloc(sizeof(char)*len)))
82 + die("malloc");
83 + p = text;
84 + memcpy(text, stext, len);
85 +
86 + /* compute width of the status text */
87 + w = 0;
88 + i = -1;
89 + while (text[++i]) {
90 + if (text[i] == '^') {
91 + if (!isCode) {
92 + isCode = 1;
93 + text[i] = '\0';
94 + w += TEXTW(text) - lrpad;
95 + text[i] = '^';
96 + if (text[++i] == 'f')
97 + w += atoi(text + ++i);
98 + } else {
99 + isCode = 0;
100 + text = text + i + 1;
101 + i = -1;
102 + }
103 + }
104 + }
105 + if (!isCode)
106 + w += TEXTW(text) - lrpad;
107 + else
108 + isCode = 0;
109 + text = p;
110 +
111 + w += 2; /* 1px padding on both sides */
112 + ret = x = m->ww - w;
113 +
114 + drw_setscheme(drw, scheme[LENGTH(colors)]);
115 + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
116 + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
117 + drw_rect(drw, x - 2 * sp, 0, w, bh, 1, 1);
118 + x++;
119 +
120 + /* process status text */
121 + i = -1;
122 + while (text[++i]) {
123 + if (text[i] == '^' && !isCode) {
124 + isCode = 1;
125 +
126 + text[i] = '\0';
127 + w = TEXTW(text) - lrpad;
128 + drw_text(drw, x - 2 * sp, 0, w, bh, 0, text, 0);
129 +
130 + x += w;
131 +
132 + /* process code */
133 + while (text[++i] != '^') {
134 + if (text[i] == 'c') {
135 + char buf[8];
136 + memcpy(buf, (char*)text+i+1, 7);
137 + buf[7] = '\0';
138 + drw_clr_create(drw, &drw->scheme[ColFg], buf);
139 + i += 7;
140 + } else if (text[i] == 'b') {
141 + char buf[8];
142 + memcpy(buf, (char*)text+i+1, 7);
143 + buf[7] = '\0';
144 + drw_clr_create(drw, &drw->scheme[ColBg], buf);
145 + i += 7;
146 + } else if (text[i] == 'd') {
147 + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg];
148 + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg];
149 + } else if (text[i] == 'r') {
150 + int rx = atoi(text + ++i);
151 + while (text[++i] != ',');
152 + int ry = atoi(text + ++i);
153 + while (text[++i] != ',');
154 + int rw = atoi(text + ++i);
155 + while (text[++i] != ',');
156 + int rh = atoi(text + ++i);
157 +
158 + drw_rect(drw, rx + x - 2 * sp, ry, rw, rh, 1, 0);
159 + } else if (text[i] == 'f') {
160 + x += atoi(text + ++i);
161 + }
162 + }
163 +
164 + text = text + i + 1;
165 + i=-1;
166 + isCode = 0;
167 + }
168 + }
169 +
170 + if (!isCode) {
171 + w = TEXTW(text) - lrpad;
172 + drw_text(drw, x - 2 * sp, 0, w, bh, 0, text, 0);
173 + }
174 +
175 + drw_setscheme(drw, scheme[SchemeNorm]);
176 + free(p);
177 +
178 + return ret;
179 +}
180 +
181 void
182 drawbar(Monitor *m)
183 {
184 @@ -708,9 +819,7 @@ drawbar(Monitor *m)
185
186 /* draw status first so it can be overdrawn by tags later */
187 if (m == selmon) { /* status is only drawn on selected monitor */
188 - drw_setscheme(drw, scheme[SchemeNorm]);
189 - tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
190 - drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
191 + tw = m->ww - drawstatusbar(m, bh, stext);
192 }
193
194 for (c = m->clients; c; c = c->next) {
195 @@ -736,12 +845,12 @@ drawbar(Monitor *m)
196 if ((w = m->ww - tw - x) > bh) {
197 if (m->sel) {
198 drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
199 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
200 + drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0);
201 if (m->sel->isfloating)
202 drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
203 } else {
204 drw_setscheme(drw, scheme[SchemeNorm]);
205 - drw_rect(drw, x, 0, w, bh, 1, 1);
206 + drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1);
207 }
208 }
209 drw_map(drw, m->barwin, 0, 0, m->ww, bh);
210 @@ -1562,7 +1671,10 @@ setup(void)
211 die("no fonts could be loaded.");
212 lrpad = drw->fonts->h;
213 bh = drw->fonts->h + 2;
214 + sp = sidepad;
215 + vp = (topbar == 1) ? vertpad : - vertpad;
216 updategeom();
217 +
218 /* init atoms */
219 utf8string = XInternAtom(dpy, "UTF8_STRING", False);
220 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
221 @@ -1583,7 +1695,8 @@ setup(void)
222 cursor[CurResize] = drw_cur_create(drw, XC_sizing);
223 cursor[CurMove] = drw_cur_create(drw, XC_fleur);
224 /* init appearance */
225 - scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
226 + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *));
227 + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], 3);
228 for (i = 0; i < LENGTH(colors); i++)
229 scheme[i] = drw_scm_create(drw, colors[i], 3);
230 /* init bars */
231 @@ -1716,7 +1829,7 @@ togglebar(const Arg *arg)
232 {
233 selmon->showbar = !selmon->showbar;
234 updatebarpos(selmon);
235 - XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
236 + XMoveResizeWindow(dpy, selmon->barwin, selmon->wx + sp, selmon->by + vp, selmon->ww - 2 * sp, bh);
237 arrange(selmon);
238 }
239
240 @@ -1827,7 +1940,7 @@ updatebars(void)
241 for (m = mons; m; m = m->next) {
242 if (m->barwin)
243 continue;
244 - m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
245 + m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen),
246 CopyFromParent, DefaultVisual(dpy, screen),
247 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
248 XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
249 @@ -1842,11 +1955,11 @@ updatebarpos(Monitor *m)
250 m->wy = m->my;
251 m->wh = m->mh;
252 if (m->showbar) {
253 - m->wh -= bh;
254 - m->by = m->topbar ? m->wy : m->wy + m->wh;
255 - m->wy = m->topbar ? m->wy + bh : m->wy;
256 + m->wh = m->wh - vertpad - bh;
257 + m->by = m->topbar ? m->wy : m->wy + m->wh + vertpad;
258 + m->wy = m->topbar ? m->wy + bh + vp : m->wy;
259 } else
260 - m->by = -bh;
261 + m->by = -bh - vp;
262 }
263
264 void
265 --
266 2.46.2
267