effects/screenshot: Provide information about captured window or screen

This can be useful for the screenshot capture tool if it needs some
information about the captured window or screen, for example to generate
the file name.
This commit is contained in:
Vlad Zahorodnii 2023-03-17 17:12:08 +02:00
parent 5e63f9afc9
commit 1b1f0c6b32
2 changed files with 56 additions and 5 deletions

View file

@ -53,6 +53,8 @@
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
* "windowId" (s): The window id of the captured window. Available
since version 4.
-->
<method name="CaptureWindow">
<arg name="handle" type="s" direction="in" />
@ -96,6 +98,8 @@
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
* "windowId" (s): The window id of the captured window. Available
since version 4.
-->
<method name="CaptureActiveWindow">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap" />
@ -181,6 +185,8 @@
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
* "screen" (s): The name of the captured screen, same as QScreen::name().
Available since version 4
-->
<method name="CaptureScreen">
<arg name="name" type="s" direction="in" />
@ -222,6 +228,8 @@
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
* "screen" (s): The name of the captured screen, same as QScreen::name().
Available since version 4
-->
<method name="CaptureActiveScreen">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap" />
@ -260,6 +268,16 @@
image type is "raw"
* "format" (u): The image format, as defined in QImage::Format.
Available only if the image type is "raw"
The following results get returned when taking a window screenshot:
* "windowId" (s): The window id of the captured window. Available
since version 4
The following results get returned when taking a monitor screenshot:
* "screen" (s): The name of the captured screen, same as QScreen::name().
Available since version 4
-->
<method name="CaptureInteractive">
<arg name="kind" type="u" direction="in" />

View file

@ -133,6 +133,8 @@ public:
bool isCompleted() const;
void marshal(ScreenShotSinkPipe2 *sink);
virtual QVariantMap attributes() const;
Q_SIGNALS:
void cancelled();
void completed();
@ -148,6 +150,11 @@ class ScreenShotSourceScreen2 : public ScreenShotSource2
public:
ScreenShotSourceScreen2(ScreenShotEffect *effect, EffectScreen *screen, ScreenShotFlags flags);
QVariantMap attributes() const override;
private:
EffectScreen *m_screen;
};
class ScreenShotSourceArea2 : public ScreenShotSource2
@ -164,6 +171,11 @@ class ScreenShotSourceWindow2 : public ScreenShotSource2
public:
ScreenShotSourceWindow2(ScreenShotEffect *effect, EffectWindow *window, ScreenShotFlags flags);
QVariantMap attributes() const override;
private:
EffectWindow *m_window;
};
class ScreenShotSinkPipe2 : public QObject
@ -174,7 +186,7 @@ public:
ScreenShotSinkPipe2(int fileDescriptor, QDBusMessage replyMessage);
void cancel();
void flush(const QImage &image);
void flush(const QImage &image, const QVariantMap &attributes);
private:
QDBusMessage m_replyMessage;
@ -200,18 +212,31 @@ bool ScreenShotSource2::isCompleted() const
return m_future.isFinished();
}
QVariantMap ScreenShotSource2::attributes() const
{
return QVariantMap();
}
void ScreenShotSource2::marshal(ScreenShotSinkPipe2 *sink)
{
sink->flush(m_future.result());
sink->flush(m_future.result(), attributes());
}
ScreenShotSourceScreen2::ScreenShotSourceScreen2(ScreenShotEffect *effect,
EffectScreen *screen,
ScreenShotFlags flags)
: ScreenShotSource2(effect->scheduleScreenShot(screen, flags))
, m_screen(screen)
{
}
QVariantMap ScreenShotSourceScreen2::attributes() const
{
return QVariantMap{
{QStringLiteral("screen"), m_screen->name()},
};
}
ScreenShotSourceArea2::ScreenShotSourceArea2(ScreenShotEffect *effect,
const QRect &area,
ScreenShotFlags flags)
@ -223,9 +248,17 @@ ScreenShotSourceWindow2::ScreenShotSourceWindow2(ScreenShotEffect *effect,
EffectWindow *window,
ScreenShotFlags flags)
: ScreenShotSource2(effect->scheduleScreenShot(window, flags))
, m_window(window)
{
}
QVariantMap ScreenShotSourceWindow2::attributes() const
{
return QVariantMap{
{QStringLiteral("windowId"), m_window->internalId().toString()},
};
}
ScreenShotSinkPipe2::ScreenShotSinkPipe2(int fileDescriptor, QDBusMessage replyMessage)
: m_replyMessage(replyMessage)
, m_fileDescriptor(fileDescriptor)
@ -238,14 +271,14 @@ void ScreenShotSinkPipe2::cancel()
s_errorCancelledMessage));
}
void ScreenShotSinkPipe2::flush(const QImage &image)
void ScreenShotSinkPipe2::flush(const QImage &image, const QVariantMap &attributes)
{
if (!m_fileDescriptor.isValid()) {
return;
}
// Note that the type of the data stored in the vardict matters. Be careful.
QVariantMap results;
QVariantMap results = attributes;
results.insert(QStringLiteral("type"), QStringLiteral("raw"));
results.insert(QStringLiteral("format"), quint32(image.format()));
results.insert(QStringLiteral("width"), quint32(image.width()));
@ -278,7 +311,7 @@ ScreenShotDBusInterface2::~ScreenShotDBusInterface2()
int ScreenShotDBusInterface2::version() const
{
return 3;
return 4;
}
bool ScreenShotDBusInterface2::checkPermissions() const