Help with screenshot API.
rahul vadhyar <[email protected]> Thu, 3 Oct 2024 21:21:16 +0530
| Newsgroups | gmane.comp.kde.devel.kwin |
|---|---|
| Message-ID | <CAOL1oiaGp7Leys9z9GWL1SN-Km3XGnXNeXkgDxBnxvZwGzRKrA@mail.gmail.com> |
--0000000000000f8ac106239487b6
Content-Type: text/plain; charset="UTF-8"
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());
}
}
--0000000000000f8ac106239487b6
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<div>I am Rahul, a college student from India.</div><di=
v>I am working on a project where=C2=A0I need to take screenshots of the sc=
reen for further processing. From looking online and looking at the spectac=
le code, I have figured out that you need to install the application in /us=
r/bin and that the .desktop file must contain the following</div><div><br><=
/div><div>X-DBUS-StartupType=3DUnique<br>X-DBUS-ServiceName=3Dorg.kde.kooli=
ntelligence<br>X-KDE-DBUS-Restricted-Interfaces=3Dorg.kde.KWin.ScreenShot2<=
br>X-KDE-Wayland-Interfaces=3Dorg_kde_plasma_window_management,zkde_screenc=
ast_unstable_v1<br></div><div><br></div><div>However, even after doing this=
, I am getting the following error</div><div><br></div><div><span style=3D"=
font-family:monospace"><span style=3D"color:rgb(0,0,0)">Screenshot failed: =
No such method 'CaptureWorkspace' in interface 'org.</span><br>=
kde.KWin.ScreenShot2' at object path '/org/kde/KWin/ScreenShot2'=
; (signature '')<br></span></div><div><span style=3D"font-family:mo=
nospace"><br></span></div><div>My code is attached below for reference. Ple=
ase let me know how I can resolve this issue.</div><div><br></div><div>#inc=
lude <QtDBus/QtDBus><br>#include <QDBusUnixFileDescriptor><br>#=
include "logging.hpp"<br>#include <fcntl.h><br>static const=
QString screenShotService =3D QString().fromStdString("org.kde.KWin.S=
creenShot2");<br>static const QString screenShotObjectPath =3D QString=
().fromStdString("/org/kde/KWin/ScreenShot2");<br>static const QS=
tring screenShotInterface =3D QString().fromStdString("org.kde.KWin.Sc=
reenShot2");<br>void takeScreenshotKwin(std::string path) {<br>=C2=A0 =
=C2=A0 // Connect to KWin's screenshot service<br>=C2=A0 =C2=A0 QDBusIn=
terface interface(<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 screenShotService,<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 screenShotObjectPath,<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 screenShotInterface,<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 QDBusConnection::se=
ssionBus() // Bus connection<br>=C2=A0 =C2=A0 );<br><br>=C2=A0 =C2=A0 if (!=
interface.isValid()) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_ERROR("takeS=
creenshotKwin", "Failed to connect to KWin Screenshot interface&q=
uot;);<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>=C2=A0 =C2=A0 }<br>=C2=A0<=
br>=C2=A0 =C2=A0 QDBusReply<QString> reply =3D interface.call(QString=
().fromStdString("CaptureWorkspace"));<br><br>=C2=A0 =C2=A0 if (r=
eply.isValid()) {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_INFO("takeScreens=
hotKwin", "Screenshot saved at: " + path);<br>=C2=A0 =C2=A0 =
} else {<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_ERROR("takeScreenshotKwin&=
quot;, "Screenshot failed: " + reply.error().message().toStdStrin=
g());<br>=C2=A0 =C2=A0 }<br>}<br></div></div>
--0000000000000f8ac106239487b6--