summaryrefslogtreecommitdiffhomepage
path: root/patch
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2020-02-11 18:31:11 +0100
committerbakkeby <[email protected]>2020-02-11 18:31:11 +0100
commit4b45c6071f8e960d85dfa83e610b47e1971cfb87 (patch)
treeb9dfb1eb4996ff608e788bf37e008d309c4ad5d9 /patch
parent9ef44a0bc1462bca87226f31d6d0c999465a86c2 (diff)
downloaddwm-flexipatch-4b45c6071f8e960d85dfa83e610b47e1971cfb87.tar.gz
dwm-flexipatch-4b45c6071f8e960d85dfa83e610b47e1971cfb87.zip
Adding vtcolors patch
Diffstat (limited to 'patch')
-rw-r--r--patch/include.c5
-rw-r--r--patch/include.h5
-rw-r--r--patch/vtcolors.c70
-rw-r--r--patch/vtcolors.h2
4 files changed, 80 insertions, 2 deletions
diff --git a/patch/include.c b/patch/include.c
index 4ed46cd..80be7d0 100644
--- a/patch/include.c
+++ b/patch/include.c
@@ -146,6 +146,9 @@
#if VANITYGAPS_PATCH
#include "vanitygaps.c"
#endif
+#if VTCOLORS_PATCH
+#include "vtcolors.c"
+#endif
#if WARP_PATCH
#include "warp.c"
#endif
@@ -155,7 +158,7 @@
#if ZOOMSWAP_PATCH
#include "zoomswap.c"
#endif
-#if XRDB_PATCH
+#if XRDB_PATCH && !VTCOLORS_PATCH
#include "xrdb.c"
#endif
/* Layouts */
diff --git a/patch/include.h b/patch/include.h
index ba906a5..dd36e37 100644
--- a/patch/include.h
+++ b/patch/include.h
@@ -146,6 +146,9 @@
#if VANITYGAPS_PATCH
#include "vanitygaps.h"
#endif
+#if VTCOLORS_PATCH
+#include "vtcolors.h"
+#endif
#if WARP_PATCH
#include "warp.h"
#endif
@@ -155,7 +158,7 @@
#if ZOOMSWAP_PATCH
#include "zoomswap.h"
#endif
-#if XRDB_PATCH
+#if XRDB_PATCH && !VTCOLORS_PATCH
#include "xrdb.h"
#endif
/* Layouts */
diff --git a/patch/vtcolors.c b/patch/vtcolors.c
new file mode 100644
index 0000000..349970f
--- /dev/null
+++ b/patch/vtcolors.c
@@ -0,0 +1,70 @@
+void
+get_vt_colors(void)
+{
+ char *cfs[3] = {
+ "/sys/module/vt/parameters/default_red",
+ "/sys/module/vt/parameters/default_grn",
+ "/sys/module/vt/parameters/default_blu",
+ };
+ char vtcs[16][8];
+ char tk[] = ",";
+ char cl[64];
+ char *tp = NULL;
+ FILE *fp;
+ size_t r;
+ int i, c, n;
+
+ for (i = 0; i < 16; i++)
+ strcpy(vtcs[i], "#000000");
+
+ for (i = 0, r = 0; i < 3; i++) {
+ if ((fp = fopen(cfs[i], "r")) == NULL)
+ continue;
+ while ((cl[r] = fgetc(fp)) != EOF && cl[r] != '\n')
+ r++;
+ cl[r] = '\0';
+ for (c = 0, tp = cl, n = 0; c < 16; c++, tp++) {
+ if ((r = strcspn(tp, tk)) == -1)
+ break;
+ for (n = 0; r && *tp >= 48 && *tp < 58; r--, tp++)
+ n = n * 10 - 48 + *tp;
+ vtcs[c][i * 2 + 1] = n / 16 < 10 ? n / 16 + 48 : n / 16 + 87;
+ vtcs[c][i * 2 + 2] = n % 16 < 10 ? n % 16 + 48 : n % 16 + 87;
+ }
+ fclose(fp);
+ }
+ for (i = 0; i < LENGTH(colors); i++) {
+ #if FLOAT_BORDER_COLOR_PATCH
+ for (c = 0; c < 4; c++)
+ #else
+ for (c = 0; c < 3; c++)
+ #endif // FLOAT_BORDER_COLOR_PATCH
+ {
+ n = color_ptrs[i][c];
+ if (n > -1 && strlen(colors[i][c]) >= strlen(vtcs[n]))
+ memcpy(colors[i][c], vtcs[n], 7);
+ }
+ }
+}
+
+int get_luminance(char *r)
+{
+ char *c = r;
+ int n[3] = {0};
+ int i = 0;
+
+ while (*c) {
+ if (*c >= 48 && *c < 58)
+ n[i / 2] = n[i / 2] * 16 - 48 + *c;
+ else if (*c >= 65 && *c < 71)
+ n[i / 2] = n[i / 2] * 16 - 55 + *c;
+ else if (*c >= 97 && *c < 103)
+ n[i / 2] = n[i / 2] * 16 - 87 + *c;
+ else
+ i--;
+ i++;
+ c++;
+ }
+
+ return (0.299 * n[0] + 0.587 * n[1] + 0.114 * n[2]) / 2.55;
+} \ No newline at end of file
diff --git a/patch/vtcolors.h b/patch/vtcolors.h
new file mode 100644
index 0000000..7341e6a
--- /dev/null
+++ b/patch/vtcolors.h
@@ -0,0 +1,2 @@
+static void get_vt_colors(void);
+static int get_luminance(char *rgb); \ No newline at end of file