commit: d1f4d9e8428a00920d8740e517114a744b32c4e9
parent: f1fb34c656fdd7dc17375214deeb3a21ea580148
author: Chris Noxz <chris@noxz.tech>
date: Tue, 7 Feb 2023 12:22:06 +0100
Draw rectangles instead of using text for layout symbols
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -79,12 +79,18 @@ 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_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 const Layout layouts[] = {
/* symbol arrange function */
- [LayoutGrid] = { "\uE026\uE027",nrowgrid }, /* default */
- [LayoutTiled] = { "\uE020\uE021",tile },
- [LayoutMonocle] = { "\uE024\uE025",monocle },
- [LayoutFloating] = { "\uE022\uE023",NULL }, /* no layout function means floating behavior */
+ [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 */
};
/* context menu command used when right clicking root window */
diff --git a/dwm.c b/dwm.c
@@ -109,12 +109,12 @@ struct Client {
};
typedef struct {
- const char *symbol;
void (*arrange)(Monitor *);
+ int *rec;
+ int reclength;
} Layout;
struct Monitor {
- char ltsymbol[16];
int nmaster;
int num;
int by; /* bar geometry */
@@ -444,7 +444,6 @@ arrange(Monitor *m)
void
arrangemon(Monitor *m)
{
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
}
@@ -540,7 +539,7 @@ void
cleanup(void)
{
Arg a = {.ui = ~0};
- Layout foo = { "", NULL };
+ Layout foo = { NULL };
Monitor *m;
size_t i;
@@ -712,7 +711,6 @@ createmon(void)
m->gap = gap;
m->lt[0] = &layouts[0];
m->lt[1] = &layouts[1 % LENGTH(layouts)];
- strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
m->pertag = ecalloc(1, sizeof(Pertag));
m->pertag->curtag = m->pertag->prevtag = 1;
for (i = 0; i <= LENGTH(tags); i++) {
@@ -958,9 +956,14 @@ drawbar(Monitor *m)
drw_rect(drw, x + ulinepad, bh - ulinestroke - ulinevoffset, w - (ulinepad * 2), ulinestroke, 1, 0);
x += w;
}
- w = blw = TEXTW(m->ltsymbol);
+ w = blw = r_basewidth;
drw_setscheme(drw, scheme[SchemeLayout]);
- x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
+ 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;
if ((w = m->ww - tw - x) > bh) {
if (m->sel) {
@@ -1370,14 +1373,7 @@ maprequest(XEvent *e)
void
monocle(Monitor *m)
{
- unsigned int n = 0;
Client *c;
-
- for (c = m->clients; c; c = c->next)
- if (ISVISIBLE(c))
- n++;
- if (n > 0) /* override layout symbol */
- snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
}
@@ -1873,7 +1869,6 @@ setlayout(const Arg *arg)
selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel)
arrange(selmon);
else
@@ -1924,7 +1919,6 @@ rotatelayout(const Arg *arg)
selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = &layouts[idx];
selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
- strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
if (selmon->sel)
arrange(selmon);
else