Re: Help with screenshot API.

rahul vadhyar <[email protected]> Fri, 4 Oct 2024 19:58:34 +0530
Newsgroups gmane.comp.kde.devel.kwin
Message-ID <CAOL1oibGSZ_sgdtyyWQkjanfjeNuEn2sTJyW90h+j+6g2-Tp4g@mail.gmail.com>
--0000000000002087290623a77d92
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yes, I am running plasma 6.1 on fedora 40. The details of my system are as
follows
Operating System: Fedora Linux 40
KDE Plasma Version: 6.1.5
KDE Frameworks Version: 6.6.0
Qt Version: 6.7.2
Kernel Version: 6.10.11-200.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 16 =C3=97 12th Gen Intel=C2=AE Core=E2=84=A2 i9-12900K
Memory: 46.8 GB of RAM
Graphics Processor: NVIDIA GeForce RTX 3080/PCIe/SSE2
Manufacturer: Gigabyte Technology Co., Ltd.
Product Name: Z690 UD AX DDR4

Even if CaptureWorkspace returns a dictionary, I shouldn't be getting the
error that the API doesn't exist.

To provide more context, I am making a kirigami app. I am using the
.desktop file as given in the previous email. I am also using the
following command for compiling and testing

cmake -S . -B build -GNinja && cmake --build build --parallel && sudo
 cmake --install build/ --prefix "/usr" && koolintelligence

I cannot tell where I am going wrong with this. Is there anything else that
I can try that might help?

Thanks for your help,
Rahul

On Fri, 4 Oct 2024 at 19:13, Vlad Zahorodnii <[email protected]>
wrote:

> Also note that CaptureWorkspace returns a dictionary. The API can be
> found here
>
> https://invent.kde.org/plasma/kwin/-/blob/master/src/plugins/screenshot/o=
rg.kde.KWin.ScreenShot2.xml?ref_type=3Dheads#L350
>
> On 10/4/24 4:40 PM, Vlad Zahorodnii wrote:
> > 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=3DUnique
> >> X-DBUS-ServiceName=3Dorg.kde.koolintelligence
> >> X-KDE-DBUS-Restricted-Interfaces=3Dorg.kde.KWin.ScreenShot2
> >>
> X-KDE-Wayland-Interfaces=3Dorg_kde_plasma_window_management,zkde_screenca=
st_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 =3D
> >> QString().fromStdString("org.kde.KWin.ScreenShot2");
> >> static const QString screenShotObjectPath =3D
> >> QString().fromStdString("/org/kde/KWin/ScreenShot2");
> >> static const QString screenShotInterface =3D
> >> 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 =3D
> >> 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());
> >>     }
> >> }
>

--0000000000002087290623a77d92
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yes, I am running plasma 6.1 on fedora 40. The details of =
my system are as follows<div>Operating System: Fedora Linux 40<br>KDE Plasm=
a Version: 6.1.5<br>KDE Frameworks Version: 6.6.0<br>Qt Version: 6.7.2<br>K=
ernel Version: 6.10.11-200.fc40.x86_64 (64-bit)<br>Graphics Platform: Wayla=
nd<br>Processors: 16 =C3=97 12th Gen Intel=C2=AE Core=E2=84=A2 i9-12900K<br=
>Memory: 46.8 GB of RAM<br>Graphics Processor: NVIDIA GeForce RTX 3080/PCIe=
/SSE2<br>Manufacturer: Gigabyte Technology Co., Ltd.<br>Product Name: Z690 =
UD AX DDR4<br></div><div><br></div><div>Even if CaptureWorkspace returns a =
dictionary, I shouldn&#39;t be getting the error that the API doesn&#39;t e=
xist.=C2=A0</div><div><br></div><div>To provide more context, I am making a=
 kirigami app. I am using the .desktop file as given in the previous email.=
 I am also using the following=C2=A0command for compiling and=C2=A0testing=
=C2=A0</div><div><br></div><div>cmake -S . -B build -GNinja &amp;&amp; cmak=
e --build build --parallel &amp;&amp; sudo =C2=A0cmake --install build/ --p=
refix &quot;/usr&quot; &amp;&amp; koolintelligence<br></div><div><br></div>=
<div>I cannot tell=C2=A0where I am going wrong=C2=A0with=C2=A0this. Is ther=
e anything else that I can try that might=C2=A0help?</div><div><br></div><d=
iv>Thanks for your help,</div><div>Rahul</div></div><br><div class=3D"gmail=
_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Fri, 4 Oct 2024 at 19:13, =
Vlad Zahorodnii &lt;<a href=3D"mailto:[email protected]">vlad.zahorod=
[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">Also note that CaptureWorkspace returns a dictionary. The API ca=
n be <br>
found here <br>
<a href=3D"https://invent.kde.org/plasma/kwin/-/blob/master/src/plugins/scr=
eenshot/org.kde.KWin.ScreenShot2.xml?ref_type=3Dheads#L350" rel=3D"noreferr=
er" target=3D"_blank">https://invent.kde.org/plasma/kwin/-/blob/master/src/=
plugins/screenshot/org.kde.KWin.ScreenShot2.xml?ref_type=3Dheads#L350</a><b=
r>
<br>
On 10/4/24 4:40 PM, Vlad Zahorodnii wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; CaptureWorkspace was introduced in Plasma 6.0. Are you running Plasma =
6?<br>
&gt;<br>
&gt; Vlad<br>
&gt;<br>
&gt; On 10/3/24 6:51 PM, rahul vadhyar wrote:<br>
&gt;&gt; Hi,<br>
&gt;&gt; I am Rahul, a college student from India.<br>
&gt;&gt; I am working on a project where=C2=A0I need to take screenshots of=
 the <br>
&gt;&gt; screen for further processing. From looking online and looking at =
the <br>
&gt;&gt; spectacle code, I have figured out that you need to install the <b=
r>
&gt;&gt; application in /usr/bin and that the .desktop file must contain th=
e <br>
&gt;&gt; following<br>
&gt;&gt;<br>
&gt;&gt; X-DBUS-StartupType=3DUnique<br>
&gt;&gt; X-DBUS-ServiceName=3Dorg.kde.koolintelligence<br>
&gt;&gt; X-KDE-DBUS-Restricted-Interfaces=3Dorg.kde.KWin.ScreenShot2<br>
&gt;&gt; X-KDE-Wayland-Interfaces=3Dorg_kde_plasma_window_management,zkde_s=
creencast_unstable_v1 <br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; However, even after doing this, I am getting the following error<b=
r>
&gt;&gt;<br>
&gt;&gt; Screenshot failed: No such method &#39;CaptureWorkspace&#39; in in=
terface &#39;org.<br>
&gt;&gt; kde.KWin.ScreenShot2&#39; at object path &#39;/org/kde/KWin/Screen=
Shot2&#39; <br>
&gt;&gt; (signature &#39;&#39;)<br>
&gt;&gt;<br>
&gt;&gt; My code is attached below for reference. Please let me know how I =
can <br>
&gt;&gt; resolve this issue.<br>
&gt;&gt;<br>
&gt;&gt; #include &lt;QtDBus/QtDBus&gt;<br>
&gt;&gt; #include &lt;QDBusUnixFileDescriptor&gt;<br>
&gt;&gt; #include &quot;logging.hpp&quot;<br>
&gt;&gt; #include &lt;fcntl.h&gt;<br>
&gt;&gt; static const QString screenShotService =3D <br>
&gt;&gt; QString().fromStdString(&quot;org.kde.KWin.ScreenShot2&quot;);<br>
&gt;&gt; static const QString screenShotObjectPath =3D <br>
&gt;&gt; QString().fromStdString(&quot;/org/kde/KWin/ScreenShot2&quot;);<br=
>
&gt;&gt; static const QString screenShotInterface =3D <br>
&gt;&gt; QString().fromStdString(&quot;org.kde.KWin.ScreenShot2&quot;);<br>
&gt;&gt; void takeScreenshotKwin(std::string path) {<br>
&gt;&gt; =C2=A0 =C2=A0 // Connect to KWin&#39;s screenshot service<br>
&gt;&gt; =C2=A0 =C2=A0 QDBusInterface interface(<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 screenShotService,<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 screenShotObjectPath,<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 screenShotInterface,<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 QDBusConnection::sessionBus() // Bus c=
onnection<br>
&gt;&gt; =C2=A0 =C2=A0 );<br>
&gt;&gt;<br>
&gt;&gt; =C2=A0 =C2=A0 if (!interface.isValid()) {<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_ERROR(&quot;takeScreenshotKwin&quo=
t;, &quot;Failed to connect to KWin <br>
&gt;&gt; Screenshot interface&quot;);<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;<br>
&gt;&gt; =C2=A0 =C2=A0 }<br>
&gt;&gt;<br>
&gt;&gt; =C2=A0 =C2=A0 QDBusReply&lt;QString&gt; reply =3D <br>
&gt;&gt; interface.call(QString().fromStdString(&quot;CaptureWorkspace&quot=
;));<br>
&gt;&gt;<br>
&gt;&gt; =C2=A0 =C2=A0 if (reply.isValid()) {<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_INFO(&quot;takeScreenshotKwin&quot=
;, &quot;Screenshot saved at: &quot; + path);<br>
&gt;&gt; =C2=A0 =C2=A0 } else {<br>
&gt;&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 LOG_ERROR(&quot;takeScreenshotKwin&quo=
t;, &quot;Screenshot failed: &quot; + <br>
&gt;&gt; reply.error().message().toStdString());<br>
&gt;&gt; =C2=A0 =C2=A0 }<br>
&gt;&gt; }<br>
</blockquote></div>

--0000000000002087290623a77d92--