diff --git a/pyprland/plugins/monitors.py b/pyprland/plugins/monitors.py index f8e0918..964b292 100644 --- a/pyprland/plugins/monitors.py +++ b/pyprland/plugins/monitors.py @@ -5,6 +5,34 @@ import subprocess from ..ipc import hyprctlJSON +def configure_monitors(monitors, screenid: str, x: int, y: int) -> None: + x_offset = -x if x < 0 else 0 + y_offset = -y if y < 0 else 0 + + min_x = x + min_y = y + + command = ["wlr-randr"] + other_monitors = [mon for mon in monitors if mon["name"] != screenid] + for mon in other_monitors: + min_x = min(min_x, mon["x"]) + min_y = min(min_y, mon["y"]) + x_offset = -min_x + y_offset = -min_y + for mon in other_monitors: + command.extend( + [ + "--output", + mon["name"], + "--pos", + f"{mon['x']+x_offset},{mon['y']+y_offset}", + ] + ) + + command.extend(["--output", screenid, "--pos", f"{x+x_offset},{y+y_offset}"]) + subprocess.call(command) + + class Extension(Plugin): async def event_monitoradded(self, screenid): screenid = screenid.strip() @@ -40,6 +68,9 @@ class Extension(Plugin): else: # rightof x: int = ref["x"] + ref["width"] y: int = ref["y"] - subprocess.call( - ["wlr-randr", "--output", screenid, "--pos", f"{x},{y}"] - ) + + configure_monitors(monitors, screenid, x, y) + return + default_command = self.config.get("noplacement") + if default_command: + subprocess.call(default_command, shell=True)