fix crash on initializing colorschemes

This commit is contained in:
Luca Bilke 2023-02-09 21:34:40 +01:00
parent 9ca0c8c715
commit 6ba83ad46b
3 changed files with 33 additions and 19 deletions

View File

@ -20,24 +20,34 @@ static const char *fonts[] = {
"monospace:pixelsize=30", "monospace:pixelsize=30",
}; };
static const char colors[][7] = { static const char color0[] = "#15161E";
[0] = "#15161E", [1] = "#f7768e", [2] = "#9ece6a", [3] = "#e0af68", static const char color1[] = "#f7768e";
[4] = "#7aa2f7", [5] = "#bb9af7", [6] = "#7dcfff", [7] = "#a9b1d6", static const char color2[] = "#9ece6a";
[8] = "#414868", [9] = "#f7768e", [10] = "#9ece6a", [11] = "#e0af68", static const char color3[] = "#e0af68";
[12] = "#7aa2f7", [13] = "#bb9af7", [14] = "#7dcfff", [15] = "#c0caf5", static const char color4[] = "#7aa2f7";
/* Extra Colors (not accessible with SGR escapes) */ static const char color5[] = "#bb9af7";
[16] = "#383c4a", [17] = "#7aa2f7", static const char color6[] = "#7dcfff";
}; static const char color7[] = "#a9b1d6";
static const char color8[] = "#414868";
static const char color9[] = "#f7768e";
static const char color10[] = "#9ece6a";
static const char color11[] = "#e0af68";
static const char color12[] = "#7aa2f7";
static const char color13[] = "#bb9af7";
static const char color14[] = "#7dcfff";
static const char color15[] = "#c0caf5";
static const char bordernorm[] = "#383c4a";
static const char bordersel[] = "#7aa2f7";
static const char *barschemes[7][3] = { static const char *barschemes[][3] = {
/* fg bg border */ /* fg bg border */
[SchemeNorm] = {colors[15], colors[0], colors[16]}, [SchemeNorm] = { color15, color0, bordernorm },
[SchemeSel] = {colors[15], colors[4], colors[17]}, [SchemeSel] = { color15, color4, bordersel },
[SchemeStatus] = {colors[7], colors[0], "#000000"}, // Statusbar right [SchemeStatus] = { color7, color0, "#000000" }, // Statusbar right
[SchemeTagsSel] = {colors[0], colors[4], "#000000"}, // Tagbar left selected [SchemeTagsSel] = { color0, color4, "#000000" }, // Tagbar left selected
[SchemeTagsNorm] = {colors[7], colors[0], "#000000"}, // Tagbar left unselected [SchemeTagsNorm] = { color7, color0, "#000000" }, // Tagbar left unselected
[SchemeInfoSel] = {colors[7], colors[0], "#000000"}, // infobar middle selected [SchemeInfoSel] = { color7, color0, "#000000" }, // infobar middle selected
[SchemeInfoNorm] = {colors[7], colors[0], "#000000"}, // infobar middle unselected [SchemeInfoNorm] = { color7, color0, "#000000" }, // infobar middle unselected
}; };
/* tagging */ /* tagging */

2
drw.c
View File

@ -174,7 +174,7 @@ void drw_clr_create(Drw *drw, Clr *dest, const char *clrname) {
/* Wrapper to create color schemes. The caller has to call free(3) on the /* Wrapper to create color schemes. The caller has to call free(3) on the
* returned color scheme when done using it. */ * returned color scheme when done using it. */
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) { Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) {
size_t i; int i;
Clr *ret; Clr *ret;
/* need at least two colors for a scheme */ /* need at least two colors for a scheme */

6
dwm.c
View File

@ -381,6 +381,11 @@ static xcb_connection_t *xcon;
/* configuration, allows nested code to access above variables */ /* configuration, allows nested code to access above variables */
#include "config.h" #include "config.h"
static const char *colors[] = {
color0, color1, color2, color3, color4, color5, color6, color7,
color8, color9, color10, color11, color12, color13, color14, color15,
};
struct Pertag { struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */ unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
@ -2313,7 +2318,6 @@ void setup(void) {
scheme[i] = drw_scm_create(drw, barschemes[i], 3); scheme[i] = drw_scm_create(drw, barschemes[i], 3);
barclrs = ecalloc(LENGTH(colors), sizeof(Clr)); barclrs = ecalloc(LENGTH(colors), sizeof(Clr));
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
drw_clr_create(drw, &barclrs[i], colors[i]); drw_clr_create(drw, &barclrs[i], colors[i]);