question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support request: Wayland

See original GitHub issue

General information:

  • OS name: Ubuntu
  • OS version: 20.04
  • OS architecture: 64 bits
  • Resolutions:
    • Monitor 1: 1920x1080
  • Python version: 3.8.2
  • MSS version: 5.0.0

For GNU/Linux users:

  • Display server protocol and version, if known: Wayland
  • Desktop Environment: Gnome
  • Composite Window Manager name and version: Unknown

Description of the warning/error

When running mss under Wayland, it crashs. As far as I understand from the source code, mss currently uses xlib for Linux, which seems to (unsurprisingly) not work on Wayland. It would be very cool to have wayland support implemented, as it becomes more and more popular.

Full message

Example: Executing the following snippet under X works perfectly, while under Wayland it produces an error.

Snippet:

import mss
fn = mss.mss().shot(mon=-1, output="screenshot.png")
print(fn)

Error on Wayland:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/holger/.local/lib/python3.8/site-packages/mss/factory.py", line 41, in mss
    return linux.MSS(**kwargs)
  File "/home/holger/.local/lib/python3.8/site-packages/mss/linux.py", line 226, in __init__
    self.root = self.xlib.XDefaultRootWindow(MSS.display)
  File "/home/holger/.local/lib/python3.8/site-packages/mss/linux.py", line 175, in validate
    raise ScreenShotError(err, details=details)
mss.exception.ScreenShotError: XDefaultRootWindow() failed

Other details

A lot of screenshot tools (e.g. shutter) have this issue, because screenshots seem to work completely different in Wayland (to improve security). Applications that do work are e.g.:

A proper way to do screenshots under Wayland is referenced in a flameshot issue and might help solving this in mss, too. The main statement from that issue:

The cross-platform way to take screenshots on Wayland is via xdg-desktop-portal (which also works outside of Flatpak). See https://github.com/flatpak/xdg-desktop-portal/blob/master/data/org.freedesktop.portal.Screenshot.xml

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
surajRathicommented, Jun 19, 2021

Hello,

I started looking at wayland support. I have worked on a very basic (incomplete) implementation repository .

However I am getting horrible FPS (~3.5) and it pulls in two external dependencies (python-dbus and pygoobject).

There are two points of interest:

  1. I think xdg-desktop-portal seems to only give the current monitor. I do not have an external monitor. I may try with virtual outputs in the future.
  2. Flow: 2.1. Call method Screenshot on Service org.freedesktop.portal.Desktop, with object /org/freedesktop/portal/desktop, and interface org.freedesktop.portal.Screenshot. This will return the path of an object: request_path 2.2 Subscribe to a signal on Service org.freedesktop.portal.Desktop on the object request_path and interface org.freedesktop.portal.Request. 2.3 Run the Main Loop (!!!). After a while we will receive a file path. 2.4 Open the file and create a screenshot object.

This project (from what I understand) is supposed to be fast and no dependencies. Further steps to be taken:

  • Monitor Support
  • Use libdbus directly and use a custom event loop. (absolutely no idea where to start from)

Concerns:

  1. The dbus event loop seems to be taking ~75% of the time (the remaining 30% being mainly reading the file from disk to a screenshot object). With this latency is xdg-desktop-portal suitable for the python-mss project?

  2. Should I add/modify the Screenshot object constructors to load images from a file more efficiently?

I have not been able to run the tests as the pygoobject dependency is causing issues. I am not that familiar with tox.

I have not made a pull request as this is very very preliminary.

Apologies if I have skipped a step or not seen another discussion.

I also just realized that I bumped a year old thread, sorry for that.

2reactions
adeliktascommented, Dec 26, 2021

A bump should be no issue as long as this issue is open and there is demand for wayland (or Xwayland on Gnome 40.0 in my case). I’ve tried the commits of surajRathi, but unfortunately receive NotImplementedError for _monitors_impl. Mss is a dependency for python-imagesearch, which i originally intended to use. As BoboTiG commented, i’m not sure either how far this issue can be solved, because of the general design of wayland. But solving this on gnome certainly seems easier because of it’s gnome-screenshot utility.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wayland Games Customer Support
How can we help you today? Enter your search term here... Search. New support ticket.
Read more >
Support Wayland
Your generosity is crucial to help Wayland Academy continue its more than 166-year tradition of emphasizing academic excellence and personal growth.
Read more >
Services and Support | waylandma
We offer counseling and information on a wide range of concerns including health insurance, housing, transportation and more. If you have questions, call...
Read more >
Chapter 4. Wayland Protocol and Model of Operation
A message sent by a client to the server is called request. ... Beginning in Wayland 1.15, implementations can optionally support server socket...
Read more >
WBUonline Staff - Wayland Baptist University
Our 24/7 support team is ready to provide support for Blackboard. Call us 1-866-547-9192, Chat With Us Chat, Submit at support ticket Submit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found