sites

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

st-alpha-osc11-20220222-0.8.5.diff (4135B)


      1 From f4c164a63fc34c9989af15db3c10e6b658586804 Mon Sep 17 00:00:00 2001
      2 From: Santtu Lakkala <inz@inz.fi>
      3 Date: Wed, 16 Feb 2022 21:23:44 +0200
      4 Subject: [PATCH] Alpha background
      5 
      6 Building on previous patches, but also apply alpha to the OSC 11, set
      7 background, sequence.
      8 ---
      9  config.def.h |  3 +++
     10  x.c          | 43 +++++++++++++++++++++++++++++++++----------
     11  2 files changed, 36 insertions(+), 10 deletions(-)
     12 
     13 diff --git a/config.def.h b/config.def.h
     14 index 91ab8ca..6af616e 100644
     15 --- a/config.def.h
     16 +++ b/config.def.h
     17 @@ -93,6 +93,9 @@ char *termname = "st-256color";
     18   */
     19  unsigned int tabspaces = 8;
     20  
     21 +/* bg opacity */
     22 +float alpha = 0.8;
     23 +
     24  /* Terminal colors (16 first used in escape sequence) */
     25  static const char *colorname[] = {
     26  	/* 8 normal colors */
     27 diff --git a/x.c b/x.c
     28 index 8a16faa..812af66 100644
     29 --- a/x.c
     30 +++ b/x.c
     31 @@ -105,6 +105,7 @@ typedef struct {
     32  	XSetWindowAttributes attrs;
     33  	int scr;
     34  	int isfixed; /* is fixed geometry? */
     35 +	int depth; /* bit depth */
     36  	int l, t; /* left and top offset */
     37  	int gm; /* geometry mask */
     38  } XWindow;
     39 @@ -736,7 +737,7 @@ xresize(int col, int row)
     40  
     41  	XFreePixmap(xw.dpy, xw.buf);
     42  	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
     43 -			DefaultDepth(xw.dpy, xw.scr));
     44 +			xw.depth);
     45  	XftDrawChange(xw.draw, xw.buf);
     46  	xclear(0, 0, win.w, win.h);
     47  
     48 @@ -796,6 +797,10 @@ xloadcols(void)
     49  			else
     50  				die("could not allocate color %d\n", i);
     51  		}
     52 +
     53 +	dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
     54 +	dc.col[defaultbg].pixel &= 0x00FFFFFF;
     55 +	dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
     56  	loaded = 1;
     57  }
     58  
     59 @@ -826,6 +831,12 @@ xsetcolorname(int x, const char *name)
     60  	XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]);
     61  	dc.col[x] = ncolor;
     62  
     63 +	if (x == defaultbg) {
     64 +		dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
     65 +		dc.col[defaultbg].pixel &= 0x00FFFFFF;
     66 +		dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
     67 +	}
     68 +
     69  	return 0;
     70  }
     71  
     72 @@ -1118,11 +1129,23 @@ xinit(int cols, int rows)
     73  	Window parent;
     74  	pid_t thispid = getpid();
     75  	XColor xmousefg, xmousebg;
     76 +	XWindowAttributes attr;
     77 +	XVisualInfo vis;
     78  
     79  	if (!(xw.dpy = XOpenDisplay(NULL)))
     80  		die("can't open display\n");
     81  	xw.scr = XDefaultScreen(xw.dpy);
     82 -	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
     83 +
     84 +	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
     85 +		parent = XRootWindow(xw.dpy, xw.scr);
     86 +		xw.depth = 32;
     87 +	} else {
     88 +		XGetWindowAttributes(xw.dpy, parent, &attr);
     89 +		xw.depth = attr.depth;
     90 +	}
     91 +
     92 +	XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
     93 +	xw.vis = vis.visual;
     94  
     95  	/* font */
     96  	if (!FcInit())
     97 @@ -1132,7 +1155,7 @@ xinit(int cols, int rows)
     98  	xloadfonts(usedfont, 0);
     99  
    100  	/* colors */
    101 -	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    102 +	xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
    103  	xloadcols();
    104  
    105  	/* adjust fixed window geometry */
    106 @@ -1152,19 +1175,15 @@ xinit(int cols, int rows)
    107  		| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
    108  	xw.attrs.colormap = xw.cmap;
    109  
    110 -	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
    111 -		parent = XRootWindow(xw.dpy, xw.scr);
    112  	xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
    113 -			win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
    114 +			win.w, win.h, 0, xw.depth, InputOutput,
    115  			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
    116  			| CWEventMask | CWColormap, &xw.attrs);
    117  
    118  	memset(&gcvalues, 0, sizeof(gcvalues));
    119  	gcvalues.graphics_exposures = False;
    120 -	dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
    121 -			&gcvalues);
    122 -	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
    123 -			DefaultDepth(xw.dpy, xw.scr));
    124 +	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
    125 +	dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
    126  	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    127  	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
    128  
    129 @@ -2019,6 +2038,10 @@ main(int argc, char *argv[])
    130  	case 'a':
    131  		allowaltscreen = 0;
    132  		break;
    133 +	case 'A':
    134 +		alpha = strtof(EARGF(usage()), NULL);
    135 +		LIMIT(alpha, 0.0, 1.0);
    136 +		break;
    137  	case 'c':
    138  		opt_class = EARGF(usage());
    139  		break;
    140 -- 
    141 2.32.0
    142