Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to take screenshot under Wayland #6312

Closed
KhazAkar opened this issue May 19, 2022 · 10 comments
Closed

Not possible to take screenshot under Wayland #6312

KhazAkar opened this issue May 19, 2022 · 10 comments

Comments

@KhazAkar
Copy link

What did you do?

I've tried to make screenshot using Pillow on Wayland compositor, such as GNOME running in Wayland mode

What did you expect to happen?

Screenshot of full display

What actually happened?

Traceback (most recent call last):
  Python Shell, prompt 2, line 1
    # Used internally for debug sandbox under external interpreter
  File "/home/khazakar/Project/Test/test_venv/lib/python3.8/site-packages/PIL/ImageGrab.py", line 68, in grab
    size, data = Image.core.grabscreen_x11(xdisplay)
builtins.OSError: X get_image failed: error 8 (73, 0, 1315)

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 20.04, GNOME Wayland
  • Python: 3.8.10
  • Pillow: 9.1.0
from PIL import ImageGrab
ImageGrab.grab()

Is there wayland support on roadmap anytime soon?

@radarhere radarhere changed the title Not possible to make screenshot under wayland session Not possible to make screenshot under Wayland May 19, 2022
@nulano
Copy link
Contributor

nulano commented May 19, 2022

Is there wayland support on roadmap anytime soon?

AFAIK no one is working on this, contributions are welcome.

From https://stackoverflow.com/q/72216896/1648883, it sounds like gnome-screenshot is one of few utilities that can take a screenshot on Wayland. From a cursory look, https://gitlab.gnome.org/GNOME/gnome-screenshot/-/blob/master/src/screenshot-backend-shell.c appears to be the implementation.

@radarhere radarhere changed the title Not possible to make screenshot under Wayland Not possible to take screenshot under Wayland May 20, 2022
@radarhere
Copy link
Member

I don't suppose it would be sufficient to just check for gnome-screenshot and call that, in the same way that ImageGrab calls screencapture on macOS?

@KhazAkar
Copy link
Author

KhazAkar commented May 25, 2022

Not so much, since you can don't have GNOME stack running and all and you have more than 1 wayland-enabled DE :)

@nulano
Copy link
Contributor

nulano commented May 25, 2022

From https://news.ycombinator.com/item?id=26446802, it sounds like there is no standard way to take a screenshot on Wayland. gnome-screenshot uses a gnome-specific extension to Wayland, other implementations work differently.

@radarhere
Copy link
Member

Googling, it seems Wayland considers it a security feature to prevent screenshots.

@KhazAkar there doesn't seem to be any way to achieve what you are after.

@KhazAkar
Copy link
Author

KhazAkar commented Jun 4, 2022

Depends. Somehow tools like gnome-screenshot works, right? I think they use some sort of portal or interface to contact the underlying compositor and grab needed data.

@radarhere
Copy link
Member

https://www.reddit.com/r/linux/comments/7lb5l7/new_screenshot_alternative_for_wayland/

It has been almost a decade, why does Wayland not have a protocol definition for screenshots?
...
Because security

It could be done by using compositor-specific tools like gnome-screenshot, but I thought you were looking for a generic solution.

@radarhere
Copy link
Member

I've created PR #6361 to use gnome-screenshot.

@hugovk
Copy link
Member

hugovk commented Jun 12, 2022

@KhazAkar Please can you test #6361 and let us know if it works for you?

@radarhere
Copy link
Member

PR #6361 has been merged, and there has been a lack of response here about that.

Any thoughts of further improvement can be continued in #6392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants