I'd like to make the background of a Gtk+ window transparent so that only the widgets in the window are visible. I found a few tutorials:
http://mikehearn.wordpress.com/2006/03/26/gtk-windows-with-alpha-channels/
http://macslow.thepimp.net/?p=26
But they both appear to listen to the "expose" event, and then delegate to Cairo to do the rendering. This means that other widgets added to the window are not rendered (for example, I've tried adding a button to the window as well).
I see that there's a method modify-bg on GtkWidget: http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-modify-bg
However, GdkColor does not appear to accept a parameter for transparency: http://library.gnome.org/devel/gdk/stable/gdk-Colormaps-and-Colors.html
I've tried the GtkWindow.set_opacity method as well, but this sets the opacity for the window contents as well, which is not what I want.
I'd appreciate any guidance anyone can provide in this.
I changed the alphademo example to draw a button instead of the red circle.
This application draws the button on a 400x400 transparent window.
When you click on the window the application shows/hides the title bar.
Compiled on Ubuntu 10.04:
Thanks for the code, just what i was looking for though it needs to be modified to work GTK3. Also the expose-event needs to be changed to a 'draw' event to get it working. So here's my code contribution modified for GTK3:
Here's how i compiled it on Ubuntu 15.04:
Hopefully this helps out someone else trying to get it working on GTK3.
Thanks for the answer. I rewrite the code in python + GTK3:
For those using golang, here's one using gotk3 ( https://github.com/gotk3/gotk3 ) :