From 9dbf94938fb06d08d851aa5208d5ce34f7d4aabd Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 14 May 2023 19:28:39 +0200 Subject: Actually use an instance of GraphicalServer, instead of just a string Signed-off-by: Olivier Gayot --- monitor_menu/__main__.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'monitor_menu/__main__.py') diff --git a/monitor_menu/__main__.py b/monitor_menu/__main__.py index 87719e7..5670954 100644 --- a/monitor_menu/__main__.py +++ b/monitor_menu/__main__.py @@ -71,17 +71,18 @@ class Profile: return cls(**kwargs) def apply(self, graphical_server: GraphicalServer | None): - if graphical_server == "xorg": - self.apply_xorg() - elif graphical_server == "wayland": - self.apply_wayland() - else: - try: - subprocess.run(["xrandr"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - except (subprocess.CalledProcessError, FileNotFoundError): - self.apply_wayland() - else: + 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() def apply_xorg(self): # We build the command line starting from just "xrandr" and adding @@ -172,7 +173,8 @@ def load_profiles_config(path: pathlib.Path | None): def main(): parser = argparse.ArgumentParser() parser.add_argument("--log-level", "--loglevel", type=LogLevel, default="info") - parser.add_argument("--graphical-server", choices=("wayland", "xorg"), type=GraphicalServer) + parser.add_argument("--graphical-server", choices=list(GraphicalServer), + type=GraphicalServer) parser.add_argument( "--profiles-config", metavar="PATH", -- cgit v1.2.3