dwm-barconfig-20220906-c2b748e.diff (5641B)
1 From 42d79a0a4f4eee5a985a1427cd84e8dbf055e11d Mon Sep 17 00:00:00 2001 2 From: Dylan Cairns-Howarth <dairnarth@dylancairns.co.uk> 3 Date: Tue, 6 Sep 2022 03:29:59 +0100 4 Subject: [PATCH] Allow bar order to be configured in config.h 5 6 This patch adds char *barlayout to config(.def).h which can contain as 7 many or as few of the characters 'l', 'n', 's', 't', or '|' to configure 8 the order of dwm's bar. 9 10 l Layout indicator; 11 n Window name; 12 s Status (set with xsetroot); 13 t Tag indicators; 14 | Split point. 15 16 Everything before '|' (and if it is omitted) will appear on the left of 17 the bar. Everything after will appear on the right, but in reverse 18 order. 19 20 By default, this patch leaves the bar as is. 21 --- 22 config.def.h | 2 +- 23 dwm.c | 117 +++++++++++++++++++++++++++++++++++---------------- 24 2 files changed, 81 insertions(+), 38 deletions(-) 25 26 diff --git a/config.def.h b/config.def.h 27 index 061ad66..463d7f4 100644 28 --- a/config.def.h 29 +++ b/config.def.h 30 @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ 31 static const unsigned int snap = 32; /* snap pixel */ 32 static const int showbar = 1; /* 0 means no bar */ 33 static const int topbar = 1; /* 0 means bottom bar */ 34 +static const char *barlayout = "tln|s"; 35 static const char *fonts[] = { "monospace:size=10" }; 36 static const char dmenufont[] = "monospace:size=10"; 37 static const char col_gray1[] = "#222222"; 38 @@ -112,4 +113,3 @@ static const Button buttons[] = { 39 { ClkTagBar, MODKEY, Button1, tag, {0} }, 40 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 41 }; 42 - 43 diff --git a/dwm.c b/dwm.c 44 index e5efb6a..5da79b5 100644 45 --- a/dwm.c 46 +++ b/dwm.c 47 @@ -699,53 +699,96 @@ dirtomon(int dir) 48 void 49 drawbar(Monitor *m) 50 { 51 - int x, w, tw = 0; 52 + int x = 0, w, tw = 0, moveright = 0; 53 int boxs = drw->fonts->h / 9; 54 int boxw = drw->fonts->h / 6 + 2; 55 - unsigned int i, occ = 0, urg = 0; 56 + unsigned int i, j, occ = 0, urg = 0; 57 Client *c; 58 59 if (!m->showbar) 60 return; 61 + if (barlayout[0] == '\0') 62 + barlayout = "tln|s"; 63 64 - /* draw status first so it can be overdrawn by tags later */ 65 - if (m == selmon) { /* status is only drawn on selected monitor */ 66 - drw_setscheme(drw, scheme[SchemeNorm]); 67 - tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ 68 - drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); 69 - } 70 - 71 - for (c = m->clients; c; c = c->next) { 72 - occ |= c->tags; 73 - if (c->isurgent) 74 - urg |= c->tags; 75 - } 76 - x = 0; 77 - for (i = 0; i < LENGTH(tags); i++) { 78 - w = TEXTW(tags[i]); 79 - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 80 - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 81 - if (occ & 1 << i) 82 - drw_rect(drw, x + boxs, boxs, boxw, boxw, 83 - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 84 - urg & 1 << i); 85 - x += w; 86 - } 87 - w = TEXTW(m->ltsymbol); 88 drw_setscheme(drw, scheme[SchemeNorm]); 89 - x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 90 - 91 - if ((w = m->ww - tw - x) > bh) { 92 - if (m->sel) { 93 - drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); 94 - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); 95 - if (m->sel->isfloating) 96 - drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); 97 - } else { 98 - drw_setscheme(drw, scheme[SchemeNorm]); 99 - drw_rect(drw, x, 0, w, bh, 1, 1); 100 + drw_text(drw, 0, 0, m->ww, bh, 0, "", 0); /* draw background */ 101 + 102 + for (i = 0; i < strlen(barlayout); i++) { 103 + switch (barlayout[i]) { 104 + case 'l': 105 + w = TEXTW(m->ltsymbol); 106 + drw_setscheme(drw, scheme[SchemeNorm]); 107 + if (moveright) { 108 + x -= w; 109 + drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 110 + } else 111 + x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 112 + break; 113 + 114 + case 'n': 115 + tw = TEXTW(m->sel->name); 116 + if (moveright) 117 + x -= tw; 118 + if (m->sel) { 119 + drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); 120 + drw_text(drw, x, 0, moveright ? tw : m->ww, bh, lrpad / 2, m->sel->name, 0); 121 + if (m->sel->isfloating) 122 + drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); 123 + } else { 124 + drw_setscheme(drw, scheme[SchemeNorm]); 125 + drw_rect(drw, x, 0, tw, bh, 1, 1); 126 + } 127 + if (!moveright) 128 + x += tw; 129 + break; 130 + 131 + case 's': 132 + if (m == selmon) { /* status is only drawn on selected monitor */ 133 + drw_setscheme(drw, scheme[SchemeNorm]); 134 + tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ 135 + if (moveright) { 136 + x -= tw; 137 + drw_text(drw, x, 0, tw, bh, 0, stext, 0); 138 + } else 139 + x = drw_text(drw, x, 0, tw, bh, 0, stext, 0); 140 + } 141 + break; 142 + 143 + case 't': 144 + for (c = m->clients; c; c = c->next) { 145 + occ |= c->tags; 146 + if (c->isurgent) 147 + urg |= c->tags; 148 + } 149 + /* tags */ 150 + if (moveright) { 151 + tw = 0; 152 + for (j = 0; j < LENGTH(tags); j++) { 153 + tw += TEXTW(tags[j]); 154 + } 155 + x -= tw; 156 + } 157 + for (j = 0; j < LENGTH(tags); j++) { 158 + w = TEXTW(tags[j]); 159 + drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << j ? SchemeSel : SchemeNorm]); 160 + drw_text(drw, x, 0, w, bh, lrpad / 2, tags[j], urg & 1 << j); 161 + if (occ & 1 << j) 162 + drw_rect(drw, x + boxs, boxs, boxw, boxw, 163 + m == selmon && selmon->sel && selmon->sel->tags & 1 << j, 164 + urg & 1 << i); 165 + x += w; 166 + } 167 + if (moveright) 168 + x -= tw; 169 + break; 170 + 171 + case '|': 172 + moveright = 1; 173 + x = m->ww; 174 + break; 175 } 176 } 177 + 178 drw_map(drw, m->barwin, 0, 0, m->ww, bh); 179 } 180 181 -- 182 2.37.3 183