Add KDE Wayland support for ImageGrab

This commit is contained in:
Adian Kozlica 2025-03-28 16:43:10 +01:00
parent 1cb6c7c347
commit 722283e819
2 changed files with 8 additions and 5 deletions

View File

@ -40,9 +40,7 @@ class TestImageGrab:
@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
def test_grab_no_xcb(self) -> None:
if sys.platform not in ("win32", "darwin") and not shutil.which(
"gnome-screenshot"
):
if sys.platform not in ("win32", "darwin") and not shutil.which("gnome-screenshot") and not shutil.which('spectacle'):
with pytest.raises(OSError) as e:
ImageGrab.grab()
assert str(e.value).startswith("Pillow was built without XCB support")

View File

@ -80,11 +80,16 @@ def grab(
if (
display_name is None
and sys.platform not in ("darwin", "win32")
and shutil.which("gnome-screenshot")
):
fh, filepath = tempfile.mkstemp(".png")
os.close(fh)
subprocess.call(["gnome-screenshot", "-f", filepath])
if shutil.which("gnome-screenshot"):
subprocess.call(["gnome-screenshot", "-f", filepath])
elif shutil.which("spectacle"):
subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath])
else:
os.unlink(filepath)
raise
im = Image.open(filepath)
im.load()
os.unlink(filepath)