Transparent background under Linux?

274 views
Skip to first unread message

Adam Avramov

unread,
Aug 7, 2014, 3:17:15 AM8/7/14
to cefp...@googlegroups.com
Hello everyone! I've seen some great, albeit Windows-specific hacks here for applying different modes of transparency modes on a CEFPython window. Has anyone managed to do the same under Linux? I'm mostly interested in getting a transparent background (e.g. color key). Would love to see some examples for that.

Cheers,
Adam

Czarek Tomczak

unread,
Aug 7, 2014, 4:45:18 AM8/7/14
to cefp...@googlegroups.com
Call WindowInfo.SetTransparentPainting(True). There was a bug in docs, on the WindowInfo wiki page saying that SetTransparentPainting was only available on Windows and that it wasn't implemented in CEF Python 3. This is not true anymore in the latest CEF 31.0.

Adam Avramov

unread,
Aug 7, 2014, 5:32:50 AM8/7/14
to cefp...@googlegroups.com
Excellent. Is there anything else I need to do, though? I'm calling that method in my code (based on the wxPython demo), and I have body { background: transparent } set in my document, but I still can't see the transparency working.

Czarek Tomczak

unread,
Aug 7, 2014, 11:20:36 AM8/7/14
to
Transparency was set for the CEF inner window. You still have to set transparency for the host window. Try google "wxpython transparent window", numerous examples appear.

Adam Avramov

unread,
Aug 7, 2014, 12:17:34 PM8/7/14
to cefp...@googlegroups.com
Ok, that's good. Can't seem to find a resource about transparent backgrounds in wxPython that makes me happy though -- most of my findings make me think I need to use one wx.SHAPED_WINDOW and get my own transparency mask for it, too - presumably via something from RenderHandler?

Czarek Tomczak

unread,
Aug 7, 2014, 2:23:13 PM8/7/14
to
This might be a bug in wxPython on Linux. Most of the examples found through google are for Windows. Found Issue 13240 in wxwidgets tracker, that reports transparent windows not working in some scenarios. I've tested calling SetTransparent before running main loop, but it still didn't work.

I got transparent window with CEF browser working fine in the pygtk_.py example that is available in CEF 31.0. Tested on Ubuntu 12.04. Here is the diff:

--- a/cefpython/cef3/linux/binaries_64bit/pygtk_.py
+++ b/cefpython/cef3/linux/binaries_64bit/pygtk_.py
@@ -94,6 +94,7 @@ class PyGTKExample:
         
self.mainWindow.set_size_request(width=800, height=600)
         
self.mainWindow.set_title('PyGTK CEF example')
         
self.mainWindow.realize()
+        self.mainWindow.set_opacity(0.5)
 
         
self.vbox = gtk.VBox(False, 0)
         
self.vbox.pack_start(self.CreateMenu(), False, False, 0)
@@ -104,6 +105,7 @@ class PyGTKExample:
         windowID
= int(hexID, 16)
 
         windowInfo
= cefpython.WindowInfo()
+        windowInfo.SetTransparentPainting(True)
         windowInfo
.SetAsChild(windowID)
         
# Linux requires adding "file://" for local files,
         
# otherwise /home/some will be replaced as http://home/some

Adam Avramov

unread,
Aug 7, 2014, 3:50:56 PM8/7/14
to cefp...@googlegroups.com
That doesn't work for me since I only have the python-cefpython3 package, not sure if I'm supposed to have have cefpython1 alongside it? Also set_opacity looks like a transparent/translucent window rather than the completely transparent background I'm looking for (ostensibly by masking, though I'd be happier with an alpha channel). I'm looking for irregular-shaped windows, also possibly with dimensions that can fit to the size of a contained HTML element. I might eventually just use fake transparency, such as used by e.g. Conky, the kind that uses a screenshot of your root window as window background, but if there's a better way to get a transparent background I'd like to find out what it is...

Czarek Tomczak

unread,
Aug 7, 2014, 4:05:11 PM8/7/14
to cefp...@googlegroups.com
If you've installed debian package, then examples can be found in:
/usr/lib/pymodules/python2.7/cefpython3/examples/

Adam Avramov

unread,
Aug 7, 2014, 4:05:41 PM8/7/14
to cefp...@googlegroups.com
Found the correct file, sorry. Applied your changes, but all I got was the same opaque white background. By the way, I'm running a lightweight xmonad desktop; window transparency wouldn't depend on a compositing window manager, would it?

Czarek Tomczak

unread,
Aug 7, 2014, 4:09:26 PM8/7/14
to cefp...@googlegroups.com
See http://www.wxpython.org/docs/api/wx.Window-class.html#CanSetTransparent
It says something about a composite manager program being required.

Adam Avramov

unread,
Aug 8, 2014, 6:13:05 AM8/8/14
to cefp...@googlegroups.com
Okay, fair enough. What about achieving opaque controls on a transparent background, then?

Czarek Tomczak

unread,
Aug 9, 2014, 1:34:02 AM8/9/14
to cefp...@googlegroups.com
On Friday, August 8, 2014 12:13:05 PM UTC+2, Adam Avramov wrote:
Okay, fair enough. What about achieving opaque controls on a transparent background, then?

Reply all
Reply to author
Forward
0 new messages