[Gtk-sharp-list] Problem with Semi-Transparent Window

Arno Nühm informatik4u at web.de
Fri May 4 08:46:07 EDT 2007

i have a non-decorated (borderless) and dragable Gtk.Window with a semi-transparent PNG image in the background and a label above. The progrmm will be used as a desktop widget and should be transparent (by copying the desktop background).

That works so far, but i have the following problem:
When another window is above my programm and the window is moved or minimized, it draws some lines on my programm. Sometimes even the text of my label will be ereased.

Does somebody knows where's the problem here?

Here is a example code and a example semi-transparent PNG image:


using System;
using Gtk;
using Gdk;

public class TransparentWindow : Gtk.Window
	double offsetX;
	double offsetY;
	public TransparentWindow (String title) : base (Gtk.WindowType.Toplevel)
		this.Events |= Gdk.EventMask.ButtonPressMask;
		this.Events |= Gdk.EventMask.ButtonReleaseMask;
		this.Events |= Gdk.EventMask.ButtonMotionMask;
		this.DeleteEvent += new DeleteEventHandler (OnSkinWindowDelete);
		this.ButtonPressEvent += new ButtonPressEventHandler(OnButtonPressEvent);
		this.ButtonReleaseEvent += new ButtonReleaseEventHandler(OnButtonReleaseEvent);
		this.MotionNotifyEvent += new MotionNotifyEventHandler(OnButtonMotionEvent);
		this.Title = title;
		this.Decorated = false;
		// transparent Background image 
		Gdk.Pixbuf pixbufBg = new Pixbuf("backgroundtrans.png");
		Gtk.Image backgroundImage = new Gtk.Image(pixbufBg);
		// Label
		Gtk.Label label = new Gtk.Label();
		label.Text = "<span color=\"black\" weight=\"bold\">test test test test test test test test </span>";
		label.UseMarkup = true;
		// Container to add Widgets with fixed positions
		Gtk.Fixed fixedContainer = new Gtk.Fixed();
		fixedContainer.Put(label, 6, 5);
		// add fixed Container to window
		this.ShowAll ();
	// drag methods
	private void OnButtonPressEvent(object o, ButtonPressEventArgs a)
		this.offsetX = a.Event.X;
		this.offsetY = a.Event.Y;
	private void OnButtonMotionEvent(object o, MotionNotifyEventArgs a)
		int x = (int)(a.Event.XRoot - this.offsetX);
		int y = (int)(a.Event.YRoot - this.offsetY);
	private void OnButtonReleaseEvent(object o, ButtonReleaseEventArgs a)
	// transparency methods
	void MakeTransparent (Widget widget)
            if (0 < (int) (widget.WidgetFlags & WidgetFlags.NoWindow)) {

            widget.AppPaintable = true;
            widget.DoubleBuffered = false;
            widget.GdkWindow.SetBackPixmap (null, true);
            widget.ExposeEvent += OnChildExpose;
            widget.StyleSet += MakeTransparentAgain;

         void MakeTransparentAgain (object obj, StyleSetArgs args)
            (obj as Widget).GdkWindow.SetBackPixmap (null, true);
        protected override void OnAdded (Widget widget)
            widget.Realized += OnChildRealized;
            base.OnAdded (widget);
		protected override void OnRealized ()
            base.OnRealized ();
            MakeTransparent (this);
        void OnChildRealized (object obj, EventArgs args)
            MakeTransparent (obj as Widget);
        void OnChildExpose (object obj, ExposeEventArgs args)
            (obj as Widget).GdkWindow.ClearArea (args.Event.Area.X,
            args.RetVal = false;
        // quit
        void OnSkinWindowDelete (object sender, DeleteEventArgs a)
		Application.Quit ();
		a.RetVal = true;
	public static void Main (string[] args)
		Application.Init ();
		TransparentWindow win = new TransparentWindow ("TestWindow");
		win.Show ();
		Application.Run ();

Thanks in advance!

SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192

More information about the Gtk-sharp-list mailing list