diff options
Diffstat (limited to 'monitor_menu')
-rw-r--r-- | monitor_menu/__main__.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/monitor_menu/__main__.py b/monitor_menu/__main__.py index 5670954..b1811f6 100644 --- a/monitor_menu/__main__.py +++ b/monitor_menu/__main__.py @@ -5,6 +5,7 @@ import dataclasses import enum import json import logging +import os import pathlib import subprocess from typing import Any @@ -71,18 +72,23 @@ class Profile: return cls(**kwargs) def apply(self, graphical_server: GraphicalServer | None): + if graphical_server is None: + try: + graphical_server = GraphicalServer(os.environ["XDG_SESSION_TYPE"]) + except KeyError: + if "WAYLAND_DISPLAY" in os.environ: + graphical_server = GraphicalServer.WAYLAND + elif "DISPLAY" in os.environ: + graphical_server = GraphicalServer.XORG + match graphical_server: case GraphicalServer.XORG: self.apply_xorg() case GraphicalServer.WAYLAND: self.apply_wayland() case None: - try: - subprocess.run(["xrandr"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - except (subprocess.CalledProcessError, FileNotFoundError): - self.apply_wayland() - else: - self.apply_xorg() + log.debug("Cannot determine graphical server type") + raise Exception def apply_xorg(self): # We build the command line starting from just "xrandr" and adding |