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

The new method can be used to implement the "Current Screen" capture
mode in Spectacle.
This commit is contained in:
Vlad Zahorodnii 2021-10-30 19:11:13 +03:00
parent d1b2a0e4d4
commit cd018b6ba3
3 changed files with 68 additions and 0 deletions

View file

@ -191,6 +191,46 @@
<arg name="results" type="a{sv}" direction="out" />
</method>
<!--
CaptureActiveScreen:
@options: Optional vardict with screenshot options
@pipe: The pipe file descriptor where the screenshot will be written
Take a screenshot of the active monitor. 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
* "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="CaptureActiveScreen">
<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>
<!--
CaptureInteractive:
@kind: 0 - window, 1 - screen

View file

@ -415,6 +415,32 @@ QVariantMap ScreenShotDBusInterface2::CaptureScreen(const QString &name,
return QVariantMap();
}
QVariantMap ScreenShotDBusInterface2::CaptureActiveScreen(const QVariantMap &options,
QDBusUnixFileDescriptor pipe)
{
if (!checkPermissions()) {
return QVariantMap();
}
EffectScreen *screen = effects->activeScreen();
if (!screen) {
sendErrorReply(s_errorInvalidScreen, s_errorInvalidScreenMessage);
return QVariantMap();
}
const int fileDescriptor = dup(pipe.fileDescriptor());
if (fileDescriptor == -1) {
sendErrorReply(s_errorFileDescriptor, s_errorFileDescriptorMessage);
return QVariantMap();
}
takeScreenShot(screen, screenShotFlagsFromOptions(options),
new ScreenShotSinkPipe2(fileDescriptor, message()));
setDelayedReply(true);
return QVariantMap();
}
QVariantMap ScreenShotDBusInterface2::CaptureInteractive(uint kind,
const QVariantMap &options,
QDBusUnixFileDescriptor pipe)

View file

@ -49,6 +49,8 @@ public Q_SLOTS:
QDBusUnixFileDescriptor pipe);
QVariantMap CaptureScreen(const QString &name, const QVariantMap &options,
QDBusUnixFileDescriptor pipe);
QVariantMap CaptureActiveScreen(const QVariantMap &options,
QDBusUnixFileDescriptor pipe);
QVariantMap CaptureInteractive(uint kind, const QVariantMap &options,
QDBusUnixFileDescriptor pipe);