diff options
| author | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-05-14 19:28:39 +0200 | 
|---|---|---|
| committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2023-05-14 19:29:59 +0200 | 
| commit | 9dbf94938fb06d08d851aa5208d5ce34f7d4aabd (patch) | |
| tree | b7cc9e0cedd311bfb4730800e2bfaf2d1864cdba | |
| parent | f46620d94d6a76e4b3f6f8cb41c89994879482ec (diff) | |
Actually use an instance of GraphicalServer, instead of just a string
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
| -rw-r--r-- | monitor_menu/__main__.py | 24 | 
1 files changed, 13 insertions, 11 deletions
| 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", | 
