dwm-noxz

[fork] suckless dwm - personal fork
git clone https://noxz.tech/git/dwm-noxz.git
Log | Files | README | LICENSE

commit: 79ea37f0f0b678e9f8354e8c607beb957a2e03e6
parent: 7911386107e442d7cf26db00af21644a35b6a6ae
author: Chris Noxz <chris@noxz.tech>
date:   Tue, 7 Feb 2023 20:06:06 +0100
Create function for drawing icons
Mconfig.def.h20++++----
Mdwm.c54++++++++++++--------
2 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -76,19 +76,19 @@ static const Rule rules[] = { NULL
 static int nmaster              = 1;    /* number of clients in master area */
 static int resizehints          = 0;    /* 1 means respect size hints in tiled resizals */
 
-static int r_basewidth          = 30;
-static int r_wmicon[]           = {13,4,3,3,17,8,3,3,9,12,3,3,13,12,3,3,17,12,3,3};
-static int r_nrowgrid[]         = {8,6,6,4,16,6,6,4,8,11,4,3,13,11,4,3,18,11,4,3};
-static int r_tile[]             = {8,6,8,4,8,11,8,3,17,6,5,2,17,9,5,2,17,12,5,2};
-static int r_monocle[]          = {8,6,4,1,18,6,4,1,8,13,4,1,18,13,4,1,8,7,1,2,21,7,1,2,8,11,1,2,21,11,1,2};
-static int r_float[]            = {8,6,10,2,8,8,3,3,12,9,10,5};
+static int i_basewidth          = 30;
+static int i_wmicon[]           = {4,0,3,3,8,4,3,3,0,8,3,3,4,8,3,3,8,8,3,3};
+static int i_nrowgrid[]         = {0,1,7,4,8,1,6,4,0,6,4,3,5,6,4,3,10,6,4,3};
+static int i_tile[]             = {0,1,8,4,0,6,8,3,9,1,5,2,9,4,5,2,9,7,5,2};
+static int i_monocle[]          = {0,1,4,1,10,1,4,1,0,8,4,1,10,8,4,1,0,2,1,2,13,2,1,2,0,6,1,2,13,6,1,2};
+static int i_float[]            = {0,1,10,2,0,3,3,3,4,4,10,5};
 
 static const Layout layouts[] = {
 	/* symbol     arrange function */
-	[LayoutGrid]                = { nrowgrid, r_nrowgrid, LENGTH(r_nrowgrid) }, /* default */
-	[LayoutTiled]               = { tile, r_tile, LENGTH(r_tile) },
-	[LayoutMonocle]             = { monocle, r_monocle, LENGTH(r_monocle) },
-	[LayoutFloating]            = { NULL, r_float, LENGTH(r_float) },    /* no layout function means floating behavior */
+	[LayoutGrid]                = { nrowgrid, i_nrowgrid, LENGTH(i_nrowgrid) }, /* default */
+	[LayoutTiled]               = { tile, i_tile, LENGTH(i_tile) },
+	[LayoutMonocle]             = { monocle, i_monocle, LENGTH(i_monocle) },
+	[LayoutFloating]            = { NULL, i_float, LENGTH(i_float) },           /* no layout function means floating behavior */
 };
 
 /* context menu command used when right clicking root window */
diff --git a/dwm.c b/dwm.c
@@ -110,8 +110,8 @@ struct Client {
 
 typedef struct {
 	void (*arrange)(Monitor *);
-	int *rec;
-	int reclength;
+	int *icon;
+	int vectlength;
 } Layout;
 
 struct Monitor {
@@ -189,6 +189,7 @@ static void dispatchline(const char*, int, void (*)(const Arg*), const Arg*);
 static void dispatchcmd(void);
 static void drawbar(Monitor *m);
 static void drawbars(void);
+static void drawicon(int scheme_type, int *icon, int size, int offset);
 static void enqueue(Client *c);
 static void enqueuestack(Client *c);
 static Bool evpredicate();
@@ -904,7 +905,7 @@ drawbar(Monitor *m)
 			tp = ++ts;
 		}
 		tw += 2; /* 2px right padding */
-		tx = -r_basewidth;
+		tx = -i_basewidth;
 		ts = stext;
 		tp = stext;
 		while (1) {
@@ -918,17 +919,11 @@ drawbar(Monitor *m)
 			*ts = ctmp;
 			tp = ++ts;
 		}
-		tw += r_basewidth;
+		tw += i_basewidth;
 	}
 
 	/* draw wm icon */
-	x = m->ww - r_basewidth;
-	drw_setscheme(drw, scheme[SchemeWMIcon]);
-	drw_rect(drw, x, 0, r_basewidth, bh, 1, 1);
-	if (LENGTH(r_wmicon) % 4 == 0) { /* draw wm icon */
-		for (i = 0; i < LENGTH(r_wmicon); i+=4)
-			drw_rect(drw, x + r_wmicon[i], r_wmicon[i+1], r_wmicon[i+2], r_wmicon[i+3], 1, 0);
-	}
+	drawicon(SchemeWMIcon, i_wmicon, LENGTH(i_wmicon), m->ww - i_basewidth);
 
 	for (i = 0; i < LENGTH(tags); i++)
 		masterclientontag[i] = NULL;
@@ -947,8 +942,8 @@ drawbar(Monitor *m)
 					masterclientontag[i][j] = tolower(masterclientontag[i][j]);
 			}
 	}
-	x = 0;
-	for (i = 0; i < LENGTH(tags); i++) {
+
+	for (i = x = 0; i < LENGTH(tags); i++) {
 		/* do not draw vacant tags */
 		if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
 			continue;
@@ -967,14 +962,10 @@ drawbar(Monitor *m)
 			drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
 		x += w;
 	}
-	w = blw = r_basewidth;
-	drw_setscheme(drw, scheme[SchemeLayout]);
-	drw_rect(drw, x, 0, w, bh, 1, 1);
-	if (m->lt[0]->reclength % 4 == 0) { /* draw symbol */
-		for (i = 0; i < m->lt[0]->reclength; i+=4)
-			drw_rect(drw, x + m->lt[0]->rec[i], m->lt[0]->rec[i+1], m->lt[0]->rec[i+2], m->lt[0]->rec[i+3], 1, 0);
-	}
-	x += w;
+
+	/* draw layout icon */
+	drawicon(SchemeLayout, m->lt[0]->icon, m->lt[0]->vectlength, x);
+	x += blw = i_basewidth;
 
 	if ((w = m->ww - tw - x) > bh) {
 		if (m->sel) {
@@ -1002,6 +993,27 @@ drawbars(void)
 		drawbar(m);
 }
 
+void
+drawicon(int scheme_type, int *icon, int size, int offset)
+{
+	int i, x, y;
+	if (size == 0 || size % 4 != 0)
+		return;
+
+	for (i = x = y = 0; i < size;
+	     x = MAX(x, icon[i + 0] + icon[i + 2]),
+	     y = MAX(y, icon[i + 1] + icon[i + 3]), i+=4);
+	x = (i_basewidth - x) / 2 + offset;
+	y = (bh - y) / 2;
+
+	drw_setscheme(drw, scheme[scheme_type]);
+
+	/* draw icon */
+	drw_rect(drw, offset, 0, i_basewidth, bh, 1, 1);
+	for (i = 0; i < size; i+=4)
+		drw_rect(drw, x + icon[i], y + icon[i+1], icon[i+2], icon[i+3], 1, 0);
+}
+
 void
 enqueue(Client *c)
 {