Windows with transparent backgrounds

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
ProgRob
Posts: 67
Joined: Wed 13 Feb 2013, 12:39

Windows with transparent backgrounds

#1 Post by ProgRob »

For a project I am learning Genie. I want to create a window where the background is transparent but the widgets visible in it are opaque.

The problem I am having is that in Puppy Linux I cannot get a transparent background!

Here is my code:

Code: Select all

uses
        Gtk
        Cairo

def on_expose (wid : Widget, event : Gdk.EventExpose) : bool
        // Get a cairo context for our window
        var ctx = Gdk.cairo_create (wid.window)
        // This should make the current color transparent (a = 0)
        ctx.set_source_rgba (1, 1, 1, 0)
        // Paint the entire window transparent to start with.
        ctx.set_operator (Cairo.Operator.SOURCE)
        ctx.paint ()
        // Draw circle
        var pat = new Cairo.Pattern.radial (75, 75, 20, 100,  100, 75)
        pat.add_color_stop_rgba (0, 1, 1, 1, 1)
        pat.add_color_stop_rgba (1, 0, 0, 0, 1)
        ctx.set_source (pat)
        ctx.arc (100, 100, 175, 0, 2 * 3.1416)
        ctx.fill ()
        return true

init
        Gtk.init (ref args)

        var window = new Gtk.Window
        window.title = "Demo window"
        window.set_default_size (200,200)
        window.app_paintable = true
        var cm = window.screen.get_rgba_colormap()
        window.set_colormap(cm)
        window.expose_event.connect(on_expose)
        window.destroy.connect (Gtk.main_quit)
        window.show_all ()
 
        Gtk.main ()
When I run this it shows a black background rather than a transparent one. I am running xcompmgr as well which makes non-active windows transparent so some kind of transparency is possible.

Can anyone guide me as to what I am doing wrong as I am pretty new to all this Cairo/GTK etc.?

Thanks,
Rob

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Hello, ProgRob.

I don't know anything about Genie. That said...

Your program may be showing the background, not the ROX backdrop, but the system
background, which is indeed black. Same thing happens in conky if you use the
"transparent", "own window" and "normal" settings. It is little known, but you can have
a "hierarchy" of backgrounds, which are used at different levels of the Linux system.

For example, if you try

Code: Select all

urxvt -bg sienna4 -fg cornsilk -bd firebrick4 -b 4 -tr -tint white -sh 67 -cr white
the "-tr -tint white -sh 67" settings will allow the ROX background to seep through, with
a shade of white. Not so with conky, because conky, when its "own window" is set to
"normal", is looking at the system background, not at the ROX background.

In your case, I believe that you may need to introduce your same background earlier,
in the .initrc code, through a program such as qiv. See attached illustration. For your
transparency to work, my hunch is that the picture called by qiv (line 107) should be the
same as the one used by ROX. Also, please note that the addition needs to go just
below the xsetroot call.

Again, I don't know anything about Genie, but I hope this helps. Keep us posted?

BFN.

musher0
Attachments
initrc-with-qiv-added.jpg
(40.8 KiB) Downloaded 602 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#3 Post by Ted Dog »

Thanks for clearing that up I wondered why a wallpaper mode for video playback has sound and no picture. video hidden behind rox background. Can we drop that or make it transparent¿

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#4 Post by musher0 »

Ted Dog wrote:Thanks for clearing that up I wondered why a wallpaper mode for video playback has sound and no picture. video hidden behind rox background. Can we drop that or make it transparent¿
Hi, Ted.

That sounds like a logical explanation, but I can't help you there: I know zero in video stuff.
I wouldn't know which layer the video playback uses.

Stick around though, somebody's bound to answer! :)

BFN.

musher0
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

#5 Post by Ted Dog »

root or base layer. Had it working on v4 series and forgot about that until I tried it a week or so ago when I saw the settings in VLC and hunted it down for mplayer. both did the same...

ProgRob
Posts: 67
Joined: Wed 13 Feb 2013, 12:39

#6 Post by ProgRob »

Thanks Musher for the advice. I agree with you that this is not a Genie question. I think this is more about understanding how GTK+ works on Puppy.

So, here is the result of my investigations so far and they are weird. Firstly some corrected code, though, as there was an error in the original.

Code: Select all

def on_expose (wid : Widget, event : Gdk.EventExpose) : bool
        var ctx = Gdk.cairo_create (wid.window)
        ctx.set_source_rgba(0, 0, 1, 0)
        ctx.set_operator (Cairo.Operator.SOURCE)
        ctx.paint ()
        var pat = new Cairo.Pattern.radial (75, 75, 20, 100,  100, 75)
        pat.add_color_stop_rgba (0, 1, 1, 0, 1)
        pat.add_color_stop_rgba (1, 1, 0, 0, 1)
        ctx.set_source (pat)
        ctx.arc (100, 100, 75, 0, 2 * 3.1416)
        ctx.fill ()
        return true

init
        Gtk.init (ref args)

        var window = new Gtk.Window()
        window.title = "Demo window"
        window.set_default_size (200,200)
        window.app_paintable = true
        var cm = window.screen.get_rgba_colormap()
        window.set_colormap(cm)
        window.expose_event.connect(on_expose)
        window.destroy.connect (Gtk.main_quit)
        window.show_all ()
 
        Gtk.main ()
So I have tried the following to see what is going on:

1. I modified the third line in the code above (set_source_rgba) so that the last parameter, the alpha value, was 1. This successfully painted the background a nice blue colour - this shows my code seems to be setting the background to something and that the alpha channel makes a difference.

2. I then set the alpha value on the same line to 0.5. The background became a darker blue - as if the black and blue were being merged. Exactly what you would expect if composition is taking place and the alpha channel was working but the background was black.

3. Next I switched off composition and switched off the Rox filer pinboard. This showed me a black background - exactly what Musher predicted

4. I then switched on xcompmgr and the background turned grey - this is really strange as this means that having composition switched on is affecting the black background beneath the Rox pinboard.

5. I then switched off xcompmgr and modified my .xinitrc file as suggested. Rebooting X gave me the same background as the Rox filer background (except without the icons). Again as expected.

6. I then switched on composition and the background turned grey (not a composited version of the background image but the same grey as in step 4). That I was not expecting.

7. Then I tried running my code - and it continued to give the same black background whether or not the pinboard was showing.

All of the above is very strange. Why does the image set with qiv disappear when composition is turned on? What is the black background being composited with to create the grey? And, why is my code still getting a black background even when I paint the background with an image?

One other oddity is that when I run xcompmgr and I have switched off the pinboard, if I move a window around I cannot see the outline of the window unless I move it over another window. The grey background seems to hide the outline.

Anyone got any further suggestions?

Thanks,
Rob

Post Reply