Add support for Grim in Wayland sessions ImageGrab (#8912)

Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
This commit is contained in:
Adian Kozlica 2025-04-21 04:36:40 +02:00 committed by GitHub
parent 03e7871afd
commit 4402797b35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View File

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

View File

@ -16,9 +16,9 @@ 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. 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 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
fallback if they are installed. To disable this behaviour, pass ``xdisplay=""`` used as a fallback if they are installed. To disable this behaviour, pass
instead. ``xdisplay=""`` instead.
.. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.1.0 (Linux) .. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.1.0 (Linux)

View File

@ -89,6 +89,8 @@ def grab(
if display_name is None and sys.platform not in ("darwin", "win32"): if display_name is None and sys.platform not in ("darwin", "win32"):
if shutil.which("gnome-screenshot"): if shutil.which("gnome-screenshot"):
args = ["gnome-screenshot", "-f"] args = ["gnome-screenshot", "-f"]
elif shutil.which("grim"):
args = ["grim"]
elif shutil.which("spectacle"): elif shutil.which("spectacle"):
args = ["spectacle", "-n", "-b", "-f", "-o"] args = ["spectacle", "-n", "-b", "-f", "-o"]
else: else: