# Semi transparent windows first draft

**URL:** <https://forum.juce.com/t/semi-transparent-windows-first-draft/11012>\
**Category:** Linux\
**Created:** [February 23, 2010, 11:42am UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012 "2010-02-23T11:42:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [February 23, 2010, 11:42am UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/1 "2010-02-23T11:42:12Z")

</div>

I’ve cleaned up a patch to allow semi transparent windows with juce.

[attachment=1]argb32.png[/attachment]

At the time, i’ve only implemented a more organic way to obtain 32bit argb Visuals if they are present (if there is a composition manager like compiz, xcompmgr, or metacity compositing running) thru the Xrender extension. If not, or a window is not translucent, the fallback mode of 24/16it is preserved. Actually this feature is enabled only if XSHM extension is enabled: it should be possible to use ARGB32 images with XPutImage too (and not only in companion with XSHM), but from my tests i was getting a huge load of BadMatch in trying to do so. So for now the patch is available only if you are using XSHM.

the only drawback is that we will lose the transparent background of the window if we overwrite it with a translucent one repeatedly (like the drag-me-to-desktop-translucent-component in the jucedemo):

[attachment=0]argb32\_bad.png[/attachment]

If you look at the desktop component, it leaves trails of the old paint (but it is translucent). Maybe it’s a problem of premultiplying the alpha before blitting ? I don’t know here. Probably i should take care of introducing the Xcomposite extension in the field, so to have a better control over composition of old window background and the new translucent one.

Anyway, to enable the patch only define this:

` #define JUCE_USE_XSHM 1
  #define JUCE_USE_XRENDER 1 `

And no other linking library (all is done transparently).

Since this is extremely experimental, i need people to test this over more distros as possible and report feedback, and if anyone would like to contribute with code it will be appreciated cause translucent windows is possible on linux, we only need to teach juce to do so !

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 23, 2010, 2:14pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/2 "2010-02-23T14:14:21Z")

</div>

awesome… I’ll take a look asap!

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [March 6, 2010, 4:44pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/3 "2010-03-06T16:44:31Z")

</div>

Kraken, just to make sure, do you erase the background of the window before painting it ?  
Or is it a simple “XOR” like hack ?

(I don’t get the basic idea about the implementation)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2010, 11:50am UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/4 "2010-03-08T11:50:10Z")

</div>

Just having a go with this - where do I get the Xcomposition.h header from? Can’t seem to find any packages that contain it (?)

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 2:01pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/5 "2010-03-08T14:01:16Z")

</div>

the idea is only to obtain a 32bit Visual from X11 and use that for all subsequent drawing operation, instead of forcing the use of 24/16 bit visuals.

the problem is that we need to get the window backing store and clear the actual content of the window, probably using XRenderComposite with an operation of PictOpSrc (the destination pixels should be replaced with the source pixels) or getting the window back pixmap with XCompositeNameWindowPixmap and clear that (but i don’t know if it will work simply clearing it).

There is some more info [here](http://ktown.kde.org/~fredrik/composite_howto.html), i will try some options and see what i come up with when i have some time .

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 2:02pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/6 "2010-03-08T14:02:55Z")

</div>

> [@jules](#):
>
> Just having a go with this - where do I get the Xcomposition.h header from? Can’t seem to find any packages that contain it (?)

libxcomposite-dev maybe ? i don’t have a debian system to test it but i found it by googleing

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2010, 2:05pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/7 "2010-03-08T14:05:37Z")

</div>

I’ve merged in your code and will check it in shortly (disabled)

But I couldn’t actually try it, because I can’t find a copy of Xcomposite.h?!

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 2:06pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/8 "2010-03-08T14:06:58Z")

</div>

to ease the test you can enable metacity composition by doing like this, instead of installing a complex composition manager like compiz, or using xcompmgr.

```auto
gconftool-2 -s '/apps/metacity/general/compositing_manager' --type bool true
```

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 2:11pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/9 "2010-03-08T14:11:00Z")

</div>

[quote=“jules”]I’ve merged in your code and will check it in shortly (disabled)

But I couldn’t actually try it, because I can’t find a copy of Xcomposite.h?![/quote]

have you tried doing apt-get install libxcomposite-dev ?

[http://packages.debian.org/etch/i386/libxcomposite-dev/filelist](http://packages.debian.org/etch/i386/libxcomposite-dev/filelist)

```auto
Filelist of package libxcomposite-dev in etch of architecture i386

/usr/include/X11/extensions/Xcomposite.h
/usr/lib/libXcomposite.a
/usr/lib/libXcomposite.so
/usr/lib/pkgconfig/xcomposite.pc
/usr/share/doc/libxcomposite-dev/changelog.Debian.gz
/usr/share/doc/libxcomposite-dev/copyright
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2010, 2:32pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/10 "2010-03-08T14:32:16Z")

</div>

Ok, got it working now - seems pretty good! I’ve fixed the problem with the trails, it just needed to clear the image before drawing.

Any idea how you’d tell it to turn off the drop-shadow for a window?

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 2:37pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/11 "2010-03-08T14:37:35Z")

</div>

i’ve tried some options, it seems it is dependent on the window manager on how to treat the window, based on window hints.

i’ve read carefully the detailed description here, but i’m still trying to figure out the correct hints to give to temporary windows ( \_NET\_WM\_WINDOW\_TYPE ):

[http://standards.freedesktop.org/wm-spec/wm-spec-latest.html](http://standards.freedesktop.org/wm-spec/wm-spec-latest.html)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2010, 2:54pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/12 "2010-03-08T14:54:34Z")

</div>

Can’t find anything at all about shadow hints - I’m going to check in what I’ve got, and can fine-tune it later…

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 3:08pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/13 "2010-03-08T15:08:11Z")

</div>

> [@jules](#):
>
> Can’t find anything at all about shadow hints - I’m going to check in what I’ve got, and can fine-tune it later…

no there is nothing about a shadow hint. typically window managers ignore the drop shadow for \_NET\_WM\_WINDOW\_TYPE\_NOTIFICATION type windows (\_NET\_WM\_WINDOW\_TYPE), but there is nothing sure out there (they can even ignore it) . also making those window ignore the taskbar with \_NET\_WM\_STATE\_SKIP\_TASKBAR as \_NET\_WM\_STATE\_SKIP\_TASKBAR may be of help… but i always failed, sometimes it always put the shadow, some other times the wm do not.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 8, 2010, 3:28pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/14 "2010-03-08T15:28:25Z")

</div>

How annoying… I can’t believe they’d add the drop-shadows and not add a flag to control it!

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [March 8, 2010, 4:07pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/15 "2010-03-08T16:07:28Z")

</div>

How about \_NET\_WM\_WINDOW\_TYPE\_COMBO ? I’ve never seen a combo box type with a drop shadow, as it might cover the initial edit box.  
While I say this, I’ve never tested this.

---

<div class="post-metadata">

**Author:** ![X-Ryl669](https://avatars.discourse-cdn.com/v4/letter/x/a5b964/32.png) [@X-Ryl669](https://forum.juce.com/u/X-Ryl669)\
**Post date:** [March 8, 2010, 4:24pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/16 "2010-03-08T16:24:09Z")

</div>

I’ve looked at Enlightenment window manager, and clearly the test to enable shadow is:  
if (window is shaped or window doesn’t have a border) then disable shadow.  
So either you set a 0 pixel border or you set the shape of the window (with XShape and a single rectangle in the list: XShapeCombineRectangles)

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 4:37pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/17 "2010-03-08T16:37:31Z")

</div>

> [@jules](#):
>
> How annoying… I can’t believe they’d add the drop-shadows and not add a flag to control it!

yes you are right, actually it works pretty good apart that when i drag the jucedemo’s transparent widget to the desktop it has the drop shadow 2 times out of 5… probably we should play with window type and state to make it work like we need.

[quote=“X-Ryl669”]I’ve looked at Enlightenment window manager, and clearly the test to enable shadow is:  
if (window is shaped or window doesn’t have a border) then disable shadow.  
So either you set a 0 pixel border or you set the shape of the window (with XShape and a single rectangle in the list: XShapeCombineRectangles)[/quote]

you spotted the right path, i’ve double checked metacity and its compositor checks for shaped windows and for specially typed windows that are not menus or drag and drop.

[http://people.gnome.org/~tthurman/docs/metacity/compositor-xrender\_8c-source.html#l00888](http://people.gnome.org/~tthurman/docs/metacity/compositor-xrender_8c-source.html#l00888)

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 9:16pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/18 "2010-03-08T21:16:04Z")

</div>

[quote=“X-Ryl669”]I’ve looked at Enlightenment window manager, and clearly the test to enable shadow is:  
if (window is shaped or window doesn’t have a border) then disable shadow.  
So either you set a 0 pixel border or you set the shape of the window (with XShape and a single rectangle in the list: XShapeCombineRectangles)[/quote]

hey i was totally wrong. you spotted the right path, i’ve double checked metacity and its compositor checks for shaped windows and for specially typed windows that are not menus or drag and drop.

[http://people.gnome.org/~tthurman/docs/metacity/compositor-xrender\_8c-source.html#l00888](http://people.gnome.org/~tthurman/docs/metacity/compositor-xrender_8c-source.html#l00888)

---

<div class="post-metadata">

**Author:** ![kunitoki](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kunitoki/32/15_2.png) [@kunitoki](https://forum.juce.com/u/kunitoki)\
**Post date:** [March 8, 2010, 11:01pm UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/19 "2010-03-08T23:01:44Z")

</div>

well, i actually managed to get the drop shadow “on demand”, and without using the Xshape extension 🙂

try this cleanup !

ps. i’m still trying to understand how to properly use the \_NET\_WM\_STATE\_SKIP\_TASKBAR hint. it seems it is ignored !

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 9, 2010, 10:57am UTC](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012/20 "2010-03-09T10:57:15Z")

</div>

Cool - seems to work! I’ve checked that in now (and did a bit of tidying up of some of the older code in that file)

[Next page](https://forum.juce.com/t/semi-transparent-windows-first-draft/11012.md?page=2)
