Subject: FVWM: Transparency/Translucency revisited...

From: Dawid Kuroczko <[email-masked]>
Date: Mon, 25 Aug 2003 21:00:32 +0200 (CEST)

Hello. :-)

I did manage to make pseudo-transparent menus, but now I'd like
to make something more "real".  What I'd like to do is to have
something like there is in KDE.

It should work like this:
 1. user clicks thus calling a Menu.
 2. current screen dump is taken (with all the windows, but
    without a menu just as yet).
 3. this screen dump is made available to Menu as
    root background pixmap.
 4. Menu is displayed with tinted real background.

This way it's pretty easy to make an illusion of real
transparency (and looks "l33t", as some may say).

My question is, how to do it to, and make it good.  I came up
with a function which would call xwd, convert and fvwm-root
and then call Menu.  Which is slow (convert) and does set
background instead of just making it "virtually" available
to Menu...

Second question -- Xrender.  AFAIK this extension allows
making windows really transparent/translucent without using
any of these tricks.  I know fvwm has Xrender support, but
is there a way (magical fvwm2rc lines :)) to enable
Xrendered translucent windows? :-)

   Regards,
     Dawid

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Olivier Chapuis <[email-masked]>
Date: Tue, 26 Aug 2003 01:27:02 +0200

> background instead of just making it "virtually" available

I do not think that you will succeed to have something which
works by using this method. fvwm cannot do what you ask,
maybe in the future.

> Xrendered translucent windows? :-)

Xrender does not allows to make window transparent. This is
a legend (which comes from a screenshot). Xrender can be
used to apply 2 images in one via an alpha channel (an
obvious example is tinting). You can do that without Xrender,
but with Xrender you may hope that the operation is faster
(e.g., hardware acceleration).

Regards, Olivier

---

From: Tavis Ormandy <[email-masked]>
Date: Tue, 26 Aug 2003 13:31:19 +0000

> transparency (and looks "l33t", as some may say).

nice idea, i havnt seen it before so i got a kde using friend to show
it to me.

> background instead of just making it "virtually" available

i would implement a wrapper to the Popup command, TransMenuPopup for
example, ive been playing around and its definitiely possible (its a
little laggy if you want to tint it, like i have below, but the effect
is nice)

I'm not sure if theres anyway of getting the geometry of a menu before
its drawn, so ive just grabbed a menu size chunk here (edit to fit your
menus)

# Usage: TransMenuPopup [MenuName]
DestroyFunc TransMenuPopup
AddToFunc TransMenuPopup
+ I PipeRead "echo SetEnv tr_menu_face /tmp/fvwm_$${RANDOM}.xpm"
+ I PipeRead "import -window root -crop \
		140x300+`expr $[pointer.x] - 70`+`expr $[pointer.y] - 7` \
		-dither -silent $[tr_menu_face] \
	&& convert -modulate 50 $[tr_menu_face] $[tr_menu_face] \
		&& echo Nop \
	|| echo Beep"
+ I CopyMenuStyle * TransMenuStyle
+ I MenuStyle TransMenuStyle MenuFace TiledPixmap $[tr_menu_face], \
	Foreground White
+ I ChangeMenuStyle TransMenuStyle $0
+ I Menu $0
+ I ChangeMenuStyle * $0
+ I DestroyMenuStyle TransMenuStyle
+ I Exec exec rm -f -- $[tr_menu_face]

# Right-Click on root window to test...
Mouse 1 R A TransMenuPopup MenuFvwmRoot

Heres a screenshot of my usual MenuFvwmRoot...
http://taviso.decsystem.org/images/normal.png

And heres one after replacing Popup with TransMenuPopup example...
http://taviso.decsystem.org/images/funky.png

-- 
-------------------------------------
[email-masked] | finger me for my gpg key.
-------------------------------------------------------
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Olivier Chapuis <[email-masked]>
Date: Wed, 27 Aug 2003 15:51:26 +0200

> background instead of just making it "virtually" available

Humm, ... in fact some code in fvwm was already there for this.

Apply the attached patch to the current cvs (really current)
or to the next snapshot and use the following config:

Colorset 5 Transparent, Tint black 50
MenuStyle * MenuColorset 5, PopupOffset 0 100, AnimationOff

and you get what you want :o)

However, I do not think that such patch will be applied before
fvwm-2.6.

Regards, Olivier 
Index: fvwm/menus.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.c,v
retrieving revision 1.371
diff -u -r1.371 menus.c
--- fvwm/menus.c	5 Jul 2003 01:37:47 -0000	1.371
+++ fvwm/menus.c	27 Aug 2003 13:04:23 -0000
@@ -3202,7 +3202,39 @@
 	}
 	MR_IS_PAINTED(mr) = 1;
 	/* paint the menu background */
-	if (ms && ST_HAS_MENU_CSET(ms))
+	if (ms && ST_HAS_MENU_CSET(ms) &&
+	    CSET_IS_TRANSPARENT_PR(ST_CSET_MENU(ms)) &&
+	    !MR_IS_TEAR_OFF_MENU(mr))
+	{
+		Pixmap trans = None;
+		FvwmRenderAttributes fra;
+		colorset_t *colorset = &Colorset[ST_CSET_MENU(ms)];
+	
+		fra.mask = 0;
+		if (colorset->tint_percent > 0)
+		{
+			fra.mask = FRAM_HAVE_TINT;
+			fra.tint = colorset->tint;
+			fra.tint_percent = colorset->tint_percent;
+		}
+		if (MR_IS_BACKGROUND_SET(mr) == False)
+		{
+			trans = PGraphicsCreateTranslucent(
+				dpy, MR_WINDOW(mr), &fra,
+				BACK_GC(ST_MENU_INACTIVE_GCS(ms)),
+				MR_X(mr), MR_Y(mr), MR_WIDTH(mr), MR_HEIGHT(mr));
+			XMapRaised(dpy, MR_WINDOW(mr));
+			if (trans != None)
+			{
+				XSetWindowBackgroundPixmap(
+					dpy, MR_WINDOW(mr), trans);
+				MR_IS_BACKGROUND_SET(mr) = True;
+				clear_expose_menu_area(MR_WINDOW(mr), pevent);
+				XFreePixmap(dpy, trans);
+			}
+		}
+	}
+	else if (ms && ST_HAS_MENU_CSET(ms))
 	{
 		if (MR_IS_BACKGROUND_SET(mr) == False)
 		{
@@ -4172,10 +4204,23 @@
 	 */
 
 	XMoveWindow(dpy, MR_WINDOW(mr), x, y);
+	MR_X(mr) = x;
+	MR_Y(mr) = y;
 	XSelectInput(dpy, MR_WINDOW(mr), event_mask);
-	XMapRaised(dpy, MR_WINDOW(mr));
-	if (popdown_window)
-		XUnmapWindow(dpy, popdown_window);
+	if (MR_STYLE(mr) && ST_HAS_MENU_CSET(MR_STYLE(mr)) &&
+	    CSET_IS_TRANSPARENT_PR(ST_CSET_MENU(MR_STYLE(mr))) &&
+	    !MR_IS_TEAR_OFF_MENU(mr))
+	{
+		if (popdown_window)
+			XUnmapWindow(dpy, popdown_window);
+		paint_menu(mr, NULL, fw);
+	}
+	else
+	{
+		XMapRaised(dpy, MR_WINDOW(mr));
+		if (popdown_window)
+			XUnmapWindow(dpy, popdown_window);
+	}
 	XFlush(dpy);
 	MR_MAPPED_COPIES(mr)++;
 	MST_USAGE_COUNT(mr)++;
Index: fvwm/menus.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.h,v
retrieving revision 1.102
diff -u -r1.102 menus.h
--- fvwm/menus.h	29 Jun 2003 19:53:23 -0000	1.102
+++ fvwm/menus.h	27 Aug 2003 13:04:24 -0000
@@ -141,6 +141,9 @@
 	MenuItem *submenu_item;
 	/* x distance window was moved by animation */
 	int xanimation;
+	/* x,y XMapRaise */
+	int x;
+	int y;
 	/* dynamic temp flags */
 	struct
 	{
@@ -182,7 +185,9 @@
 #define MR_SELECTED_ITEM(m)         ((m)->d->selected_item)
 #define MR_SUBMENU_ITEM(m)          ((m)->d->submenu_item)
 #define MR_XANIMATION(m)            ((m)->d->xanimation)
+#define MR_X(m)            ((m)->d->x)
+#define MR_Y(m)            ((m)->d->y)
 #define MR_STORED_ITEM(m)           ((m)->d->stored_item)
 #define MR_STORED_PIXELS(m)         ((m)->d->stored_pixels)
 /* flags */
Index: libs/PictureGraphics.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/PictureGraphics.c,v
retrieving revision 1.24
diff -u -r1.24 PictureGraphics.c
--- libs/PictureGraphics.c	27 Aug 2003 12:59:25 -0000	1.24
+++ libs/PictureGraphics.c	27 Aug 2003 13:04:36 -0000
@@ -1338,8 +1338,8 @@
 	}
 }
 
-#if 0 /* humm... maybe usefull one day with menus */
+#if 1 /* humm... maybe usefull one day with menus */
 Pixmap PGraphicsCreateTranslucent(
 	Display *dpy, Window win, FvwmRenderAttributes *fra, GC gc,
 	int x, int y, int width, int height)
Index: libs/PictureGraphics.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/PictureGraphics.h,v
retrieving revision 1.12
diff -u -r1.12 PictureGraphics.h
--- libs/PictureGraphics.h	29 Jun 2003 19:53:24 -0000	1.12
+++ libs/PictureGraphics.h	27 Aug 2003 13:04:36 -0000
@@ -122,8 +122,10 @@
 	Display *dpy, Window win, Pixel tint, int tint_percent,
 	Drawable dest, Bool dest_is_a_window, GC gc, GC mono_gc, GC alpha_gc,
 	int dest_x, int dest_y, int dest_w, int dest_h);
-
+Pixmap PGraphicsCreateTranslucent(
+	Display *dpy, Window win, FvwmRenderAttributes *fra, GC gc,
+	int x, int y, int width, int height);
 /* never used ! */
 Pixmap PGraphicsCreateDitherPixmap(
 	Display *dpy, Window win, Drawable src, Pixmap mask, int depth, GC gc,

---

From: Ben Winslow <[email-masked]>
Date: 27 Aug 2003 14:47:09 -0400

> or to the next snapshot and use the following config:

I had some trouble applying the patch, so I applied the troublesome bits
manually and made another diff...  Strangely, my diff doesn't look
significantly different from yours, but my version of patch had trouble
with the one attached to your message...

I like the effect this provides... it's not perfect (of course, you
can't get perfect behavior in X yet), but it works pretty nicely, and
since menus are fairly transient anyway, it's not too likely that
whatever they're over top of will change.

-- 
Ben Winslow <[email-masked]>
Index: fvwm/menus.c
diff -u -3 -p -r1.371 menus.c
+++ fvwm/menus.c	27 Aug 2003 18:41:49 -0000
@@ -3202,7 +3202,39 @@ static void paint_menu(
@@ -4172,10 +4204,23 @@ static int pop_menu_up(
 	 */
 
 	XMoveWindow(dpy, MR_WINDOW(mr), x, y);
+	MR_X(mr) = x;
+	MR_Y(mr) = y;
 	XSelectInput(dpy, MR_WINDOW(mr), event_mask);
-	XMapRaised(dpy, MR_WINDOW(mr));
-	if (popdown_window)
-		XUnmapWindow(dpy, popdown_window);
+	if (MR_STYLE(mr) && ST_HAS_MENU_CSET(MR_STYLE(mr)) &&
+	    CSET_IS_TRANSPARENT_PR(ST_CSET_MENU(MR_STYLE(mr))) &&
+	    !MR_IS_TEAR_OFF_MENU(mr))
+	{
+		if (popdown_window)
+			XUnmapWindow(dpy, popdown_window);
+		paint_menu(mr, NULL, fw);
+	}
+	else
+	{
+		XMapRaised(dpy, MR_WINDOW(mr));
+		if (popdown_window)
+			XUnmapWindow(dpy, popdown_window);
+	}
 	XFlush(dpy);
 	MR_MAPPED_COPIES(mr)++;
 	MST_USAGE_COUNT(mr)++;
Index: fvwm/menus.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/menus.h,v
retrieving revision 1.102
diff -u -3 -p -r1.102 menus.h
--- fvwm/menus.h	29 Jun 2003 19:53:23 -0000	1.102
+++ fvwm/menus.h	27 Aug 2003 18:41:50 -0000
@@ -141,6 +141,9 @@ typedef struct MenuRootDynamic
 	MenuItem *submenu_item;
 	/* x distance window was moved by animation */
 	int xanimation;
+	/* x, y XMapRaise */
+	int x;
+	int y;
 	/* dynamic temp flags */
 	struct
 	{
@@ -182,6 +185,8 @@ typedef struct MenuRootDynamic
 #define MR_SELECTED_ITEM(m)         ((m)->d->selected_item)
 #define MR_SUBMENU_ITEM(m)          ((m)->d->submenu_item)
 #define MR_XANIMATION(m)            ((m)->d->xanimation)
+#define MR_X(m)			    ((m)->d->x)
+#define MR_Y(m)			    ((m)->d->y)
 #define MR_STORED_ITEM(m)           ((m)->d->stored_item)
 #define MR_STORED_PIXELS(m)         ((m)->d->stored_pixels)
 /* flags */
Index: libs/PictureGraphics.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/PictureGraphics.c,v
retrieving revision 1.25
diff -u -3 -p -r1.25 PictureGraphics.c
--- libs/PictureGraphics.c	27 Aug 2003 13:37:04 -0000	1.25
+++ libs/PictureGraphics.c	27 Aug 2003 18:41:50 -0000
@@ -1338,7 +1338,7 @@ void PGraphicsTintRectangle(
 	}
 }
 
diff -u -3 -p -r1.12 PictureGraphics.h
+++ libs/PictureGraphics.h	27 Aug 2003 18:41:50 -0000
@@ -122,7 +122,9 @@ void PGraphicsTintRectangle(

---

From: Bob Woodside <[email-masked]>
Date: Wed, 27 Aug 2003 16:09:56 -0400

On 27 Aug 2003 14:47:09 -0400

> whatever they're over top of will change.

	Unless, of course, they're tear-off menus....

Cheers,
Bob
(Resident Curmudgeon)

---

From: Mikhael Goikhman <[email-masked]>
Date: Wed, 27 Aug 2003 23:11:05 +0300

> whatever they're over top of will change.

It is more likely that the menu itself moves, as in animated menus.

Regards,
Mikhael.

---

From: Olivier Chapuis <[email-masked]>
Date: Wed, 27 Aug 2003 23:47:39 +0200

> It is more likely that the menu itself moves, as in animated menus.

Yes, but this can be more or less fixed (I do not handle this case,
I wrote the patch just for fun). Anyway, I suggested AnimationOff
and no menu overlapping: PopupOffset 0 100.

Regard, Olivier

---

From: Olivier Chapuis <[email-masked]>
Date: Wed, 27 Aug 2003 23:44:21 +0200

> 	Unless, of course, they're tear-off menus....

Yes. However, the patch does not use translucence when the menu is
a tear-off menu. When, the menu is tear-off the usual Transparent
colorset is used, so you need:

Style fvwm_menu ParentalRelativity

and if you have some tint the stuff may be broken (see the FvwmTheme
man page about tinting the Transparent colorset).  By the way,
Transparent and RootTransparent colorset are broken with tear-off
menu: the menu bg is not updated when you move the window or on a bg
change (with a compliant "setbg" apps). This may (should/must ?) be
fixed before 2.6. I Recall that at some point tear-off menu was
declared as "possibly disabled for 2.6". But this is not the case
anymore.

Regards, Olivier

---

From: Dawid Kuroczko <[email-masked]>
Date: Thu, 28 Aug 2003 09:34:37 +0200 (CEST)

> Humm, ... in fact some code in fvwm was already there for this.

I should have expected that. :-)  Like a prodigal son,
I recently returned to Fvwm (I was misle by false WMs ;-))
and I'm constantly at awe...

> and you get what you want :o)

Great, it works great. :-)))

   Regards,
     Dawid

---

From: Olivier Chapuis <[email-masked]>
Date: Sun, 31 Aug 2003 22:39:19 +0200

> transparency (and looks "l33t", as some may say).

Here a new version of the patch for current cvs/snapshot.
This patch add a new options to Colorset: Translucent/NoTranslucent.
These options has effects only with (non tear-off) menu.
Also menu animation is "handled".

For example with:

  Colorset 5 fg yellow, bg blue, HGradient 200 lightblue darkblue, \
	  Translucent blue 60
  Style * MenuColorset 5, PopupOffset 0 100, AnimationOff

you get translucent menus (with a 60% blue tint) and if you tear-off
a menu the menu use the gradient.

Regards, Olivier