Skip to content

Commit

Permalink
Check session type using environment variable instead of loginctl
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNooB2706 committed Aug 12, 2023
1 parent 7b157b0 commit 0b6ab79
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,27 +140,10 @@ def grabclipboard():
return BmpImagePlugin.DibImageFile(data)
return None
else:
if shutil.which("loginctl"):
try:
loginctl = subprocess.check_output("loginctl").decode().split("\n")
except subprocess.CalledProcessError:
loginctl = None
else:
loginctl = None

if loginctl is not None:
username = os.getlogin()
sessionid = [
line.split()[0] for line in loginctl if username in line.split()
][0]
sessiontype = (
subprocess.check_output(
["loginctl", "show-session", sessionid, "-p", "Type"]
)
.decode()
.strip("\n")
.split("=")[1]
)
if os.getenv("WAYLAND_DISPLAY"):
sessiontype = "wayland"
elif os.getenv("DISPLAY"):
sessiontype = "x11"
else: # Session type check failed
sessiontype = None

Expand Down

0 comments on commit 0b6ab79

Please sign in to comment.