Skip to content

Commit 4402797

Browse files
Add support for Grim in Wayland sessions ImageGrab (#8912)
Co-authored-by: Andrew Murray <[email protected]>
1 parent 03e7871 commit 4402797

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Tests/test_imagegrab.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def test_grab_no_xcb(self) -> None:
4343
if (
4444
sys.platform not in ("win32", "darwin")
4545
and not shutil.which("gnome-screenshot")
46+
and not shutil.which("grim")
4647
and not shutil.which("spectacle")
4748
):
4849
with pytest.raises(OSError) as e:

docs/reference/ImageGrab.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ or the clipboard to a PIL image memory.
1616
the entire screen is copied, and on macOS, it will be at 2x if on a Retina screen.
1717

1818
On Linux, if ``xdisplay`` is ``None`` and the default X11 display does not return
19-
a snapshot of the screen, ``gnome-screenshot`` or ``spectacle`` will be used as a
20-
fallback if they are installed. To disable this behaviour, pass ``xdisplay=""``
21-
instead.
19+
a snapshot of the screen, ``gnome-screenshot``, ``grim`` or ``spectacle`` will be
20+
used as a fallback if they are installed. To disable this behaviour, pass
21+
``xdisplay=""`` instead.
2222

2323
.. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.1.0 (Linux)
2424

src/PIL/ImageGrab.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def grab(
8989
if display_name is None and sys.platform not in ("darwin", "win32"):
9090
if shutil.which("gnome-screenshot"):
9191
args = ["gnome-screenshot", "-f"]
92+
elif shutil.which("grim"):
93+
args = ["grim"]
9294
elif shutil.which("spectacle"):
9395
args = ["spectacle", "-n", "-b", "-f", "-o"]
9496
else:

0 commit comments

Comments
 (0)