effects/screenshot: Add org.kde.KWin.ScreenShot2.CaptureActiveWindow

BUG: 386271
This commit is contained in:
Vlad Zahorodnii 2021-10-29 11:55:10 +03:00
parent 5379b010b4
commit b135a1c7b0
3 changed files with 70 additions and 0 deletions

View file

@ -63,6 +63,48 @@
<arg name="results" type="a{sv}" direction="out" />
</method>
<!--
CaptureActiveWindow:
@options: Optional vardict with screenshot options
@pipe: The pipe file descriptor where the screenshot will be written
Take a screenshot of the active window. The application that
requests the screenshot must have the org.kde.KWin.ScreenShot2
interface listed in the X-KDE-DBUS-Restricted-Interfaces desktop
file entry.
Supported since version 2.
Available @options include:
* "include-cursor" (b): Whether the cursor should be included.
Defaults to false
* "include-decoration" (b): Whether the decoration should be included.
Defaults to false
* "native-resolution" (b): Whether the screenshot should be in
native size. Defaults to false
The following results get returned via the @results vardict:
* "type" (s): The type of the image written to the pipe. Currently,
the only supported type is "raw"
* "width" (u): The width of the image. Available only if the image
type is "raw"
* "height" (u): The height of the image. Available only if the image
type is "raw"
* "stride" (u): The number of bytes per row. Available only if the
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
-->
<method name="CaptureActiveWindow">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap" />
<arg name="options" type="a{sv}" direction="in" />
<arg name="pipe" type="h" direction="in" />
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap" />
<arg name="results" type="a{sv}" direction="out" />
</method>
<!--
CaptureArea:
@x: The x coordinate of the upper left corner of the area

View file

@ -299,6 +299,32 @@ bool ScreenShotDBusInterface2::checkPermissions() const
return true;
}
QVariantMap ScreenShotDBusInterface2::CaptureActiveWindow(const QVariantMap &options,
QDBusUnixFileDescriptor pipe)
{
if (!checkPermissions()) {
return QVariantMap();
}
EffectWindow *window = effects->activeWindow();
if (!window) {
sendErrorReply(s_errorInvalidWindow, s_errorInvalidWindowMessage);
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
}
takeScreenShot(window, screenShotFlagsFromOptions(options),
new ScreenShotSinkPipe2(fileDescriptor, message()));
setDelayedReply(true);
return QVariantMap();
}
QVariantMap ScreenShotDBusInterface2::CaptureWindow(const QString &handle,
const QVariantMap &options,
QDBusUnixFileDescriptor pipe)

View file

@ -42,6 +42,8 @@ public:
public Q_SLOTS:
QVariantMap CaptureWindow(const QString &handle, const QVariantMap &options,
QDBusUnixFileDescriptor pipe);
QVariantMap CaptureActiveWindow(const QVariantMap &options,
QDBusUnixFileDescriptor pipe);
QVariantMap CaptureArea(int x, int y, int width, int height,
const QVariantMap &options,
QDBusUnixFileDescriptor pipe);