Help with screenshot API.
rahul vadhyar
vadhyarrahul at gmail.com
Thu Oct 3 16:51:16 BST 2024
Hi,
I am Rahul, a college student from India.
I am working on a project where I need to take screenshots of the screen
for further processing. From looking online and looking at the spectacle
code, I have figured out that you need to install the application in
/usr/bin and that the .desktop file must contain the following
X-DBUS-StartupType=Unique
X-DBUS-ServiceName=org.kde.koolintelligence
X-KDE-DBUS-Restricted-Interfaces=org.kde.KWin.ScreenShot2
X-KDE-Wayland-Interfaces=org_kde_plasma_window_management,zkde_screencast_unstable_v1
However, even after doing this, I am getting the following error
Screenshot failed: No such method 'CaptureWorkspace' in interface 'org.
kde.KWin.ScreenShot2' at object path '/org/kde/KWin/ScreenShot2' (signature
'')
My code is attached below for reference. Please let me know how I can
resolve this issue.
#include <QtDBus/QtDBus>
#include <QDBusUnixFileDescriptor>
#include "logging.hpp"
#include <fcntl.h>
static const QString screenShotService =
QString().fromStdString("org.kde.KWin.ScreenShot2");
static const QString screenShotObjectPath =
QString().fromStdString("/org/kde/KWin/ScreenShot2");
static const QString screenShotInterface =
QString().fromStdString("org.kde.KWin.ScreenShot2");
void takeScreenshotKwin(std::string path) {
// Connect to KWin's screenshot service
QDBusInterface interface(
screenShotService,
screenShotObjectPath,
screenShotInterface,
QDBusConnection::sessionBus() // Bus connection
);
if (!interface.isValid()) {
LOG_ERROR("takeScreenshotKwin", "Failed to connect to KWin
Screenshot interface");
return;
}
QDBusReply<QString> reply =
interface.call(QString().fromStdString("CaptureWorkspace"));
if (reply.isValid()) {
LOG_INFO("takeScreenshotKwin", "Screenshot saved at: " + path);
} else {
LOG_ERROR("takeScreenshotKwin", "Screenshot failed: " +
reply.error().message().toStdString());
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kwin/attachments/20241003/2f0d2985/attachment.htm>
More information about the kwin
mailing list