From 5705e8b3cc6378d8f8c83f381830922a1ba3797c Mon Sep 17 00:00:00 2001 From: Merith-TK Date: Mon, 10 Mar 2025 09:37:28 -0700 Subject: [PATCH] it compiles, but doesnt do anything else Suspect due to pywal using hexcodes while st uses colornames, --- .gitignore | 4 ++-- Makefile | 2 +- colors.c | 39 +++++++++++++++++++++++++++++++++++++++ colors.h | 2 ++ config.def.h | 2 +- st.c | 1 + x.c | 2 ++ 7 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 colors.c create mode 100644 colors.h diff --git a/.gitignore b/.gitignore index 39a6daf..8002050 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -st.o + st -x.o config.h +*.o *.orig *.rej \ No newline at end of file diff --git a/Makefile b/Makefile index 15db421..69da496 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ include config.mk -SRC = st.c x.c +SRC = st.c x.c colors.c OBJ = $(SRC:.c=.o) all: st diff --git a/colors.c b/colors.c new file mode 100644 index 0000000..d1ef77f --- /dev/null +++ b/colors.c @@ -0,0 +1,39 @@ +#include +#include +#include + +// Declare the colorname array (defined in config.h) +extern char *colorname[]; + +void colorpywal() { + const char *home_dir = getenv("HOME"); + if (home_dir == NULL) { + fprintf(stderr, "Error: Could not determine home directory.\n"); + return; + } else { + fprintf(stdout, "Debug: Found Home Directory.\n"); + } + + // Construct the path to the Pywal colors file + char pywal_colors_path[256]; + snprintf(pywal_colors_path, sizeof(pywal_colors_path), "%s/.cache/wal/colors", home_dir); + fprintf(stdout, "Debug: PyWal Path: %s", pywal_colors_path); + FILE *fp = fopen(pywal_colors_path, "r"); + if (fp == NULL) { + // Pywal colors file not found, do nothing + return; + } + + char line[256]; + int i = 0; + + // Read colors from the file and update the colorname array + while (fgets(line, sizeof(line), fp) != NULL && i < 16) { + line[strcspn(line, "\n")] = 0; // Remove newline character + colorname[i] = strdup(line); // Duplicate the color string + i++; + } + + // Clean up + fclose(fp); +} \ No newline at end of file diff --git a/colors.h b/colors.h new file mode 100644 index 0000000..9d13440 --- /dev/null +++ b/colors.h @@ -0,0 +1,2 @@ + +void colorpywal(void); \ No newline at end of file diff --git a/config.def.h b/config.def.h index 84929f3..6b95ec7 100644 --- a/config.def.h +++ b/config.def.h @@ -97,7 +97,7 @@ unsigned int tabspaces = 8; float alpha = 0.8; /* Terminal colors (16 first used in escape sequence) */ -static const char *colorname[] = { +char *colorname[] = { /* 8 normal colors */ "black", "red3", diff --git a/st.c b/st.c index f17abbc..bc01391 100644 --- a/st.c +++ b/st.c @@ -1360,6 +1360,7 @@ tdeleteline(int n) tscrollup(term.c.y, n, 0); } + int32_t tdefcolor(const int *attr, int *npar, int l) { diff --git a/x.c b/x.c index ecbbbd1..c96f78c 100644 --- a/x.c +++ b/x.c @@ -17,6 +17,7 @@ char *argv0; #include "arg.h" +#include "colors.h" #include "st.h" #include "win.h" @@ -771,6 +772,7 @@ sixd_to_16bit(int x) int xloadcolor(int i, const char *name, Color *ncolor) { + colorpywal(); XRenderColor color = { .alpha = 0xffff }; if (!name) {