Index: src/xterm.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/xterm.c,v
retrieving revision 1.930
diff -u -r1.930 xterm.c
--- src/xterm.c	3 Nov 2006 08:58:39 -0000	1.930
+++ src/xterm.c	4 Nov 2006 13:32:47 -0000
@@ -947,6 +947,51 @@
   return FONT_TYPE_UNKNOWN;
 }
 
+#define OPAQUE  0xffffffff
+#define OPACITY "_NET_WM_WINDOW_OPACITY"
+
+void
+x_set_frame_alpha (f, activate_p)
+     struct frame *f;
+     int activate_p;
+{
+  Display *dpy = FRAME_X_DISPLAY (f);
+  Window win = FRAME_OUTER_WINDOW (f);
+  if (FRAME_X_DISPLAY_INFO (f)->root_window != FRAME_X_OUTPUT (f)->parent_desc)
+    /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
+       we must treat the former instead of the latter. */
+    win = FRAME_X_OUTPUT(f)->parent_desc;
+
+  double alpha = activate_p? f->active_alpha: f->inactive_alpha;
+  unsigned int opac = (unsigned int)(alpha * OPAQUE);
+
+  {
+    unsigned char *data;
+
+    Atom actual;
+    int format;
+    unsigned long n, left;
+
+    XGetWindowProperty(dpy, win, XInternAtom(dpy, OPACITY, False),
+		       0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
+		       (unsigned char **) &data);
+
+    if (data != None)
+      if (*(unsigned int *)data == opac)
+	{
+	  XFree ((void *) data);
+	  return;
+	}
+      else
+	XFree ((void *) data);
+  }
+
+  XChangeProperty (dpy, win, XInternAtom (dpy, OPACITY, False),
+		   XA_CARDINAL, 32, PropModeReplace,
+		   (unsigned char *) &opac, 1L);
+  XSync (dpy, False);
+}
+
 
 
 /***********************************************************************
@@ -3148,6 +3193,7 @@
 		    f->output_data.x->border_pixel);
   UNBLOCK_INPUT;
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 1);
 }
 
 static void
@@ -3163,6 +3209,7 @@
 			  f->output_data.x->border_tile);
   UNBLOCK_INPUT;
   x_update_cursor (f, 1);
+  x_set_frame_alpha (f, 0);
 }
 
 /* The focus has changed.  Update the frames as necessary to reflect
Index: src/xfns.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/xfns.c,v
retrieving revision 1.679
diff -u -r1.679 xfns.c
--- src/xfns.c	31 Oct 2006 06:41:55 -0000	1.679
+++ src/xfns.c	4 Nov 2006 13:32:48 -0000
@@ -565,6 +565,8 @@
 							     Lisp_Object,
 							     char *, char *,
 							     int));
+extern void x_set_frame_alpha P_ ((struct frame *, int));
+
 
 
 /* Store the screen positions of frame F into XPTR and YPTR.
@@ -1801,6 +1803,82 @@
 #endif
 }
 
+/* Change the opacity of frame F to ALPHA.
+   ALPHA must be a number between 0.0 and 1.0
+
+   The frame will become completely invisible if ALPHA is 0.0,
+   while the value of 1.0 makes it completely opaque.  */
+
+static void
+x_set_active_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->active_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha) && (XFLOAT_DATA (alpha) >= 0.0 && XFLOAT_DATA (alpha) <= 1.0))
+    f->active_alpha = XFLOAT_DATA (alpha);
+  else if (INTEGERP (alpha) && (XINT (alpha) == 0 || XINT (alpha) == 1))
+    f->active_alpha = (XINT (alpha) == 0) ? 0.0 : 1.0;
+  else
+    {
+      f->active_alpha = XFLOAT_DATA (old_alpha);
+      return;
+    }
+
+  BLOCK_INPUT;
+
+  if (dpyinfo->x_highlight_frame == f)
+    x_set_frame_alpha (f, 1);
+
+  UNBLOCK_INPUT;
+
+  return;
+}
+
+static void
+x_set_inactive_alpha (f, alpha, old_alpha)
+     struct frame *f;
+     Lisp_Object alpha, old_alpha;
+{
+  struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
+
+  /* Don't change the alpha if it's already ALPHA.  */
+  if (EQ (alpha, f->inactive_alpha))
+    return;
+
+  if (NILP (alpha))
+    return;
+
+  if (FLOATP (alpha) && (XFLOAT_DATA (alpha) >= 0.0 && XFLOAT_DATA (alpha) <= 1.0))
+    f->inactive_alpha = XFLOAT_DATA (alpha);
+  else if (INTEGERP (alpha) && (XINT (alpha) == 0 || XINT (alpha) == 1))
+    f->inactive_alpha = (XINT (alpha) == 0) ? 0.0 : 1.0;
+  else
+    {
+      f->inactive_alpha = XFLOAT_DATA (old_alpha);
+      return;
+    }
+
+  BLOCK_INPUT;
+
+  if(dpyinfo->x_highlight_frame != f)
+    {
+      x_set_frame_alpha (f, 0);
+    }
+
+  UNBLOCK_INPUT;
+
+  return;
+}
+
 
 /* Record in frame F the specified or default value according to ALIST
    of the parameter named PROP (a Lisp symbol).  If no value is
@@ -3356,6 +3434,10 @@
   x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
 		       "scrollBarWidth", "ScrollBarWidth",
 		       RES_TYPE_NUMBER);
+  x_default_parameter (f, parms, Qactive_alpha, make_float(1.0),
+		       "activeAlpha", "ActiveAlpha", RES_TYPE_FLOAT);
+  x_default_parameter (f, parms, Qinactive_alpha, make_float(1.0),
+		       "inactiveAlpha", "InactiveAlpha", RES_TYPE_FLOAT);
 
   /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
      Change will not be effected unless different from the current
@@ -5737,6 +5819,8 @@
   x_set_fringe_width,
   x_set_wait_for_wm,
   x_set_fullscreen,
+  x_set_active_alpha,
+  x_set_inactive_alpha,
 };
 
 void

