commit f0b5e0d40c2637290bad4936b44ddb2c1f841527
parent 99d3a18f9916c484c4f046c0fef881c3c1e6d3f4
Author: ssnf <ssnf@ssnf.xyz>
Date: Fri, 25 Nov 2022 12:54:56 +0000
focus patch
Diffstat:
4 files changed, 23 insertions(+), 10 deletions(-)
diff --git a/config.h b/config.h
@@ -6,7 +6,7 @@
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
static char *font = "monospace:pixelsize=12:antialias=true:autohint=true";
-static int borderpx = 2;
+static int borderpx = 3;
/*
* What program is execed by st depends of these precedence rules:
@@ -95,6 +95,7 @@ unsigned int tabspaces = 8;
/* bg opacity */
float alpha = 0.85;
+float alphaUnfocused = 0.65;
/* Terminal colors (16 first used in escape sequence) */
static const char *colorname[] = {
diff --git a/st.c b/st.c
@@ -194,7 +194,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
@@ -79,6 +79,7 @@ typedef union {
void die(const char *, ...);
void redraw(void);
+void tfulldirt(void);
void draw(void);
void printscreen(const Arg *);
@@ -125,3 +126,4 @@ extern unsigned int defaultfg;
extern unsigned int defaultbg;
extern unsigned int defaultcs;
extern float alpha;
+extern float alphaUnfocused;
diff --git a/x.c b/x.c
@@ -256,6 +256,8 @@ static char *opt_title = NULL;
static uint buttons; /* bit field of pressed buttons */
+static int focused = 0;
+
void
clipcopy(const Arg *dummy)
{
@@ -795,6 +797,7 @@ xloadcolor(int i, const char *name, Color *ncolor)
void
xloadcols(void)
{
+ float a;
int i;
static int loaded;
Color *cp;
@@ -806,21 +809,19 @@ xloadcols(void)
dc.collen = MAX(LEN(colorname), 256);
dc.col = xmalloc(dc.collen * sizeof(Color));
}
-
- for (i = 0; i < dc.collen; i++)
+ 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]);
else
die("could not allocate color %d\n", i);
}
-
- /* set alpha value of bg color */
if (opt_alpha)
alpha = strtof(opt_alpha, NULL);
- dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
- dc.col[defaultbg].pixel &= 0x00FFFFFF;
- dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
+ a = focused ? alpha : alphaUnfocused;
+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * a);
+ dc.col[defaultbg].pixel &= 0x00ffffff;
+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * a) << 24;
loaded = 1;
}
@@ -1794,12 +1795,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();
+ }
}
}
@@ -1821,7 +1832,7 @@ kmap(KeySym k, uint state)
break;
}
if (i == LEN(mappedkeys)) {
- if ((k & 0xFFFF) < 0xFD00)
+ if ((k & 0xffff) < 0xFD00)
return NULL;
}