aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--deckit/display.py11
-rw-r--r--tests/test_display.py10
2 files changed, 21 insertions, 0 deletions
diff --git a/deckit/display.py b/deckit/display.py
index 50fa3f6..c1a74b1 100644
--- a/deckit/display.py
+++ b/deckit/display.py
@@ -30,6 +30,12 @@ def tablet_resolution(cfg: dict, adb=None) -> str:
return f"{w}x{h}"
+def below_position(ref: dict, resolution: str, scale=1) -> str:
+ """Center a monitor below `ref` (a hyprctl monitor dict)."""
+ width = round(int(re.match(r"(\d+)x", resolution).group(1)) / scale)
+ return f"{ref['x'] + (ref['width'] - width) // 2}x{ref['y'] + ref['height']}"
+
+
def hypr_lua(cfg: dict) -> bool:
mode = cfg.get("hyprland", "auto")
if mode == "auto":
@@ -72,9 +78,14 @@ def setup_display(cfg: dict, run_cmd=None, popen=None) -> None:
if not any(m["name"] == mon for m in monitors):
run_cmd(["hyprctl", "output", "create", "headless", mon])
time.sleep(1)
+ # Creating the output can re-flow the layout, so read it again.
+ monitors = json.loads(run_cmd(["hyprctl", "monitors", "-j"]) or "[]")
mode = f"{tablet_resolution(cfg)}@{d.get('refresh', 60)}"
pos = d.get("position", "auto-right")
scale = d.get("scale", 1)
+ if pos in ("auto-below", "below"):
+ ref = next((m for m in monitors if m["name"] != mon), monitors[0])
+ pos = below_position(ref, mode, scale)
if hypr_lua(cfg):
run_cmd(["hyprctl", "eval",
f'hl.monitor({{output="{mon}", mode="{mode}", position="{pos}", scale={scale}}})'])
diff --git a/tests/test_display.py b/tests/test_display.py
index b69759a..7f90fe4 100644
--- a/tests/test_display.py
+++ b/tests/test_display.py
@@ -22,6 +22,16 @@ class Resolution(unittest.TestCase):
"2560x1600")
+class Below(unittest.TestCase):
+ def test_centered_under_the_reference(self):
+ ref = {"x": 0, "y": 0, "width": 2560, "height": 1080}
+ self.assertEqual(display.below_position(ref, "1280x800"), "640x1080")
+
+ def test_honours_the_reference_offset(self):
+ ref = {"x": 0, "y": -540, "width": 2560, "height": 1080}
+ self.assertEqual(display.below_position(ref, "1280x800"), "640x540")
+
+
class Swaybg(unittest.TestCase):
def test_finds_the_image_for_an_output(self):
root = Path(tempfile.mkdtemp())