2

I am developing a multiplatform program using Mono and it requires Form Opacity support. Basically the ability to make a window semi-transparent. This works fine in windows by setting the Window.Form.Opacity property to say 0.5. In Ubuntu 14.04 however it does not work out-of-the-box. I think I'm running Unity and Compiz, whatever came with the default Ubuntu setup.

According to the Mono FAQ, this should be supported:

How can I make my windows alpha blended? (transparent)

Mono’s Winform implementation supports transparency on its windows as long as the underlying windowing system has support for it.

For Unix/X11 users this means that they must have the COMPOSITE extension enabled on their server, and they must be running a compositing manager, like xcompmgr.

The GenToo Linux Wiki has a good description on how to setup the Xorg server for transparency support.

http://www.mono-project.com/docs/faq/winforms/

The link they point to is dead.

I'm new to Linux and not quite sure I understand all the parts involved in getting a compositing window manager up and running. Besides, don't I already have one (compiz?)

What should I try to get my Winform opacity to work?

Edit: My test program is basically a form with a scrollbar (goes from 0 to 100) that has an event handler on change to set the form's opacity based on the scrollbar's value. This is the meat of it:

private void trackBar1_Scroll(object sender, EventArgs e)
{
    double opacity = ((double)trackBar1.Value) / 100;
    this.Opacity = opacity;
}

Works great in Windows.

  • Can you provide an example program that should have a transparent window? – Volker Siegel Aug 28 '14 at 0:29
  • @VolkerSiegel Edited the question with the main part of the code. – Cubicle Dragon Aug 28 '14 at 16:53
  • Oh, I have not the faintest idea how to use that - the last time I used Windows, .net etc did not exist... ;) If you have a SSCCE, I can take a look at what the library actually does, but even if it's the error I expect, that does not fix it for you, so it's not that important. – Volker Siegel Aug 28 '14 at 20:05
  • I found a way to make it work, but I must set the Winform's Opacity BEFORE showing the window. If the window is already visible, changing its opacity does nothing. No amount of Refresh, Invalidate, "hide then show" will change anything. Guess the easiest method will be to use your xprop command line example and have my Winform application call the terminal and have xprop do the work instead of Window.Opacity. – Cubicle Dragon Aug 28 '14 at 20:15
1

You do indeed have all you need with compiz.

Setting Window.Form.Opacity should set the X window property _NET_WM_WINDOW_OPACITY on the window;

For a test whether the ubuntu part works, try setting the opacity manually to 0.5 with this low-level command (click the window):

$ xprop -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0x7fffffff

And back to full opacity:

$ xprop -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY 0xffffffff


One way how setting Window.Form.Opacity could fail is that it chooses a wrong (but closely related) window, and set's the property there.


According to your comments, the idea was right. Adding:

I suspect it is a very specific error that exists in other software too: The window that is choosen to make it transparent is found by some heuristics based on how the X windows of the window decorator and the application are related/nested etc. But with the introduction of reparenting WM's there was a lot of change in the area - gladly the heuristics still worked. From what I understand, this is a case of the heuristics failing,so that some nearby invisible window will be made transparent...

Look at this bug to understand more of the problem: transset fails to change the _NET_WM_WINDOW_OPACITY property

  • This does indeed work. I am able to make my Winform window transparent with that command, but my Winform application itself still does not work. Maybe there's some platform-specific things I need to do in Linux, like manually repaint my window or refresh something. – Cubicle Dragon Aug 28 '14 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.