Rework screen configuration to avoid offsets

This commit is contained in:
fdev31 2023-04-28 21:05:10 +02:00
parent c96f2c6777
commit 458d8c886b

View file

@ -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)