Wikia

Sawfish

Alpha backgrounds

Talk0
770pages on
this wiki
Browse all patches

Author Edit

Philip Langdale

Synopsis Edit

Make window to draw properly with transparent pieces.

So, I've been playing around with the new gnome-terminal with true transparency and it's provoked me to fix the problem where ARGB windows end up with transparent frame elements. This occurs because gdk_pixbuf_xlib actively clobbers the alpha channel when rendering into Drawables. As it's easier to fix sawfish than to get a gtk patch in, I've come up with this change that ensures the alpha value is 0xFF (fully opaque) when drawing the frame elements. It's a little sad because we have to replace XCopyArea with a client side operation (XGet/PutImage) but frame elements are usually very small so this shouldn't hurt too badly.

Patch testing Edit

  1. Copy/paste the patch listed below into some file, eg. TEST.diff.
  2. If you don't have sawfish sources yet, have one, as described get it from GIT repo.
  3. Go into the directory where sawfish sources reside, eg. cd sawfish
  4. Test if the patch applies cleanly with this command:
    patch -p1 --ignore-whitespace --dry-run < TEST.diff
    in case of problems try also: -p0 or -p2
  5. If it applies cleanly, then remove the --dry-run from above command and run it again, otherwise ask on the mailing list.
  6. Compile sawfish: ./autogen.sh && make
  7. Install it for testing, but it depends on your linux distribution.
    1. It is always better to install sawfish as your distribution package, but it is different for each distribution.
    2. So you may try make install, which will install sawifish in /usr/local/share/sawfish/ (if you have write access). But then make sure that you run the correct version and delete it from that directory afterwards, to avoid any conflicts.
  8. Se also

PS: edit this template if you feel that those instructions can be improved.

Patch Edit

--- sawfish/src/frames.c.alpha	2006-05-31 23:29:03.000000000 -0600
+++ sawfish/src/frames.c	2006-12-27 11:15:36.000000000 -0700
@@ -322,6 +322,34 @@ apply_mask (Drawable dest, int x_off, in
     }
 }
 
+/* Replacement for XCopyArea that ensures the alpha value is 0xFF when
+   copying a 24bit drawable. 32bit drawables are assumed to contain a
+   meaningful alpha channel already - and smaller bit depths have no
+   alpha at all. */
+static void
+copy_area_set_alpha(Drawable src, Drawable dest, GC gc,
+		    int src_x, int src_y,
+		    unsigned int width, unsigned int height,
+		    int dest_x, int dest_y)
+{
+    XImage *image = XGetImage (dpy, src, src_x, src_y, width, height,
+			       AllPlanes, ZPixmap);
+    if (image->depth == 24) {
+	unsigned int i;
+
+	for (i = image->byte_order == LSBFirst ? 3 : 0;
+	     i < height * image->bytes_per_line; i +=4) {
+	    image->data[i] = 0xFF;
+	}
+	XPutImage(dpy, dest, gc, image, src_x, src_y, dest_x, dest_y,
+		  width, height);
+    } else {
+	XCopyArea(dpy, src, dest, gc, src_x, src_y, width, height,
+		  dest_x, dest_y);
+    }
+    XDestroyImage(image);
+}
+
 /* Construct the frame window's shape mask from the union of all
    individual shapes (frame parts and the client window, if appropriate).
    If ATOMIC is true, then the frame shape is changed _once_ only, using
@@ -534,7 +562,7 @@ set_frame_part_bg (struct frame_part *fp
 	if (bg != fp->drawn.bg)
 	{
 	    XGCValues gcv;
-	    gcv.foreground = VCOLOR(bg)->pixel;
+	    gcv.foreground = VCOLOR(bg)->pixel | (0xFF << 24);
 	    XChangeGC (dpy, fp->gc, GCForeground, &gcv);
 	    XFillRectangle (dpy, fp->id, fp->gc, 0, 0, fp->width, fp->height);
 	    fp->drawn.bg = bg;
@@ -585,8 +613,8 @@ set_frame_part_bg (struct frame_part *fp
 
 	if (!tiled)
 	{
-	    XCopyArea (dpy, bg_pixmap, fp->id, fp->gc, 0, 0,
-		       fp->width, fp->height, 0, 0);
+	  copy_area_set_alpha(bg_pixmap, fp->id, fp->gc, 0, 0,
+			      fp->width, fp->height, 0, 0);
 	    if (bg_mask != 0)
 	    {
 		XShapeCombineMask (dpy, fp->id, ShapeBounding,
@@ -622,8 +650,8 @@ set_frame_part_bg (struct frame_part *fp
 		int height = image_height (image);
 		while (x < fp->width)
 		{
-		    XCopyArea (dpy, bg_pixmap, fp->id, fp->gc,
-			       0, 0, width, height, x, y);
+		  copy_area_set_alpha (bg_pixmap, fp->id, fp->gc,
+				       0, 0, width, height, x, y);
 		    if (bg_mask != 0)
 		    {
 			XShapeCombineMask (dpy, tem, ShapeBounding,
@@ -792,9 +820,9 @@ set_frame_part_fg (struct frame_part *fp
 		}
 
 		XChangeGC (dpy, fp->gc, gcv_mask, &gcv);
-		XCopyArea (dpy, fg_pixmap, fp->id, fp->gc,
-			   0, 0, MIN(fp->width, width),
-			   MIN(fp->height, height), x, y);
+		copy_area_set_alpha (fg_pixmap, fp->id, fp->gc,
+				     0, 0, MIN(fp->width, width),
+				     MIN(fp->height, height), x, y);
 		if (fg_mask)
 		{
 		    gcv.clip_mask = None;
--- sawfish/src/ChangeLog.alpha	2006-05-31 23:29:02.000000000 -0600
+++ sawfish/src/ChangeLog	2006-12-27 11:06:24.000000000 -0700
@@ -1,3 +1,10 @@
+2006-09-30  Philip Langdale  <philipl@overt.org>
+
+       * frames.c (set_frame_part_bg, set_frame_part_fg, copy_area_set_alpha):
+       Ensure that the alpha channel is set correctly for frame elements
+       when ARGB visuals are used. Otherwise, they end up being 100%
+       transparent.
+
 2006-05-15  John Harper  <jsh@unfactored.org>
 
 	* frames.c, events.c: merged changes from Philip Langdale to

Community's reasons for inclusion or rejection Edit

Patch submitters, please vote also! Yes, obviosuly your vote will be positive, but it's the place to give your explanation why this patch is good for all Sawfish users, and why it is correct - good reasons for inclusion.

When voting anonymously please write your name, so that it can be associated with your posts on the mailing list. If you are logged in you can sign yourself by typing four tilda characters: ~~~~.

Yes vote: yes. As the author, I'm biased, but this is a very necessary change to be able to use applications like gnome-terminal which have transparent parts. Philipl 03:17, 31 July 2007 (UTC)

Wtf vote: pondering. Perhaps it was already fixed in GTK? See the mailing list I think that we should with this one until we get more feedback. Janek Kozicki 23:26, 18 January 2008 (UTC)

Wtf vote: pondering. Am using this since a week. I didn't have the problem before (not using this compmgr thing) but it hasn't caused any new ones for me in my setup. -- Peter. The post was done at 9:17, 6 February 2008 (UTC) Teika kazura 08:52, 14 July 2008 (UTC)

No vote: no. ok, according to this post the problem does not appear anymore. So the patch can be safely rejected. Janek Kozicki 14:48, 24 July 2008 (UTC)

Around Wikia's network

Random Wiki