Bug 446032 - Some screenshots fail in Wayland
Summary: Some screenshots fail in Wayland
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 21.04.2
Platform: Fedora RPMs Linux
: NOR major
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-24 13:19 UTC by gotlouemail
Modified: 2021-12-02 06:54 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
What the user sees after the screenshot fails (46.58 KB, image/png)
2021-11-24 13:19 UTC, gotlouemail
Details

Note You need to log in before you can comment on or make changes to this bug.
Description gotlouemail 2021-11-24 13:19:39 UTC
Created attachment 143900 [details]
What the user sees after the screenshot fails

SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***

On Wayland, trying to take a full screen or rectangular region screenshot results in an error. Taking a screenshot of window under cursor works only.

I think this is a well-known issue, but I was unable to find a bug report with a similar error output so I am creating this bug report here.

STEPS TO REPRODUCE
1. Open spectacle
2. Select "Full Screen" or "Rectangular Region" under Area option in Capture Mode
3. Press "Take a new screenshot"

OBSERVED RESULT

Spectacle closes for a second (as if to take a screenshot), but reappears with an error saying "Could not take a screenshot. Please report this bug here: create a spectacle bug" with a link to report the bug.

EXPECTED RESULT

Spectacle takes the screenshot without any error

SOFTWARE/OS VERSIONS
Linux/KDE Plasma
KDE Plasma Version: 5.23.3 
KDE Frameworks Version: 5.88.0
Qt Version: 5.12.2

ADDITIONAL INFORMATION

I ran the spectacle program in terminal and this was the output while trying to take a screenshot of full screen or for rectangular region:

Screenshot request failed: "The process is not authorized to take a screenshot"
QPixmap::scaled: Pixmap is a null pixmap
qt.qpa.wayland: Wayland does not support QWindow::requestActivate()

I have also compiled and built spectacle version 22.03.70 from source and it does the same exact thing.
Comment 1 gotlouemail 2021-12-02 06:53:41 UTC
So, it turns out that there are 2 restricted interfaces that Spectacle uses for taking screenshots on Wayland, one of which works just fine and the other, older one is deprecated. Some users may have a .desktop file that could still tell Spectacle to use the older interface, which produces errors such as these.

The interfaces in question are: org.kde.KWin.ScreenShot2 (new one) and org.kde.kwin.Screenshot (old and deprecated). The variable used to denote this is X-KDE-DBUS-Restricted-Interfaces.

Most distros ship a .desktop file that uses the new one now, but if you have a .desktop file in your ~/.local/share/applications folder which uses the old interface, you'll either have to find and change a certain line in that file to this:

X-KDE-DBUS-Restricted-Interfaces=org.kde.kwin.Screenshot,org.kde.KWin.ScreenShot2 

Or just delete the file itself, /usr/share/applications will have a .desktop file for Spectacle that will work as well. This helped solve this problem completely and Spectacle works just fine now.