Add Screenshot implementation for KDE/Wayland
@Jehan
Submitted by Jehan Link to original bug (#791360)
Description
KDE provides also a dbus API for screenshots. Of course screenshots on KDE/X11 stills works right now, but we need to use the API for KDE/Wayland.
I have been in contact with the KDE developer (Martin Flöser) who gave me info on the interface:
Sorry that we don't have an xml description of the protocol. I'll try to reverse engineer one. We are a little bit too pampered by Qt which can generate the API from a class.
Service: org.kde.KWin Object: /Screenshot Interface: org.kde.kwin.Screenshot
There are several methods for different features:
- interactive (fd, mask)
- interactive (fd)
- screenshotFullscreen (fd, bool)
- screenshotFullscreen (fd)
- screenshotScreen(fd, bool)
- screenshotScreen(fd)
The interactive allows to screenshot a window which the user can select, the argument mask is:
- Include window decoration (1 << 0)
- include cursor (1 << 1)
The variant without mask is both bits not set.
The screenshotFullscreen takes a screenshot of all screens. The (optional) boolean is whether to include mouse cursor. The screenshotScreen allows to let the user click on a screen to capture in a multi screen setup. The bool is whether to include mouse cursor.
[…]
Again, RGB or ARGB? :-)
Yes, ARGB - important for window capture mode.
[…]
Also are you saying the result is just an array of unsigned ints? If
so, what are the width/height of the image to reconstruct it? It's a bit hard to see this in the code. :-/
I have no idea how the data is transferred. Once again we use Qt functionality and use a QDataStream to write a QImage and use a QDataStream to read back the QImage. Qt guarantees that this works. It was three lines of code to transfer the image without having to worry about any protocols.
Qt's documentation says: "Writes the given image to the given stream as a PNG image, or as a BMP image if the stream's version is 1. Note that writing the stream to a file will not produce a valid image file."
How exactly that works internally is something I would have to look into the Qt implementation.
Let's try and see if we could implement this for 2.10. How the output is to be used is still a bit fuzzy right now as one can see, since Qt apps just get it as a QImage but apparently we should be able to get it as raw data as well. Here how a Qt application makes a screenshot with the API: https://cgit.kde.org/spectacle.git/tree/src/PlatformBackends/KWinWaylandImageGrabber.cpp
Version: git master