Check session type using environment variable instead of loginctl

This commit is contained in:
TheNooB 2023-08-12 12:51:09 +08:00
parent 7b157b045a
commit 0b6ab79145
No known key found for this signature in database
GPG Key ID: B80F1826EB256C6E

View File

@ -140,27 +140,10 @@ def grabclipboard():
return BmpImagePlugin.DibImageFile(data) return BmpImagePlugin.DibImageFile(data)
return None return None
else: else:
if shutil.which("loginctl"): if os.getenv("WAYLAND_DISPLAY"):
try: sessiontype = "wayland"
loginctl = subprocess.check_output("loginctl").decode().split("\n") elif os.getenv("DISPLAY"):
except subprocess.CalledProcessError: sessiontype = "x11"
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]
)
else: # Session type check failed else: # Session type check failed
sessiontype = None sessiontype = None