mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #7332 from TheNooB2706/grabclipboard-linux
Added session type check in grabclipboard for Linux
This commit is contained in:
commit
e021d06fff
|
@ -140,7 +140,14 @@ def grabclipboard():
|
||||||
return BmpImagePlugin.DibImageFile(data)
|
return BmpImagePlugin.DibImageFile(data)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
if shutil.which("wl-paste"):
|
if os.getenv("WAYLAND_DISPLAY"):
|
||||||
|
session_type = "wayland"
|
||||||
|
elif os.getenv("DISPLAY"):
|
||||||
|
session_type = "x11"
|
||||||
|
else: # Session type check failed
|
||||||
|
session_type = None
|
||||||
|
|
||||||
|
if shutil.which("wl-paste") and session_type in ("wayland", None):
|
||||||
output = subprocess.check_output(["wl-paste", "-l"]).decode()
|
output = subprocess.check_output(["wl-paste", "-l"]).decode()
|
||||||
mimetypes = output.splitlines()
|
mimetypes = output.splitlines()
|
||||||
if "image/png" in mimetypes:
|
if "image/png" in mimetypes:
|
||||||
|
@ -153,11 +160,12 @@ def grabclipboard():
|
||||||
args = ["wl-paste"]
|
args = ["wl-paste"]
|
||||||
if mimetype:
|
if mimetype:
|
||||||
args.extend(["-t", mimetype])
|
args.extend(["-t", mimetype])
|
||||||
elif shutil.which("xclip"):
|
elif shutil.which("xclip") and session_type in ("x11", None):
|
||||||
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
|
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
|
||||||
else:
|
else:
|
||||||
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
err = p.stderr
|
err = p.stderr
|
||||||
if err:
|
if err:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user