Use KWin effect to grab also alpha channel in KSnapshot

Review Request #4814 - Created Aug. 1, 2010 and submitted

Martin Gräßlin
aseigo, rich
This patch makes KSnapshot use KWin's new Screenshot effect to create screenshots of windows. The screenshot effect uses an offscreen OpenGL framebuffer object and renders the window including the decoration shadow (glow) into this framebuffer object. This allows to only get the window (without other windows on top) and the alpha channel and of course the shadow.

I decided to use DBus instead of passing around X properties as I think it is the more convenient API and easier to understand. Especially the introspection is quite handy in this case as it allows to test if the screenshot effect is available. As the screenshot is captured during KWin's next rendering pass, I decided to use the backfiring signal instead of using a blocking DBus call.

If this approach is acceptable I will extend the screenshot effect to support not including the decoration.

KSnapshot is currently not able to handle the alpha channel in the preview. Translucent pixels are black. When saving everything is fine (see attached screenshot). If I get directions I will have a look at it :-) It might also be an idea to check the availability of the screenshot effect before taking the screenshot and a fallback if the DBus connection fails.

Martin Gräßlin
Aaron Seigo
Martin Gräßlin
Martin Gräßlin
Review request changed

Change Summary:

remove black background behind the transparent area caused by the black blurred area in the preview (see new attached screenshot).

There is one thing I need to add that is a fallback when KWin cannot grab the screenshot which is not that unlikely as the effect uses framebuffer objects which are maybe supported in current mesa drivers. So kwin will first notice that it does not work when it is tried to grab a screenshot. My idea to solve this problem is to return a null pixmap handle and use the normal grab code in ksnapshot in that case.

Nevertheless I would like to submit the changes so far :-)


Revision 3 (+158 -37)

Show changes

Aaron Seigo
other than the indentation issues in the ksnapshot bits of the code, i'm cool with it :)
trunk/KDE/kdegraphics/ksnapshot/ksnapshot.cpp (Diff revision 3)
sould be:

if (foo) 

not kwin style indenting here :)