sites

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

st-alpha-0.5.diff (5066B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 58b470e..ce34f55 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -48,6 +48,8 @@ static char termname[] = "st-256color";
      6  
      7  static unsigned int tabspaces = 8;
      8  
      9 +/* background opacity */
     10 +static const int alpha = 0xdd;
     11  
     12  /* Terminal colors (16 first used in escape sequence) */
     13  static const char *colorname[] = {
     14 @@ -75,6 +77,7 @@ static const char *colorname[] = {
     15  
     16  	/* more colors can be added after 255 to use with DefaultXX */
     17  	"#cccccc",
     18 +	"black",
     19  };
     20  
     21  
     22 @@ -83,7 +86,7 @@ static const char *colorname[] = {
     23   * foreground, background, cursor
     24   */
     25  static unsigned int defaultfg = 7;
     26 -static unsigned int defaultbg = 0;
     27 +static unsigned int defaultbg = 257;
     28  static unsigned int defaultcs = 256;
     29  
     30  /*
     31 diff --git a/config.mk b/config.mk
     32 index 97afa2c..18aec14 100644
     33 --- a/config.mk
     34 +++ b/config.mk
     35 @@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
     36  INCS = -I. -I/usr/include -I${X11INC} \
     37         `pkg-config --cflags fontconfig` \
     38         `pkg-config --cflags freetype2`
     39 -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext -lXft \
     40 +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext -lXft -lXrender \
     41         `pkg-config --libs fontconfig`  \
     42         `pkg-config --libs freetype2`
     43  
     44 diff --git a/st.c b/st.c
     45 index 392f12d..5b05a5f 100644
     46 --- a/st.c
     47 +++ b/st.c
     48 @@ -65,6 +65,7 @@ char *argv0;
     49  #define XK_ANY_MOD    UINT_MAX
     50  #define XK_NO_MOD     0
     51  #define XK_SWITCH_MOD (1<<13)
     52 +#define OPAQUE 0Xff
     53  
     54  #define REDRAW_TIMEOUT (80*1000) /* 80 ms */
     55  
     56 @@ -79,6 +80,7 @@ char *argv0;
     57  #define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg)
     58  #define IS_SET(flag) ((term.mode & (flag)) != 0)
     59  #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_usec-t2.tv_usec)/1000)
     60 +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
     61  #define CEIL(x) (((x) != (int) (x)) ? (x) + 1 : (x))
     62  
     63  #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b))
     64 @@ -255,6 +257,7 @@ typedef struct {
     65  	int w, h; /* window width and height */
     66  	int ch; /* char height */
     67  	int cw; /* char width  */
     68 +	int depth; /* bit depth */
     69  	char state; /* focus, redraw, visible */
     70  } XWindow;
     71  
     72 @@ -2706,8 +2709,7 @@ xresize(int col, int row) {
     73  	xw.th = MAX(1, row * xw.ch);
     74  
     75  	XFreePixmap(xw.dpy, xw.buf);
     76 -	xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
     77 -			DefaultDepth(xw.dpy, xw.scr));
     78 +	xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, xw.depth);
     79  	XftDrawChange(xw.draw, xw.buf);
     80  	xclear(0, 0, xw.w, xw.h);
     81  }
     82 @@ -2738,6 +2740,13 @@ xloadcols(void) {
     83  		}
     84  	}
     85  
     86 +	/* set alpha value of bg color */
     87 +	if (USE_ARGB) {
     88 +		dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE; //0xcccc;
     89 +		dc.col[defaultbg].pixel &= 0x00111111;
     90 +		dc.col[defaultbg].pixel |= alpha << 24; // 0xcc000000;
     91 +	}
     92 +
     93  	/* load colors [16-255] ; same colors as xterm */
     94  	for(i = 16, r = 0; r < 6; r++) {
     95  		for(g = 0; g < 6; g++) {
     96 @@ -2992,7 +3001,38 @@ xinit(void) {
     97  	if(!(xw.dpy = XOpenDisplay(NULL)))
     98  		die("Can't open display\n");
     99  	xw.scr = XDefaultScreen(xw.dpy);
    100 -	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    101 +	xw.depth = (USE_ARGB)? 32: XDefaultDepth(xw.dpy, xw.scr);
    102 +	if (! USE_ARGB)
    103 +		xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    104 +	else {
    105 +		XVisualInfo *vis;
    106 +		XRenderPictFormat *fmt;
    107 +		int nvi;
    108 +		int i;
    109 +
    110 +		XVisualInfo tpl = {
    111 +			.screen = xw.scr,
    112 +			.depth = 32,
    113 +			.class = TrueColor
    114 +		};
    115 +
    116 +		vis = XGetVisualInfo(xw.dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi);
    117 +		xw.vis = NULL;
    118 +		for(i = 0; i < nvi; i ++) {
    119 +			fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
    120 +			if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
    121 +				xw.vis = vis[i].visual;
    122 +				break;
    123 +			}
    124 +		}
    125 +
    126 +		XFree(vis);
    127 +
    128 +		if (! xw.vis) {
    129 +			fprintf(stderr, "Couldn't find ARGB visual.\n");
    130 +			exit(1);
    131 +		}
    132 +	}
    133  
    134  	/* font */
    135  	if(!FcInit())
    136 @@ -3002,7 +3042,10 @@ xinit(void) {
    137  	xloadfonts(usedfont, 0);
    138  
    139  	/* colors */
    140 -	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    141 +	if (! USE_ARGB)
    142 +		xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    143 +	else
    144 +		xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr), xw.vis, None);
    145  	xloadcols();
    146  
    147  	/* adjust fixed window geometry */
    148 @@ -3036,16 +3079,17 @@ xinit(void) {
    149  	parent = opt_embed ? strtol(opt_embed, NULL, 0) : \
    150  			XRootWindow(xw.dpy, xw.scr);
    151  	xw.win = XCreateWindow(xw.dpy, parent, xw.fx, xw.fy,
    152 -			xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
    153 +			xw.w, xw.h, 0, xw.depth, InputOutput,
    154  			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
    155  			| CWEventMask | CWColormap, &xw.attrs);
    156  
    157  	memset(&gcvalues, 0, sizeof(gcvalues));
    158  	gcvalues.graphics_exposures = False;
    159 -	dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
    160 +	xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, xw.depth);
    161 +	dc.gc = XCreateGC(xw.dpy,
    162 +			(USE_ARGB)? xw.buf: parent,
    163 +			GCGraphicsExposures,
    164  			&gcvalues);
    165 -	xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h,
    166 -			DefaultDepth(xw.dpy, xw.scr));
    167  	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    168  	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h);
    169