Skip to content

fix for KDE Screenshot2 interface #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions src/linuxdesktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,56 @@ namespace {
// -----------------------------------------------------------------------------------------------
QPixmap grabScreenDBusKde()
{
QDBusInterface interface(QStringLiteral("org.kde.KWin"),
QStringLiteral("/Screenshot"),
QStringLiteral("org.kde.kwin.Screenshot"));
QDBusReply<QString> reply = interface.call(QStringLiteral("screenshotFullscreen"));
QPixmap pm(reply.value());
if (!pm.isNull()) {
QFile::remove(reply.value());
} else {
logError(desktop) << LinuxDesktop::tr("Screenshot via KDE DBus interface failed.");
// Create a temporary file to receive the screenshot data
QTemporaryFile tempFile;
if (!tempFile.open()) {
qDebug() << "Failed to create temporary file";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and other locations: Please use logWarning(desktop) and logError(deskop) within this file.
(and additionally tr for strings that should be translatable)
e.g.

logError(desktop) << tr("Failed to create temporary file");

return QPixmap();
}
return pm;

QDBusUnixFileDescriptor pipe(tempFile.handle());

QVariantMap options;
options["include-cursor"] = false; // Include mouse cursor in screenshot
options["include-decoration"] = false; // Include window decorations
options["native-resolution"] = true; // Use native resolution

// Create DBus interface
QDBusInterface interface(
QStringLiteral("org.kde.KWin.ScreenShot2"),
QStringLiteral("/org/kde/KWin/ScreenShot2"),
QStringLiteral("org.kde.KWin.ScreenShot2")
);

QList<QVariant> args;
args << QVariant::fromValue(options)
<< QVariant::fromValue(pipe);

QDBusReply<QVariantMap> reply = interface.callWithArgumentList(
QDBus::Block,
QStringLiteral("CaptureActiveScreen"),
args
);

if (!reply.isValid()) {
qDebug() << "Screenshot failed:" << reply.error().message();
return QPixmap();
}

QVariantMap results = reply.value();

if (results["status"].toString() != "ok") {
qDebug() << "Screenshot failed with status:" << results["status"].toString();
qDebug() << "Error message:" << results["error"].toString();
return QPixmap();
}

tempFile.seek(0);

QImage screenshot;
screenshot.load(&tempFile, "PNG"); // Format should match what KWin writes

return QPixmap::fromImage(screenshot);
}
#endif // HAS_Qt_DBus

Expand Down
Loading