sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

st-focus-0.9.3.diff (7428B)


      1 diff -up a/config.def.h b/config.def.h
      2 --- a/config.def.h	2025-08-09 10:00:58.350298234 -0300
      3 +++ b/config.def.h	2026-02-24 12:47:39.589730661 -0300
      4 @@ -93,6 +93,9 @@ char *termname = "st-256color";
      5   */
      6  unsigned int tabspaces = 8;
      7  
      8 +/* bg opacity */
      9 +float alpha = 0.93, alphaUnfocused = 0.6;
     10 +
     11  /* Terminal colors (16 first used in escape sequence) */
     12  static const char *colorname[] = {
     13  	/* 8 normal colors */
     14 @@ -120,8 +123,7 @@ static const char *colorname[] = {
     15  	/* more colors can be added after 255 to use with DefaultXX */
     16  	"#cccccc",
     17  	"#555555",
     18 -	"gray90", /* default foreground colour */
     19 -	"black", /* default background colour */
     20 +	"black",
     21  };
     22  
     23  
     24 @@ -129,10 +131,11 @@ static const char *colorname[] = {
     25   * Default colors (colorname index)
     26   * foreground, background, cursor, reverse cursor
     27   */
     28 -unsigned int defaultfg = 258;
     29 -unsigned int defaultbg = 259;
     30 +unsigned int defaultfg = 7;
     31 +unsigned int defaultbg = 0;
     32  unsigned int defaultcs = 256;
     33  static unsigned int defaultrcs = 257;
     34 +unsigned int bg = 0, bgUnfocused = 16;
     35  
     36  /*
     37   * Default shape of cursor
     38 diff -up a/config.mk b/config.mk
     39 --- a/config.mk	2025-08-09 10:00:58.350298234 -0300
     40 +++ b/config.mk	2026-02-24 12:47:39.580955347 -0300
     41 @@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
     42  INCS = -I$(X11INC) \
     43         `$(PKG_CONFIG) --cflags fontconfig` \
     44         `$(PKG_CONFIG) --cflags freetype2`
     45 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
     46 +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
     47         `$(PKG_CONFIG) --libs fontconfig` \
     48         `$(PKG_CONFIG) --libs freetype2`
     49  
     50 diff -up a/st.c b/st.c
     51 --- a/st.c	2025-08-09 10:00:58.350298234 -0300
     52 +++ b/st.c	2026-02-24 12:47:39.588067873 -0300
     53 @@ -194,7 +194,6 @@ static void tsetscroll(int, int);
     54  static void tswapscreen(void);
     55  static void tsetmode(int, int, const int *, int);
     56  static int twrite(const char *, int, int);
     57 -static void tfulldirt(void);
     58  static void tcontrolcode(uchar );
     59  static void tdectest(char );
     60  static void tdefutf8(char);
     61 diff -up a/st.h b/st.h
     62 --- a/st.h	2025-08-09 10:00:58.350298234 -0300
     63 +++ b/st.h	2026-02-24 12:47:39.588511996 -0300
     64 @@ -79,6 +79,7 @@ typedef union {
     65  
     66  void die(const char *, ...);
     67  void redraw(void);
     68 +void tfulldirt(void);
     69  void draw(void);
     70  
     71  void printscreen(const Arg *);
     72 @@ -124,3 +125,4 @@ extern unsigned int tabspaces;
     73  extern unsigned int defaultfg;
     74  extern unsigned int defaultbg;
     75  extern unsigned int defaultcs;
     76 +extern float alpha, alphaUnfocused;
     77 diff -up a/x.c b/x.c
     78 --- a/x.c	2025-08-09 10:00:58.350298234 -0300
     79 +++ b/x.c	2026-02-24 12:50:24.094826510 -0300
     80 @@ -105,6 +105,7 @@ typedef struct {
     81  	XSetWindowAttributes attrs;
     82  	int scr;
     83  	int isfixed; /* is fixed geometry? */
     84 +	int depth; /* bit depth */
     85  	int l, t; /* left and top offset */
     86  	int gm; /* geometry mask */
     87  } XWindow;
     88 @@ -243,6 +244,7 @@ static char *usedfont = NULL;
     89  static double usedfontsize = 0;
     90  static double defaultfontsize = 0;
     91  
     92 +static char *opt_alpha = NULL;
     93  static char *opt_class = NULL;
     94  static char **opt_cmd  = NULL;
     95  static char *opt_embed = NULL;
     96 @@ -253,6 +255,7 @@ static char *opt_name  = NULL;
     97  static char *opt_title = NULL;
     98  
     99  static uint buttons; /* bit field of pressed buttons */
    100 +static int focused = 0;
    101  
    102  void
    103  clipcopy(const Arg *dummy)
    104 @@ -752,7 +755,7 @@ xresize(int col, int row)
    105  
    106  	XFreePixmap(xw.dpy, xw.buf);
    107  	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
    108 -			DefaultDepth(xw.dpy, xw.scr));
    109 +			xw.depth);
    110  	XftDrawChange(xw.draw, xw.buf);
    111  	xclear(0, 0, win.w, win.h);
    112  
    113 @@ -791,27 +794,36 @@ xloadcolor(int i, const char *name, Colo
    114  }
    115  
    116  void
    117 +xloadalpha(void)
    118 +{
    119 +	xloadcolor(focused ?bg :bgUnfocused, NULL, &dc.col[defaultbg]);
    120 +	float const usedAlpha = focused ? alpha : alphaUnfocused;
    121 +	if (opt_alpha) alpha = strtof(opt_alpha, NULL);
    122 +	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * usedAlpha);
    123 +	dc.col[defaultbg].pixel &= 0x00FFFFFF;
    124 +	dc.col[defaultbg].pixel |= (unsigned char)(0xff * usedAlpha) << 24;
    125 +}
    126 +
    127 +void
    128  xloadcols(void)
    129  {
    130 -	int i;
    131  	static int loaded;
    132  	Color *cp;
    133  
    134 -	if (loaded) {
    135 -		for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp)
    136 -			XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
    137 -	} else {
    138 -		dc.collen = MAX(LEN(colorname), 256);
    139 -		dc.col = xmalloc(dc.collen * sizeof(Color));
    140 +	if (!loaded) {
    141 +		dc.collen = 1 + (defaultbg = MAX(LEN(colorname), 256));
    142 +		dc.col = xmalloc((dc.collen) * sizeof(Color));
    143  	}
    144  
    145 -	for (i = 0; i < dc.collen; i++)
    146 +	for (int i = 0; i+1 < dc.collen; ++i)
    147  		if (!xloadcolor(i, NULL, &dc.col[i])) {
    148  			if (colorname[i])
    149  				die("could not allocate color '%s'\n", colorname[i]);
    150  			else
    151  				die("could not allocate color %d\n", i);
    152  		}
    153 +
    154 +	xloadalpha();
    155  	loaded = 1;
    156  }
    157  
    158 @@ -1134,11 +1146,23 @@ xinit(int cols, int rows)
    159  	Window parent, root;
    160  	pid_t thispid = getpid();
    161  	XColor xmousefg, xmousebg;
    162 +	XWindowAttributes attr;
    163 +	XVisualInfo vis;
    164  
    165  	if (!(xw.dpy = XOpenDisplay(NULL)))
    166  		die("can't open display\n");
    167  	xw.scr = XDefaultScreen(xw.dpy);
    168 -	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    169 +
    170 +	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
    171 +		parent = XRootWindow(xw.dpy, xw.scr);
    172 +		xw.depth = 32;
    173 +	} else {
    174 +		XGetWindowAttributes(xw.dpy, parent, &attr);
    175 +		xw.depth = attr.depth;
    176 +	}
    177 +
    178 +	XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
    179 +	xw.vis = vis.visual;
    180  
    181  	/* font */
    182  	if (!FcInit())
    183 @@ -1148,7 +1172,7 @@ xinit(int cols, int rows)
    184  	xloadfonts(usedfont, 0);
    185  
    186  	/* colors */
    187 -	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    188 +	xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
    189  	xloadcols();
    190  
    191  	/* adjust fixed window geometry */
    192 @@ -1169,10 +1193,8 @@ xinit(int cols, int rows)
    193  	xw.attrs.colormap = xw.cmap;
    194  
    195  	root = XRootWindow(xw.dpy, xw.scr);
    196 -	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
    197 -		parent = root;
    198  	xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t,
    199 -			win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
    200 +			win.w, win.h, 0, xw.depth, InputOutput,
    201  			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
    202  			| CWEventMask | CWColormap, &xw.attrs);
    203  	if (parent != root)
    204 @@ -1180,10 +1202,8 @@ xinit(int cols, int rows)
    205  
    206  	memset(&gcvalues, 0, sizeof(gcvalues));
    207  	gcvalues.graphics_exposures = False;
    208 -	dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures,
    209 -			&gcvalues);
    210 -	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
    211 -			DefaultDepth(xw.dpy, xw.scr));
    212 +	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
    213 +	dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
    214  	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    215  	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
    216  
    217 @@ -1786,12 +1806,22 @@ focus(XEvent *ev)
    218  		xseturgency(0);
    219  		if (IS_SET(MODE_FOCUS))
    220  			ttywrite("\033[I", 3, 0);
    221 +		if (!focused) {
    222 +			focused = 1;
    223 +			xloadalpha();
    224 +			tfulldirt();
    225 +		}
    226  	} else {
    227  		if (xw.ime.xic)
    228  			XUnsetICFocus(xw.ime.xic);
    229  		win.mode &= ~MODE_FOCUSED;
    230  		if (IS_SET(MODE_FOCUS))
    231  			ttywrite("\033[O", 3, 0);
    232 +		if (focused) {
    233 +			focused = 0;
    234 +			xloadalpha();
    235 +			tfulldirt();
    236 +		}
    237  	}
    238  }
    239  
    240 @@ -2047,6 +2077,9 @@ main(int argc, char *argv[])
    241  	case 'a':
    242  		allowaltscreen = 0;
    243  		break;
    244 +	case 'A':
    245 +		opt_alpha = EARGF(usage());
    246 +		break;
    247  	case 'c':
    248  		opt_class = EARGF(usage());
    249  		break;
    250 @@ -2098,6 +2131,7 @@ run:
    251  	XSetLocaleModifiers("");
    252  	cols = MAX(cols, 1);
    253  	rows = MAX(rows, 1);
    254 +	defaultbg = MAX(LEN(colorname), 256);
    255  	tnew(cols, rows);
    256  	xinit(cols, rows);
    257  	xsetenv();