st-noxz

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

commit: ea4abdc72e2c7a14d4a71d57655b906427d20169
parent: 42fa95c93fbe56dc7f4f45e86146e1eb46d9e918
author: Chris Noxz <chris@noxz.tech>
date:   Mon, 20 May 2024 09:35:52 +0200
add enter/leave color for window
Mconfig.def.h3+++
Mx.c26++++++++++++++++++--
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -144,6 +144,7 @@ static const char *colorname[] = {
 	"#000000",
 	"#000000",
 	"#000000",
+	"#000000",
 };
 
 
@@ -153,6 +154,7 @@ static const char *colorname[] = {
  */
 unsigned int defaultbg          = 259;
 unsigned int defaultbgu         = 260;
+unsigned int defaultbgi         = 261;
 unsigned int defaultfg          = 258;
 unsigned int defaultcs          = 256;
 static unsigned int defaultrcs  = 257;
@@ -214,6 +216,7 @@ ResourcePref resources[] = {
 		{ "color15",                STRING,  &colorname[15] },
 		{ "background",             STRING,  &colorname[259] },
 		{ "backgroundUnfocused",    STRING,  &colorname[260] },
+		{ "backgroundEntered",      STRING,  &colorname[261] },
 		{ "foreground",             STRING,  &colorname[258] },
 		{ "cursorColor",            STRING,  &colorname[256] },
 		{ "rcursorColor",           STRING,  &colorname[257] },
diff --git a/x.c b/x.c
@@ -128,6 +128,7 @@ static void unmap(XEvent *);
 static void kpress(XEvent *);
 static void cmessage(XEvent *);
 static void resize(XEvent *);
+static void enter(XEvent *);
 static void focus(XEvent *);
 static uint buttonmask(uint);
 static int mouseaction(XEvent *, uint);
@@ -171,6 +172,9 @@ static void (*handler[LASTEvent])(XEvent *) = {
  */
 	[PropertyNotify] = propnotify,
 	[SelectionRequest] = selrequest,
+
+	[EnterNotify] = enter,
+	[LeaveNotify] = enter,
 };
 
 /* Globals */
@@ -214,6 +218,7 @@ static char *opt_title = NULL;
 static uint buttons; /* bit field of pressed buttons */
 
 static int focused = 0;
+static int entered = 0;
 static int oldbutton = 3; /* button event on startup: 3 = release */
 
 void
@@ -300,7 +305,9 @@ zoomreset(const Arg *arg)
 const char* getcolorname(int i)
 {
 	if (i == defaultbg)
-		return !focused ? colorname[defaultbgu] : colorname[i];
+		return focused ? colorname[i]
+		      : entered ? colorname[defaultbgi]
+		      : colorname[defaultbgu];
 	return colorname[i];
 }
 
@@ -1158,7 +1165,8 @@ xinit(int cols, int rows)
 	xw.attrs.bit_gravity = NorthWestGravity;
 	xw.attrs.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask
 		| ExposureMask | VisibilityChangeMask | StructureNotifyMask
-		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
+		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask
+		| EnterWindowMask | LeaveWindowMask;
 	xw.attrs.colormap = xw.cmap;
 
 	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
@@ -2248,6 +2256,20 @@ xbell(void)
 		XkbBell(xw.dpy, xw.win, bellvolume, (Atom)NULL);
 }
 
+void
+enter(XEvent *ev)
+{
+	if ((ev->type == EnterNotify) == entered)
+		return; /* would probably never happen */
+
+	entered = (ev->type == EnterNotify);
+
+	if (!focused) { /* do not update if focused */
+		xloadcols();
+		tfulldirt();
+	}
+}
+
 void
 focus(XEvent *ev)
 {