st-alpha-0.6.diff (5062B)
1 diff --git a/config.def.h b/config.def.h 2 index 64e75b8..9a27c14 100644 3 --- a/config.def.h 4 +++ b/config.def.h 5 @@ -58,6 +58,8 @@ static char termname[] = "st-256color"; 6 7 static unsigned int tabspaces = 8; 8 9 +/* bg opacity */ 10 +static const int alpha = 0xdd; 11 12 /* Terminal colors (16 first used in escape sequence) */ 13 static const char *colorname[] = { 14 @@ -85,6 +87,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 @@ -93,7 +96,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 67844dc..005b1c6 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} -lm -lrt -lX11 -lutil -lXext -lXft \ 40 +LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -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 b89d094..d212134 100644 46 --- a/st.c 47 +++ b/st.c 48 @@ -61,6 +61,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 /* macros */ 55 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 56 @@ -77,6 +78,7 @@ char *argv0; 57 #define IS_SET(flag) ((term.mode & (flag)) != 0) 58 #define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_nsec-t2.tv_nsec)/1E6) 59 #define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) 60 +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL) 61 62 #define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) 63 #define IS_TRUECOL(x) (1 << 24 & (x)) 64 @@ -265,6 +267,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 int cursor; /* cursor style */ 71 } XWindow; 72 @@ -2895,8 +2898,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 @@ -2946,6 +2948,14 @@ xloadcols(void) { 83 else 84 die("Could not allocate color %d\n", i); 85 } 86 + 87 + /* set alpha value of bg color */ 88 + if (USE_ARGB) { 89 + dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE; //0xcccc; 90 + dc.col[defaultbg].pixel &= 0x00111111; 91 + dc.col[defaultbg].pixel |= alpha << 24; // 0xcc000000; 92 + } 93 + 94 loaded = true; 95 } 96 97 @@ -3189,7 +3199,38 @@ xinit(void) { 98 if(!(xw.dpy = XOpenDisplay(NULL))) 99 die("Can't open display\n"); 100 xw.scr = XDefaultScreen(xw.dpy); 101 - xw.vis = XDefaultVisual(xw.dpy, xw.scr); 102 + xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr); 103 + if (! USE_ARGB) 104 + xw.vis = XDefaultVisual(xw.dpy, xw.scr); 105 + else { 106 + XVisualInfo *vis; 107 + XRenderPictFormat *fmt; 108 + int nvi; 109 + int i; 110 + 111 + XVisualInfo tpl = { 112 + .screen = xw.scr, 113 + .depth = 32, 114 + .class = TrueColor 115 + }; 116 + 117 + vis = XGetVisualInfo(xw.dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &tpl, &nvi); 118 + xw.vis = NULL; 119 + for(i = 0; i < nvi; i ++) { 120 + fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual); 121 + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) { 122 + xw.vis = vis[i].visual; 123 + break; 124 + } 125 + } 126 + 127 + XFree(vis); 128 + 129 + if (! xw.vis) { 130 + fprintf(stderr, "Couldn't find ARGB visual.\n"); 131 + exit(1); 132 + } 133 + } 134 135 /* font */ 136 if(!FcInit()) 137 @@ -3199,7 +3240,10 @@ xinit(void) { 138 xloadfonts(usedfont, 0); 139 140 /* colors */ 141 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr); 142 + if (! USE_ARGB) 143 + xw.cmap = XDefaultColormap(xw.dpy, xw.scr); 144 + else 145 + xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr), xw.vis, None); 146 xloadcols(); 147 148 /* adjust fixed window geometry */ 149 @@ -3222,16 +3266,17 @@ xinit(void) { 150 if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) 151 parent = XRootWindow(xw.dpy, xw.scr); 152 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t, 153 - xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput, 154 + xw.w, xw.h, 0, xw.depth, InputOutput, 155 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity 156 | CWEventMask | CWColormap, &xw.attrs); 157 158 memset(&gcvalues, 0, sizeof(gcvalues)); 159 gcvalues.graphics_exposures = False; 160 - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures, 161 + xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, xw.depth); 162 + dc.gc = XCreateGC(xw.dpy, 163 + (USE_ARGB)? xw.buf: parent, 164 + GCGraphicsExposures, 165 &gcvalues); 166 - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.h, 167 - DefaultDepth(xw.dpy, xw.scr)); 168 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); 169 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, xw.w, xw.h); 170