Add support for grim in wayland sessions

This commit is contained in:
Adian Kozlica 2025-04-18 17:48:41 +02:00
parent eb0395442c
commit 674b2395f4
3 changed files with 4 additions and 1 deletions

View File

@ -44,6 +44,7 @@ class TestImageGrab:
sys.platform not in ("win32", "darwin")
and not shutil.which("gnome-screenshot")
and not shutil.which("spectacle")
and not shutil.which("grim")
):
with pytest.raises(OSError) as e:
ImageGrab.grab()

View File

@ -16,7 +16,7 @@ or the clipboard to a PIL image memory.
the entire screen is copied, and on macOS, it will be at 2x if on a Retina screen.
On Linux, if ``xdisplay`` is ``None`` and the default X11 display does not return
a snapshot of the screen, ``gnome-screenshot`` or ``spectacle`` will be used as a
a snapshot of the screen, ``gnome-screenshot``, ``grim`` or ``spectacle`` will be used as a
fallback if they are installed. To disable this behaviour, pass ``xdisplay=""``
instead.

View File

@ -91,6 +91,8 @@ def grab(
args = ["gnome-screenshot", "-f"]
elif shutil.which("spectacle"):
args = ["spectacle", "-n", "-b", "-f", "-o"]
elif shutil.which("grim"):
args = ["grim"]
else:
raise
fh, filepath = tempfile.mkstemp(".png")