st-noxz

[fork] suckless st - personal fork
git clone https://noxz.tech/git/st-noxz.git
st-noxz

commit: da95370761134e74f4fed968d9871dc1e4c73c24
parent: b8341f262bf21c9436dd87476b3b03fcd6a349e4
author: Chris Noxz <chris@noxz.tech>
date:   Sun, 19 May 2024 15:52:38 +0200
replace color inversion with focused background
Mconfig.def.h78++++++++++----------
Mst.c1-
Mst.h1+
Mx.c44++++-------
4 files changed, 55 insertions(+), 69 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -136,10 +136,11 @@ static const char *colorname[] = {
 	[255] = 0,
 
 	/* more colors can be added after 255 to use with DefaultXX */
-	"#000000",
 	"#ffffff",
 	"#ffffff",
 	"#000000",
+	"#000000",
+	"#000000",
 };
 
 
@@ -147,10 +148,11 @@ static const char *colorname[] = {
  * Default colors (colorname index)
  * foreground, background, cursor, reverse cursor
  */
-unsigned int defaultbg = 256;
-unsigned int defaultfg = 257;
-unsigned int defaultcs = 258;
-static unsigned int defaultrcs = 259;
+unsigned int defaultbg          = 259;
+unsigned int defaultbgu         = 260;
+unsigned int defaultfg          = 258;
+unsigned int defaultcs          = 256;
+static unsigned int defaultrcs  = 257;
 
 /*
  * Default shape of cursor
@@ -190,38 +192,39 @@ static uint forcemousemod = ShiftMask;
  * Xresources preferences to load at startup
  */
 ResourcePref resources[] = {
-		{ "font",         STRING,  &font },
-		{ "color0",       STRING,  &colorname[0] },
-		{ "color1",       STRING,  &colorname[1] },
-		{ "color2",       STRING,  &colorname[2] },
-		{ "color3",       STRING,  &colorname[3] },
-		{ "color4",       STRING,  &colorname[4] },
-		{ "color5",       STRING,  &colorname[5] },
-		{ "color6",       STRING,  &colorname[6] },
-		{ "color7",       STRING,  &colorname[7] },
-		{ "color8",       STRING,  &colorname[8] },
-		{ "color9",       STRING,  &colorname[9] },
-		{ "color10",      STRING,  &colorname[10] },
-		{ "color11",      STRING,  &colorname[11] },
-		{ "color12",      STRING,  &colorname[12] },
-		{ "color13",      STRING,  &colorname[13] },
-		{ "color14",      STRING,  &colorname[14] },
-		{ "color15",      STRING,  &colorname[15] },
-		{ "background",   STRING,  &colorname[256] },
-		{ "foreground",   STRING,  &colorname[257] },
-		{ "cursorColor",  STRING,  &colorname[258] },
-		{ "rcursorColor", STRING,  &colorname[259] },
-		{ "termname",     STRING,  &termname },
-		{ "shell",        STRING,  &shell },
-		{ "minlatency",   INTEGER, &minlatency },
-		{ "maxlatency",   INTEGER, &maxlatency },
-		{ "blinktimeout", INTEGER, &blinktimeout },
-		{ "bellvolume",   INTEGER, &bellvolume },
-		{ "tabspaces",    INTEGER, &tabspaces },
-		{ "borderpx",     INTEGER, &borderpx },
-		{ "boldisbright", INTEGER, &boldisbright },
-		{ "cwscale",      FLOAT,   &cwscale },
-		{ "chscale",      FLOAT,   &chscale },
+		{ "font",                   STRING,  &font },
+		{ "color0",                 STRING,  &colorname[0] },
+		{ "color1",                 STRING,  &colorname[1] },
+		{ "color2",                 STRING,  &colorname[2] },
+		{ "color3",                 STRING,  &colorname[3] },
+		{ "color4",                 STRING,  &colorname[4] },
+		{ "color5",                 STRING,  &colorname[5] },
+		{ "color6",                 STRING,  &colorname[6] },
+		{ "color7",                 STRING,  &colorname[7] },
+		{ "color8",                 STRING,  &colorname[8] },
+		{ "color9",                 STRING,  &colorname[9] },
+		{ "color10",                STRING,  &colorname[10] },
+		{ "color11",                STRING,  &colorname[11] },
+		{ "color12",                STRING,  &colorname[12] },
+		{ "color13",                STRING,  &colorname[13] },
+		{ "color14",                STRING,  &colorname[14] },
+		{ "color15",                STRING,  &colorname[15] },
+		{ "background",             STRING,  &colorname[259] },
+		{ "backgroundUnfocused",    STRING,  &colorname[260] },
+		{ "foreground",             STRING,  &colorname[258] },
+		{ "cursorColor",            STRING,  &colorname[256] },
+		{ "rcursorColor",           STRING,  &colorname[257] },
+		{ "termname",               STRING,  &termname },
+		{ "shell",                  STRING,  &shell },
+		{ "minlatency",             INTEGER, &minlatency },
+		{ "maxlatency",             INTEGER, &maxlatency },
+		{ "blinktimeout",           INTEGER, &blinktimeout },
+		{ "bellvolume",             INTEGER, &bellvolume },
+		{ "tabspaces",              INTEGER, &tabspaces },
+		{ "borderpx",               INTEGER, &borderpx },
+		{ "boldisbright",           INTEGER, &boldisbright },
+		{ "cwscale",                FLOAT,   &cwscale },
+		{ "chscale",                FLOAT,   &chscale },
 };
 
 /*
@@ -261,7 +264,6 @@ static Shortcut shortcuts[] = {
 
 	/* misc */
 	{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
-	{ TERMMOD,              XK_I,           invert,         {.i =  0} },
 };
 
 /*
diff --git a/st.c b/st.c
@@ -197,7 +197,6 @@ static void tsetscroll(int, int);
 static void tswapscreen(void);
 static void tsetmode(int, int, const int *, int);
 static int twrite(const char *, int, int);
-static void tfulldirt(void);
 static void tcontrolcode(uchar );
 static void tdectest(char );
 static void tdefutf8(char);
diff --git a/st.h b/st.h
@@ -90,6 +90,7 @@ typedef union {
 void die(const char *, ...);
 void redraw(void);
 void draw(void);
+void tfulldirt(void);
 
 void printscreen(const Arg *);
 void printsel(const Arg *);
diff --git a/x.c b/x.c
@@ -81,7 +81,6 @@ 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. */
@@ -279,7 +278,7 @@ static char *opt_title = NULL;
 
 static uint buttons; /* bit field of pressed buttons */
 
-static int invertcolors = 0;
+static int focused = 0;
 static int oldbutton = 3; /* button event on startup: 3 = release */
 
 void
@@ -350,36 +349,11 @@ 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];
+	if (i == defaultbg)
+		return !focused ? colorname[defaultbgu] : colorname[i];
+	return colorname[i];
 }
 
 void
@@ -2239,12 +2213,22 @@ focus(XEvent *ev)
 		xseturgency(0);
 		if (IS_SET(MODE_FOCUS))
 			ttywrite("\033[I", 3, 0);
+		if (!focused) {
+			focused = 1;
+			xloadcols();
+			tfulldirt();
+		}
 	} else {
 		if (xw.ime.xic)
 			XUnsetICFocus(xw.ime.xic);
 		win.mode &= ~MODE_FOCUSED;
 		if (IS_SET(MODE_FOCUS))
 			ttywrite("\033[O", 3, 0);
+		if (focused) {
+			focused = 0;
+			xloadcols();
+			tfulldirt();
+		}
 	}
 }