sites

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

st-alpha-20171221-0ac685f.diff (5879B)


      1 From adc6b217669b30f4396e8a89f2a15b679d0e313e Mon Sep 17 00:00:00 2001
      2 From: fanboimsft <fanboimsft@icloud.com>
      3 Date: Thu, 21 Dec 2017 23:21:53 +0700
      4 Subject: [PATCH] alpha patch to latest git version
      5 
      6 ---
      7  config.def.h |  6 ++++-
      8  config.mk    |  4 ++--
      9  st.h         |  1 +
     10  win.h        |  4 ++++
     11  x.c          | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------
     12  5 files changed, 75 insertions(+), 11 deletions(-)
     13 
     14 diff --git a/config.def.h b/config.def.h
     15 index 877afab..0e423b1 100644
     16 --- a/config.def.h
     17 +++ b/config.def.h
     18 @@ -82,6 +82,9 @@ char termname[] = "st-256color";
     19   */
     20  static unsigned int tabspaces = 8;
     21  
     22 +/* bg opacity */
     23 +unsigned int alpha = 0xcc;
     24 +
     25  /* Terminal colors (16 first used in escape sequence) */
     26  const char *colorname[] = {
     27  	/* 8 normal colors */
     28 @@ -109,6 +112,7 @@ const char *colorname[] = {
     29  	/* more colors can be added after 255 to use with DefaultXX */
     30  	"#cccccc",
     31  	"#555555",
     32 +	"black",
     33  };
     34  
     35  
     36 @@ -117,7 +121,7 @@ const char *colorname[] = {
     37   * foreground, background, cursor, reverse cursor
     38   */
     39  unsigned int defaultfg = 7;
     40 -unsigned int defaultbg = 0;
     41 +unsigned int defaultbg = 257;
     42  unsigned int defaultcs = 256;
     43  unsigned int defaultrcs = 257;
     44  
     45 diff --git a/config.mk b/config.mk
     46 index 0aceec4..d2421f8 100644
     47 --- a/config.mk
     48 +++ b/config.mk
     49 @@ -11,10 +11,10 @@ X11INC = /usr/X11R6/include
     50  X11LIB = /usr/X11R6/lib
     51  
     52  # includes and libs
     53 -INCS = -I$(X11INC) \
     54 +INCS = -I. -I/usr/include -I${X11INC} \
     55         `pkg-config --cflags fontconfig` \
     56         `pkg-config --cflags freetype2`
     57 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
     58 +LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft -lXrender\
     59         `pkg-config --libs fontconfig` \
     60         `pkg-config --libs freetype2`
     61  
     62 diff --git a/st.h b/st.h
     63 index 44d4938..180fdba 100644
     64 --- a/st.h
     65 +++ b/st.h
     66 @@ -251,6 +251,7 @@ extern unsigned int blinktimeout;
     67  extern char termname[];
     68  extern const char *colorname[];
     69  extern size_t colornamelen;
     70 +extern unsigned int alpha;
     71  extern unsigned int defaultfg;
     72  extern unsigned int defaultbg;
     73  extern unsigned int defaultcs;
     74 diff --git a/win.h b/win.h
     75 index 428111c..05e8482 100644
     76 --- a/win.h
     77 +++ b/win.h
     78 @@ -5,6 +5,10 @@
     79  #define XK_NO_MOD     0
     80  #define XK_SWITCH_MOD (1<<13)
     81  
     82 +/* alpha */
     83 +#define OPAQUE 0Xff
     84 +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
     85 +
     86  typedef XftGlyphFontSpec GlyphFontSpec;
     87  
     88  void draw(void);
     89 diff --git a/x.c b/x.c
     90 index 191e5dc..0e12ab9 100644
     91 --- a/x.c
     92 +++ b/x.c
     93 @@ -49,6 +49,7 @@ typedef struct {
     94  	XSetWindowAttributes attrs;
     95  	int scr;
     96  	int isfixed; /* is fixed geometry? */
     97 +	int depth; /* bit depth */
     98  	int l, t; /* left and top offset */
     99  	int gm; /* geometry mask */
    100  } XWindow;
    101 @@ -562,7 +563,7 @@ xresize(int col, int row)
    102  
    103  	XFreePixmap(xw.dpy, xw.buf);
    104  	xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
    105 -			DefaultDepth(xw.dpy, xw.scr));
    106 +			xw.depth);
    107  	XftDrawChange(xw.draw, xw.buf);
    108  	xclear(0, 0, win.w, win.h);
    109  }
    110 @@ -619,6 +620,13 @@ xloadcols(void)
    111  			else
    112  				die("Could not allocate color %d\n", i);
    113  		}
    114 +
    115 +	/* set alpha value of bg color */
    116 +	if (USE_ARGB) {
    117 +		dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE;
    118 +		dc.col[defaultbg].pixel &= 0x00111111;
    119 +		dc.col[defaultbg].pixel |= alpha << 24;
    120 +	}
    121  	loaded = 1;
    122  }
    123  
    124 @@ -640,6 +648,17 @@ xsetcolorname(int x, const char *name)
    125  	return 0;
    126  }
    127  
    128 +void
    129 +xtermclear(int col1, int row1, int col2, int row2)
    130 +{
    131 +	XftDrawRect(xw.draw,
    132 +			&dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
    133 +			borderpx + col1 * win.cw,
    134 +			borderpx + row1 * win.ch,
    135 +			(col2-col1+1) * win.cw,
    136 +			(row2-row1+1) * win.ch);
    137 +}
    138 +
    139  /*
    140   * Absolute coordinates.
    141   */
    142 @@ -879,7 +898,40 @@ xinit(void)
    143  	if (!(xw.dpy = XOpenDisplay(NULL)))
    144  		die("Can't open display\n");
    145  	xw.scr = XDefaultScreen(xw.dpy);
    146 -	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    147 +	xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr);
    148 +	if (!USE_ARGB)
    149 +		xw.vis = XDefaultVisual(xw.dpy, xw.scr);
    150 +	else {
    151 +		XVisualInfo *vis;
    152 +		XRenderPictFormat *fmt;
    153 +		int nvi;
    154 +		int i;
    155 +
    156 +		XVisualInfo tpl = {
    157 +			.screen = xw.scr,
    158 +			.depth = 32,
    159 +			.class = TrueColor
    160 +		};
    161 +
    162 +		vis = XGetVisualInfo(xw.dpy,
    163 +				VisualScreenMask | VisualDepthMask | VisualClassMask,
    164 +				&tpl, &nvi);
    165 +		xw.vis = NULL;
    166 +		for (i = 0; i < nvi; i++) {
    167 +			fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
    168 +			if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
    169 +				xw.vis = vis[i].visual;
    170 +				break;
    171 +			}
    172 +		}
    173 +
    174 +		XFree(vis);
    175 +
    176 +		if (!xw.vis) {
    177 +			fprintf(stderr, "Couldn't find ARGB visual.\n");
    178 +			exit(1);
    179 +		}
    180 +	}
    181  
    182  	/* font */
    183  	if (!FcInit())
    184 @@ -889,7 +941,11 @@ xinit(void)
    185  	xloadfonts(usedfont, 0);
    186  
    187  	/* colors */
    188 -	xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    189 +	if (!USE_ARGB)
    190 +		xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
    191 +	else
    192 +		xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr),
    193 +				xw.vis, None);
    194  	xloadcols();
    195  
    196  	/* adjust fixed window geometry */
    197 @@ -912,16 +968,15 @@ xinit(void)
    198  	if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
    199  		parent = XRootWindow(xw.dpy, xw.scr);
    200  	xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
    201 -			win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
    202 +			win.w, win.h, 0, xw.depth, InputOutput,
    203  			xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
    204  			| CWEventMask | CWColormap, &xw.attrs);
    205  
    206  	memset(&gcvalues, 0, sizeof(gcvalues));
    207  	gcvalues.graphics_exposures = False;
    208 -	dc.gc = XCreateGC(xw.dpy, parent, 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, (USE_ARGB) ? xw.buf: parent,
    214 +			GCGraphicsExposures, &gcvalues);
    215  	XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
    216  	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
    217  
    218 -- 
    219 2.15.0
    220