st-noxz

[fork] suckless st - personal fork
git clone https://noxz.tech/git/st-noxz.git
Log | Files | README | LICENSE

commit: eb43d192d81c120f695108f2ddee277c5520e5ce
parent: 937005f3e97f29bc27dc82ef744cdd849397cb7a
author: Chris Noxz <chris@noxz.tech>
date:   Thu, 23 Sep 2021 20:28:26 +0200
add function to invert colors based on solarized themes
Mconfig.def.h5+++
Mx.c46+++++++++++++++++---
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -43,6 +43,9 @@ wchar_t *worddelimiters = L" ";
 static unsigned int doubleclicktimeout = 300;
 static unsigned int tripleclicktimeout = 600;
 
+/* render bold as bright */
+int boldisbright = 0;
+
 /* alt screens */
 int allowaltscreen = 1;
 
@@ -218,6 +221,7 @@ ResourcePref resources[] = {
 		{ "bellvolume",   INTEGER, &bellvolume },
 		{ "tabspaces",    INTEGER, &tabspaces },
 		{ "borderpx",     INTEGER, &borderpx },
+		{ "boldisbright", INTEGER, &boldisbright },
 		{ "cwscale",      FLOAT,   &cwscale },
 		{ "chscale",      FLOAT,   &chscale },
 };
@@ -259,6 +263,7 @@ static Shortcut shortcuts[] = {
 
 	/* misc */
 	{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
+	{ TERMMOD,              XK_I,           invert,         {.i =  0} },
 };
 
 /*
diff --git a/x.c b/x.c
@@ -72,6 +72,7 @@ static void selpaste(const Arg *);
 static void zoom(const Arg *);
 static void zoomabs(const Arg *);
 static void zoomreset(const Arg *);
+static void invert(const Arg *);
 static void ttysend(const Arg *);
 
 /* config.h for applying patches and the configuration. */
@@ -267,6 +268,7 @@ static char *opt_line  = NULL;
 static char *opt_name  = NULL;
 static char *opt_title = NULL;
 
+static int invertcolors = 0;
 static int oldbutton = 3; /* button event on startup: 3 = release */
 
 void
@@ -337,6 +339,38 @@ zoomreset(const Arg *arg)
 	}
 }
 
+void
+invert(const Arg *arg)
+{
+	invertcolors = !invertcolors;
+	xloadcols();
+	redraw();
+}
+
+const char* getcolorname(int i)
+{
+	/* inverts based on solarized theme */
+	return (invertcolors) ? colorname[
+		/* base 0/00 */
+		(i == 11) ? 12 :
+		(i == 12) ? 11 :
+		/* base 1/01 */
+		(i == 10) ? 14 :
+		(i == 14) ? 10 :
+		/* base 2/02 */
+		(i == 8) ? 7 :
+		(i == 7) ? 8 :
+		/* base 3/03 */
+		(i == 0) ? 15 :
+		(i == 15) ? 0 :
+		/* carrets */
+		(i == 256) ? 15 :
+		(i == 257) ? 8 :
+		(i == 258) ? 8 :
+		(i == 259) ? 15 :
+		i] : colorname[i];
+}
+
 void
 ttysend(const Arg *arg)
 {
@@ -781,7 +815,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
 			return XftColorAllocValue(xw.dpy, xw.vis,
 			                          xw.cmap, &color, ncolor);
 		} else
-			name = colorname[i];
+			name = getcolorname(i);
 	}
 
 	return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
@@ -816,8 +850,8 @@ xloadcols(void)
 
 	for (i = 0; i < dc.collen; i++)
 		if (!xloadcolor(i, NULL, &dc.col[i])) {
-			if (colorname[i])
-				die("could not allocate color '%s'\n", colorname[i]);
+			if (getcolorname(i))
+				die("could not allocate color '%s'\n", getcolorname(i));
 			else
 				die("could not allocate color %d\n", i);
 		}
@@ -1195,13 +1229,13 @@ xinit(int cols, int rows)
 	cursor = XCreateFontCursor(xw.dpy, mouseshape);
 	XDefineCursor(xw.dpy, xw.win, cursor);
 
-	if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) {
+	if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousefg), &xmousefg) == 0) {
 		xmousefg.red   = 0xffff;
 		xmousefg.green = 0xffff;
 		xmousefg.blue  = 0xffff;
 	}
 
-	if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) {
+	if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousebg), &xmousebg) == 0) {
 		xmousebg.red   = 0x0000;
 		xmousebg.green = 0x0000;
 		xmousebg.blue  = 0x0000;
@@ -1414,7 +1448,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
 	}
 
 	/* Change basic system colors [0-7] to bright system colors [8-15] */
-	if ((base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
+	if (boldisbright && (base.mode & ATTR_BOLD_FAINT) == ATTR_BOLD && BETWEEN(base.fg, 0, 7))
 		fg = &dc.col[base.fg + 8];
 
 	if (IS_SET(MODE_REVERSE)) {