Commit 9db9ace4 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Add support for Active Window mode on Wayland

BUG: 386271
parent 13f0a353
......@@ -181,6 +181,11 @@ ScreenShotSourceScreen2::ScreenShotSourceScreen2(const QScreen *screen, Platform
{
}
ScreenShotSourceActiveWindow2::ScreenShotSourceActiveWindow2(PlatformKWinWayland2::ScreenShotFlags flags)
: ScreenShotSource2(QStringLiteral("CaptureActiveWindow"), screenShotFlagsToVardict(flags))
{
}
ScreenShotSourceMeta2::ScreenShotSourceMeta2(const QVector<ScreenShotSource2 *> &sources)
: m_sources(sources)
{
......@@ -228,6 +233,16 @@ std::unique_ptr<PlatformKWinWayland2> PlatformKWinWayland2::create()
PlatformKWinWayland2::PlatformKWinWayland2(QObject *parent)
: Platform(parent)
{
auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin.ScreenShot2"),
QStringLiteral("/org/kde/KWin/ScreenShot2"),
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("Get"));
message.setArguments({QStringLiteral("org.kde.KWin.ScreenShot2"), QStringLiteral("Version")});
const QDBusMessage reply = QDBusConnection::sessionBus().call(message);
if (reply.type() == QDBusMessage::ReplyMessage) {
m_apiVersion = reply.arguments().constFirst().value<QDBusVariant>().variant().toUInt();
}
}
QString PlatformKWinWayland2::platformName() const
......@@ -239,6 +254,10 @@ Platform::GrabModes PlatformKWinWayland2::supportedGrabModes() const
{
Platform::GrabModes supportedModes = GrabMode::AllScreens | GrabMode::WindowUnderCursor | GrabMode::PerScreenImageNative | GrabMode::AllScreensScaled;
if (m_apiVersion >= 2) {
supportedModes |= GrabMode::ActiveWindow;
}
const QList<QScreen *> screens = QGuiApplication::screens();
if (screens.count() > 1) {
supportedModes |= GrabMode::CurrentScreen;
......@@ -281,6 +300,9 @@ void PlatformKWinWayland2::doGrab(ShutterMode, GrabMode theGrabMode, bool theInc
case GrabMode::CurrentScreen:
takeScreenShotInteractive(InteractiveKind::Screen, flags);
break;
case GrabMode::ActiveWindow:
takeScreenShotActiveWindow(flags);
break;
case GrabMode::WindowUnderCursor:
takeScreenShotInteractive(InteractiveKind::Window, flags);
break;
......@@ -293,7 +315,6 @@ void PlatformKWinWayland2::doGrab(ShutterMode, GrabMode theGrabMode, bool theInc
case GrabMode::InvalidChoice:
case GrabMode::TransientWithParent:
case GrabMode::ActiveWindow:
Q_EMIT newScreenshotFailed();
break;
}
......@@ -333,6 +354,11 @@ void PlatformKWinWayland2::takeScreenShotInteractive(InteractiveKind kind, Scree
trackSource(new ScreenShotSourceInteractive2(kind, flags));
}
void PlatformKWinWayland2::takeScreenShotActiveWindow(ScreenShotFlags flags)
{
trackSource(new ScreenShotSourceActiveWindow2(flags));
}
void PlatformKWinWayland2::takeScreenShotScreens(const QList<QScreen *> &screens, ScreenShotFlags flags)
{
QVector<ScreenShotSource2 *> sources;
......
......@@ -52,9 +52,12 @@ private:
void takeScreenShotInteractive(InteractiveKind kind, ScreenShotFlags flags);
void takeScreenShotArea(const QRect &area, ScreenShotFlags flags);
void takeScreenShotScreens(const QList<QScreen *> &screens, ScreenShotFlags flags);
void takeScreenShotActiveWindow(ScreenShotFlags flags);
void trackSource(ScreenShotSource2 *source);
void trackSource(ScreenShotSourceMeta2 *source);
int m_apiVersion = 1;
};
/**
......@@ -121,6 +124,18 @@ public:
ScreenShotSourceScreen2(const QScreen *screen, PlatformKWinWayland2::ScreenShotFlags flags);
};
/**
* The ScreenShotSourceActiveWindow2 class provides a convenient way to take a screenshot
* of the active window. This uses the org.kde.KWin.ScreenShot2 dbus interface.
*/
class ScreenShotSourceActiveWindow2 final : public ScreenShotSource2
{
Q_OBJECT
public:
ScreenShotSourceActiveWindow2(PlatformKWinWayland2::ScreenShotFlags flags);
};
/**
* The ScreenShotSourceMeta2 class represents a screenshot source that is made of several
* other sources.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment