check if using wayland via WAYLAND_DISPLAY env variable

My distro does not install loginctl. I have implemented another easy
condition for wayland.

https://stackoverflow.com/questions/45536141/how-i-can-find-out-if-a-linux-system-uses-wayland-or-x11/45537237#45537237
This commit is contained in:
Anjandev Momi 2022-10-02 18:52:27 -04:00
parent 29a1e15192
commit 630e71e195
No known key found for this signature in database
GPG Key ID: 74482A13A109255D
1 changed files with 7 additions and 0 deletions

View File

@ -302,6 +302,13 @@ def is_wayland():
https://unix.stackexchange.com/a/325972/222290
"""
global IS_WAYLAND
# Easy method. Does not depend on loginctl
# https://stackoverflow.com/questions/45536141/how-i-can-find-out-if-a-linux-system-uses-wayland-or-x11/45537237#45537237
if "WAYLAND_DISPLAY" in os.environ:
IS_WAYLAND = True
return IS_WAYLAND
try:
session_id = subprocess.check_output(['loginctl']).split(b'\n')[1].split()[0]
output = subprocess.check_output(