This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to authorize Screenshot2 dbus interface for my project?

Tags: None
(comma "," separated)
dfpercush
Registered Member
Posts
2
Karma
0
I'm trying to take a screenshot from my own app (c++) in a kwin_wayland session, and I've been looking through Spectacle's source code as a template. I've gathered that I need to query the
Code: Select all
org.kde.KWin.ScreenShot2
interface over DBus. Now it's communicating - I'm getting a response, but it only returns an error saying "The process is not authorized to take a screenshot." This message is both the error code and the return value of the QDBusMessage I receive back from KWin. I see that Spectacle has a line in its .desktop file:
Code: Select all
X-KDE-DBUS-Restricted-Interfaces=org.kde.kwin.Screenshot,org.kde.KWin.ScreenShot2

So I created a .desktop entry pointed at my binary, in ~/Desktop, and added this line to it. But it still returns the same error, not authorized. I've tried restarting my session, rebooted, changed various combinations of file permissions all to no avail. I also tried removing the deprecated interface from the .desktop file:
Code: Select all
X-KDE-DBUS-Restricted-Interfaces=org.kde.KWin.ScreenShot2

Is there some other way I need to grant access to this interface? How would one grant screenshot permission to an arbitrary binary file?

plasmashell 5.26.2
kwin 5.26.2

my.desktop file:
Code: Select all
[Desktop Entry]
Comment=
Exec=/home/redacted/Desktop/imcap-kwin
GenericName=
Icon=system-run
MimeType=
Name=imcap-kwin
Path=/home/redacted/Desktop
StartupNotify=false
Terminal=true
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-DBUS-Restricted-Interfaces=org.kde.kwin.Screenshot,org.kde.KWin.ScreenShot2
X-KDE-SubstituteUID=false
X-KDE-Username=
dfpercush
Registered Member
Posts
2
Karma
0
Never mind, I found a clue on https://phabricator.kde.org/D29407
... the .desktop file has to exist in a privileged directory, like /usr/share/applications, where only root has write access. Not somewhere the current user can write.
I guess it makes sense, you don't want any app just creating a .desktop file and launching itself with restricted access. But I also saw a lot of recommendations about using the org.freedesktop.portal.screenshot interface, which doesn't seem to exist on my system. Do I need flatpak for that or something? That's another topic I guess. I guess I'll just leave this here in case anyone else is encountering the same predicament.
(edit) should I accept this reply as an answer?, or... anyone want a free credit? lol sorry, new around here.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], kesang, Yahoo [Bot]