Help with screenshot API.

Vlad Zahorodnii vlad.zahorodnii at kde.org
Fri Oct 4 14:40:24 BST 2024


Hi,

CaptureWorkspace was introduced in Plasma 6.0. Are you running Plasma 6?

Vlad

On 10/3/24 6:51 PM, rahul vadhyar wrote:
> 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());
>     }
> }


More information about the kwin mailing list