Actually the #if part was old code and is not needed.

Am Tue, 14 Sep 2010 20:03:38 +0200
schrieb Leon Winter <l...@ring0.de>:

> Hi,
> 
> just a proof of concept, no error-handling for non 32bit colordepth,
> requires composite manager like xcompmgr. I noticed this feature is
> not very popular so if you dont like the idea you better not apply the
> patch ;)
> 
> Edit ALPHA macro to change level of transparency (0x00 is invisible,
> 0xff is nontransparent).
> 
> Note: This patch will add real transparency to the background of the
> terminal while the foreground still remains with no transparency.
> 
> Diff against tip/148.
> 
> Regards,
> Leon Winter
diff -r 1cd0262c5b69 st.c
--- a/st.c	Sat Sep 11 16:07:36 2010 +0200
+++ b/st.c	Tue Sep 14 20:12:21 2010 +0200
@@ -222,6 +222,8 @@
 static Selection sel;
 static char *opt_cmd   = NULL;
 static char *opt_title = NULL;
+int bitdepth = 32;
+#define ALPHA 0xcc
 
 void
 selinit(void) {
@@ -1127,14 +1129,14 @@
 xloadcols(void) {
 	int i, r, g, b;
 	XColor color;
-	unsigned long white = WhitePixel(xw.dis, xw.scr);
+	unsigned long white = WhitePixel(xw.dis, xw.scr) & 0xffffff;
 
 	for(i = 0; i < 16; i++) {
 		if (!XAllocNamedColor(xw.dis, xw.cmap, colorname[i], &color, &color)) {
 			dc.col[i] = white;
 			fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
 		} else
-			dc.col[i] = color.pixel;
+			dc.col[i] = color.pixel & 0xffffff;
 	}
 
 	/* same colors as xterm */
@@ -1148,7 +1150,7 @@
 					dc.col[i] = white;
 					fprintf(stderr, "Could not allocate color %d\n", i);
 				} else
-					dc.col[i] = color.pixel;
+					dc.col[i] = color.pixel & 0xffffff;
 				i++;
 			}
 
@@ -1158,13 +1160,13 @@
 			dc.col[i] = white;
 			fprintf(stderr, "Could not allocate color %d\n", i);
 		} else
-			dc.col[i] = color.pixel;
+			dc.col[i] = color.pixel & 0xffffff;
 	}
 }
 
 void
 xclear(int x1, int y1, int x2, int y2) {
-	XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]);
+	XSetForeground(xw.dis, dc.gc, ALPHA << 24 | dc.col[DefaultBG]);
 	XFillRectangle(xw.dis, xw.buf, dc.gc,
 	               x1 * xw.cw, y1 * xw.ch,
 	               (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch);
@@ -1189,6 +1191,7 @@
 
 void
 xinit(void) {
+	XVisualInfo vinfo;
 	XSetWindowAttributes attrs;
 
 	if(!(xw.dis = XOpenDisplay(NULL)))
@@ -1204,7 +1207,8 @@
 	xw.ch = dc.font->ascent + dc.font->descent;
 
 	/* colors */
-	xw.cmap = XDefaultColormap(xw.dis, xw.scr);
+	XMatchVisualInfo(xw.dis, xw.scr, bitdepth, TrueColor, &vinfo);
+	xw.cmap = XCreateColormap(xw.dis, XRootWindow(xw.dis, xw.scr), vinfo.visual, None);
 	xloadcols();
 
 	/* window - default size */
@@ -1213,8 +1217,8 @@
 	xw.h = xw.bufh + 2*BORDER;
 	xw.w = xw.bufw + 2*BORDER;
 
-	attrs.background_pixel = dc.col[DefaultBG];
-	attrs.border_pixel = dc.col[DefaultBG];
+	attrs.background_pixel = ALPHA << 24 | dc.col[DefaultBG];
+	attrs.border_pixel = ALPHA << 24 | dc.col[DefaultBG];
 	attrs.bit_gravity = NorthWestGravity;
 	attrs.event_mask = FocusChangeMask | KeyPressMask
 		| ExposureMask | VisibilityChangeMask | StructureNotifyMask
@@ -1222,12 +1226,12 @@
 	attrs.colormap = xw.cmap;
 
 	xw.win = XCreateWindow(xw.dis, XRootWindow(xw.dis, xw.scr), 0, 0,
-			xw.w, xw.h, 0, XDefaultDepth(xw.dis, xw.scr), InputOutput,
-			XDefaultVisual(xw.dis, xw.scr),
+			xw.w, xw.h, 0, bitdepth, InputOutput,
+			vinfo.visual,
 			CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
 			| CWColormap,
 			&attrs);
-	xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
+	xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, bitdepth);
 	/* gc */
 	dc.gc = XCreateGC(xw.dis, xw.win, 0, NULL);
 	
@@ -1248,8 +1252,8 @@
 	else
 		xfg = dc.col[base.fg], xbg = dc.col[base.bg];
 
-	XSetBackground(xw.dis, dc.gc, xbg);
-	XSetForeground(xw.dis, dc.gc, xfg);
+	XSetBackground(xw.dis, dc.gc, ALPHA << 24 | xbg);
+	XSetForeground(xw.dis, dc.gc, 0xff << 24 | xfg);
 	
 	if(base.mode & ATTR_GFX)
 		for(i = 0; i < len; i++) {
@@ -1297,8 +1301,8 @@
 void
 xdrawc(int x, int y, Glyph g) {
 	XRectangle r = { x * xw.cw, y * xw.ch, xw.cw, xw.ch };
-	XSetBackground(xw.dis, dc.gc, dc.col[g.bg]);
-	XSetForeground(xw.dis, dc.gc, dc.col[g.fg]);
+	XSetBackground(xw.dis, dc.gc, ALPHA << 24 | dc.col[g.bg]);
+	XSetForeground(xw.dis, dc.gc, 0xff << 24 | dc.col[g.fg]);
 	XSetFont(xw.dis, dc.gc, g.mode & ATTR_BOLD ? dc.bfont->fid : dc.font->fid);
 	XDrawImageString(xw.dis, xw.buf, dc.gc, r.x, r.y+dc.font->ascent, &g.c, 1);
 }
@@ -1460,7 +1464,7 @@
 	xw.bufh = MAX(1, xw.bufh);
 	xw.bufw = MAX(1, xw.bufw);
 	XFreePixmap(xw.dis, xw.buf);
-	xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr));
+	xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, bitdepth);
 }
 
 void

Reply via email to