Skip to content

Commit 7c56b38

Browse files
authored
Merge pull request #8842 from AdianKozlica/image_grab_wayland_kde
Add KDE Wayland support for ImageGrab
2 parents 6417841 + 2b62c0b commit 7c56b38

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

Tests/test_imagegrab.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def test_grab_x11(self) -> None:
4040

4141
@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
4242
def test_grab_no_xcb(self) -> None:
43-
if sys.platform not in ("win32", "darwin") and not shutil.which(
44-
"gnome-screenshot"
43+
if (
44+
sys.platform not in ("win32", "darwin")
45+
and not shutil.which("gnome-screenshot")
46+
and not shutil.which("spectacle")
4547
):
4648
with pytest.raises(OSError) as e:
4749
ImageGrab.grab()

docs/reference/ImageGrab.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +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`` will be used as fallback if it is
20-
installed. To disable this behaviour, pass ``xdisplay=""`` instead.
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.
2122

2223
.. versionadded:: 1.1.3 (Windows), 3.0.0 (macOS), 7.1.0 (Linux)
2324

src/PIL/ImageGrab.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ def grab(
8686
raise OSError(msg)
8787
size, data = Image.core.grabscreen_x11(display_name)
8888
except OSError:
89-
if (
90-
display_name is None
91-
and sys.platform not in ("darwin", "win32")
92-
and shutil.which("gnome-screenshot")
93-
):
89+
if display_name is None and sys.platform not in ("darwin", "win32"):
90+
if shutil.which("gnome-screenshot"):
91+
args = ["gnome-screenshot", "-f"]
92+
elif shutil.which("spectacle"):
93+
args = ["spectacle", "-n", "-b", "-f", "-o"]
94+
else:
95+
raise
9496
fh, filepath = tempfile.mkstemp(".png")
9597
os.close(fh)
96-
subprocess.call(["gnome-screenshot", "-f", filepath])
98+
subprocess.call(args + [filepath])
9799
im = Image.open(filepath)
98100
im.load()
99101
os.unlink(filepath)

0 commit comments

Comments
 (0)