From b117037c45ccfc11edd270a2afbd40ea51ca07f7 Mon Sep 17 00:00:00 2001 From: fdev31 Date: Fri, 5 May 2023 17:42:03 +0200 Subject: [PATCH] monitors: trigger the rules on init & reload --- pyprland/plugins/monitors.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pyprland/plugins/monitors.py b/pyprland/plugins/monitors.py index 74e2dfa..33ba9c6 100644 --- a/pyprland/plugins/monitors.py +++ b/pyprland/plugins/monitors.py @@ -34,10 +34,22 @@ def configure_monitors(monitors, screenid: str, x: int, y: int) -> None: class Extension(Plugin): - async def event_monitoradded(self, screenid): + async def load_config(self, config) -> None: + await super().load_config(config) + monitors = await hyprctlJSON("monitors") + for monitor in monitors: + await self.event_monitoradded( + monitor["name"], noDefault=True, monitors=monitors + ) + + async def event_monitoradded( + self, screenid, noDefault=False, monitors: list | None = None + ) -> None: screenid = screenid.strip() - monitors: list[dict[str, Any]] = await hyprctlJSON("monitors") + if not monitors: + monitors: list[dict[str, Any]] = await hyprctlJSON("monitors") + for mon in monitors: if mon["name"].startswith(screenid): mon_name = mon["description"] @@ -71,6 +83,7 @@ class Extension(Plugin): configure_monitors(monitors, screenid, x, y) return - default_command = self.config.get("unknown") - if default_command: - subprocess.call(default_command, shell=True) + if not noDefault: + default_command = self.config.get("unknown") + if default_command: + subprocess.call(default_command, shell=True)