From c7e0e5d74b5df137dee3350d664eace5d2e7ae18 Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 8 May 2023 17:50:48 +0200 Subject: [PATCH] dwm-like colorscheme creation --- libs/colors.h | 2 +- libs/schemes.c | 10 ++++++---- libs/schemes.h | 1 - spmenu.c | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/libs/colors.h b/libs/colors.h index f77b623..169a91c 100644 --- a/libs/colors.h +++ b/libs/colors.h @@ -20,7 +20,7 @@ static unsigned int alphas[][2] = { }; // colorscheme array -static char *colors[SchemeLast][2] = { +static char *colors[][2] = { // fg bg [SchemeLArrow] = { col_larrowfg, col_larrowbg }, [SchemeRArrow] = { col_rarrowfg, col_rarrowbg }, diff --git a/libs/schemes.c b/libs/schemes.c index e1871f7..1be5fe7 100644 --- a/libs/schemes.c +++ b/libs/schemes.c @@ -3,7 +3,7 @@ char sixd_to_8bit(int x) { } void init_appearance(void) { - int i, j; + int i = 0, j = 0; char cbuf[8]; @@ -40,9 +40,11 @@ void init_appearance(void) { alphas[SchemeBorder][ColBg] = alpha_border; // create color schemes from array - for (j = 0; j < SchemeLast; j++) { - scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2); - } + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], alphas[i], 2); + + for (i = 0; i < LENGTH(colors) && i < LENGTH(alphas); i++) + scheme[i] = drw_scm_create(drw, colors[i], alphas[i], 2); for (i = 0; i < LENGTH(textcolors) && i < LENGTH(textclrs); i++) drw_clr_create(drw, &textclrs[i], textcolors[i], 0); diff --git a/libs/schemes.h b/libs/schemes.h index 914d50f..884f8a5 100644 --- a/libs/schemes.h +++ b/libs/schemes.h @@ -17,5 +17,4 @@ enum { SchemeLArrow, SchemeMode, SchemeBorder, SchemeCaps, - SchemeLast, }; diff --git a/spmenu.c b/spmenu.c index 216d96c..38d696b 100644 --- a/spmenu.c +++ b/spmenu.c @@ -216,7 +216,7 @@ static Visual *visual; static int depth; static Colormap cmap; static Drw *drw; -static Clr *scheme[SchemeLast]; +static Clr **scheme; static Clr textclrs[256]; // declare functions @@ -368,7 +368,7 @@ void cleanup(void) { XUngrabKey(dpy, AnyKey, AnyModifier, root); // ungrab keys // free color scheme - for (i = 0; i < SchemeLast; i++) + for (i = 0; i < LENGTH(colors) + 1; i++) free(scheme[i]); // free high priority items