dwm-vtcolors-6.2.diff (8073B)
1 Author: Chris Noxz <chris@noxz.tech> 2 3 diff -up ../dwm-6.2/config.def.h ./config.def.h 4 --- ../dwm-6.2/config.def.h 2019-02-02 13:55:28.000000000 +0100 5 +++ ./config.def.h 2020-02-02 10:56:38.865583817 +0100 6 @@ -12,10 +12,27 @@ static const char col_gray2[] = "# 7 static const char col_gray3[] = "#bbbbbb"; 8 static const char col_gray4[] = "#eeeeee"; 9 static const char col_cyan[] = "#005577"; 10 -static const char *colors[][3] = { 11 - /* fg bg border */ 12 - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, 13 - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, 14 +static const char title_bg_dark[] = "#303030"; 15 +static const char title_bg_light[] = "#fdfdfd"; 16 +static const int color_ptrs[][3] = { 17 + /* fg bg border */ 18 + [SchemeNorm] = { -1, -1, 5 }, 19 + [SchemeSel] = { -1, -1, 11 }, 20 + [SchemeTagsNorm] = { 2, 0, 0 }, 21 + [SchemeTagsSel] = { 6, 5, 5 }, 22 + [SchemeTitleNorm] = { 6, -1, -1 }, 23 + [SchemeTitleSel] = { 6, -1, -1 }, 24 + [SchemeStatus] = { 2, 0, 0 }, 25 +}; 26 +static char colors[][3][8] = { 27 + /* fg bg border */ 28 + [SchemeNorm] = { "#000000", "#000000", "#000000" }, 29 + [SchemeSel] = { "#000000", "#000000", "#000000" }, 30 + [SchemeTagsNorm] = { "#000000", "#000000", "#000000" }, 31 + [SchemeTagsSel] = { "#000000", "#000000", "#000000" }, 32 + [SchemeTitleNorm] = { "#000000", "#000000", "#000000" }, 33 + [SchemeTitleSel] = { "#000000", "#000000", "#000000" }, 34 + [SchemeStatus] = { "#000000", "#000000", "#000000" }, 35 }; 36 37 /* tagging */ 38 diff -up ../dwm-6.2/drw.c ./drw.c 39 --- ../dwm-6.2/drw.c 2019-02-02 13:55:28.000000000 +0100 40 +++ ./drw.c 2020-02-02 10:37:08.885745829 +0100 41 @@ -193,7 +193,7 @@ drw_fontset_free(Fnt *font) 42 } 43 44 void 45 -drw_clr_create(Drw *drw, Clr *dest, const char *clrname) 46 +drw_clr_create(Drw *drw, Clr *dest, const char clrname[]) 47 { 48 if (!drw || !dest || !clrname) 49 return; 50 @@ -207,7 +207,7 @@ drw_clr_create(Drw *drw, Clr *dest, cons 51 /* Wrapper to create color schemes. The caller has to call free(3) on the 52 * returned color scheme when done using it. */ 53 Clr * 54 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) 55 +drw_scm_create(Drw *drw, char clrnames[][8], size_t clrcount) 56 { 57 size_t i; 58 Clr *ret; 59 diff -up ../dwm-6.2/drw.h ./drw.h 60 --- ../dwm-6.2/drw.h 2019-02-02 13:55:28.000000000 +0100 61 +++ ./drw.h 2020-02-02 10:37:00.558746075 +0100 62 @@ -38,8 +38,8 @@ unsigned int drw_fontset_getwidth(Drw *d 63 void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); 64 65 /* Colorscheme abstraction */ 66 -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); 67 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); 68 +void drw_clr_create(Drw *drw, Clr *dest, const char clrname[]); 69 +Clr *drw_scm_create(Drw *drw, char clrnames[][8], size_t clrcount); 70 71 /* Cursor abstraction */ 72 Cur *drw_cur_create(Drw *drw, int shape); 73 diff -up ../dwm-6.2/dwm.c ./dwm.c 74 --- ../dwm-6.2/dwm.c 2019-02-02 13:55:28.000000000 +0100 75 +++ ./dwm.c 2020-02-02 10:57:40.659581991 +0100 76 @@ -59,7 +59,7 @@ 77 78 /* enums */ 79 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 80 -enum { SchemeNorm, SchemeSel }; /* color schemes */ 81 +enum { SchemeNorm, SchemeSel, SchemeTagsNorm, SchemeTagsSel, SchemeTitleNorm, SchemeTitleSel, SchemeStatus }; /* color schemes */ 82 enum { NetSupported, NetWMName, NetWMState, NetWMCheck, 83 NetWMFullscreen, NetActiveWindow, NetWMWindowType, 84 NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ 85 @@ -201,6 +201,8 @@ static void setfocus(Client *c); 86 static void setfullscreen(Client *c, int fullscreen); 87 static void setlayout(const Arg *arg); 88 static void setmfact(const Arg *arg); 89 +static void get_vt_colors(void); 90 +static int get_luminance(char *rgb); 91 static void setup(void); 92 static void seturgent(Client *c, int urg); 93 static void showhide(Client *c); 94 @@ -703,7 +705,7 @@ drawbar(Monitor *m) 95 96 /* draw status first so it can be overdrawn by tags later */ 97 if (m == selmon) { /* status is only drawn on selected monitor */ 98 - drw_setscheme(drw, scheme[SchemeNorm]); 99 + drw_setscheme(drw, scheme[SchemeStatus]); 100 sw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ 101 drw_text(drw, m->ww - sw, 0, sw, bh, 0, stext, 0); 102 } 103 @@ -716,7 +718,7 @@ drawbar(Monitor *m) 104 x = 0; 105 for (i = 0; i < LENGTH(tags); i++) { 106 w = TEXTW(tags[i]); 107 - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 108 + drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeTagsSel : SchemeTagsNorm]); 109 drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 110 if (occ & 1 << i) 111 drw_rect(drw, x + boxs, boxs, boxw, boxw, 112 @@ -725,17 +727,17 @@ drawbar(Monitor *m) 113 x += w; 114 } 115 w = blw = TEXTW(m->ltsymbol); 116 - drw_setscheme(drw, scheme[SchemeNorm]); 117 + drw_setscheme(drw, scheme[SchemeTagsNorm]); 118 x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); 119 120 if ((w = m->ww - sw - x) > bh) { 121 if (m->sel) { 122 - drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); 123 + drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); 124 drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); 125 if (m->sel->isfloating) 126 drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); 127 } else { 128 - drw_setscheme(drw, scheme[SchemeNorm]); 129 + drw_setscheme(drw, scheme[SchemeTitleNorm]); 130 drw_rect(drw, x, 0, w, bh, 1, 1); 131 } 132 } 133 @@ -1527,6 +1529,72 @@ setmfact(const Arg *arg) 134 } 135 136 void 137 +get_vt_colors(void) 138 +{ 139 + char *cfs[3] = { 140 + "/sys/module/vt/parameters/default_red", 141 + "/sys/module/vt/parameters/default_grn", 142 + "/sys/module/vt/parameters/default_blu", 143 + }; 144 + char vtcs[16][8]; 145 + char tk[] = ","; 146 + char cl[64]; 147 + char *tp = NULL; 148 + FILE *fp; 149 + size_t r; 150 + int i, c, n; 151 + 152 + for (i = 0; i < 16; i++) 153 + strcpy(vtcs[i], "#000000"); 154 + 155 + for (i = 0, r = 0; i < 3; i++) { 156 + if ((fp = fopen(cfs[i], "r")) == NULL) 157 + continue; 158 + while ((cl[r] = fgetc(fp)) != EOF && cl[r] != '\n') 159 + r++; 160 + cl[r] = '\0'; 161 + for (c = 0, tp = cl, n = 0; c < 16; c++, tp++) { 162 + if ((r = strcspn(tp, tk)) == -1) 163 + break; 164 + for (n = 0; r && *tp >= 48 && *tp < 58; r--, tp++) 165 + n = n * 10 - 48 + *tp; 166 + vtcs[c][i * 2 + 1] = n / 16 < 10 ? n / 16 + 48 : n / 16 + 87; 167 + vtcs[c][i * 2 + 2] = n % 16 < 10 ? n % 16 + 48 : n % 16 + 87; 168 + } 169 + fclose(fp); 170 + } 171 + for (i = 0; i < LENGTH(colors); i++) { 172 + for (c = 0; c < 3; c++) { 173 + n = color_ptrs[i][c]; 174 + if (n > -1 && strlen(colors[i][c]) >= strlen(vtcs[n])) 175 + memcpy(colors[i][c], vtcs[n], 7); 176 + } 177 + } 178 +} 179 + 180 +int get_luminance(char *r) 181 +{ 182 + char *c = r; 183 + int n[3] = {0}; 184 + int i = 0; 185 + 186 + while (*c) { 187 + if (*c >= 48 && *c < 58) 188 + n[i / 2] = n[i / 2] * 16 - 48 + *c; 189 + else if (*c >= 65 && *c < 71) 190 + n[i / 2] = n[i / 2] * 16 - 55 + *c; 191 + else if (*c >= 97 && *c < 103) 192 + n[i / 2] = n[i / 2] * 16 - 87 + *c; 193 + else 194 + i--; 195 + i++; 196 + c++; 197 + } 198 + 199 + return (0.299 * n[0] + 0.587 * n[1] + 0.114 * n[2]) / 2.55; 200 +} 201 + 202 +void 203 setup(void) 204 { 205 int i; 206 @@ -1567,6 +1635,14 @@ setup(void) 207 cursor[CurResize] = drw_cur_create(drw, XC_sizing); 208 cursor[CurMove] = drw_cur_create(drw, XC_fleur); 209 /* init appearance */ 210 + get_vt_colors(); 211 + if (get_luminance(colors[SchemeTagsNorm][ColBg]) > 50) { 212 + strcpy(colors[SchemeTitleNorm][ColBg], title_bg_light); 213 + strcpy(colors[SchemeTitleSel][ColBg], title_bg_light); 214 + } else { 215 + strcpy(colors[SchemeTitleNorm][ColBg], title_bg_dark); 216 + strcpy(colors[SchemeTitleSel][ColBg], title_bg_dark); 217 + } 218 scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); 219 for (i = 0; i < LENGTH(colors); i++) 220 scheme[i] = drw_scm_create(drw, colors[i], 3); 221 Only in ./: dwm-vtcolors-6.2.diff 222 Only in ./: .git 223 Only in ./: .gitignore