Skip to content

monitors

monitors

Display bounds helpers (macOS CoreGraphics; fallbacks elsewhere).

Functions:

monitor_placement

monitor_placement(
    one_based_index: int,
    *,
    windowed: tuple[int, int] | None = None,
) -> tuple[int, int, int, int]

Return AppleScript-style bounds (left, top, right, bottom).

Source code in src/diapason/desktop/monitors.py
def monitor_placement(
    one_based_index: int, *, windowed: tuple[int, int] | None = None
) -> tuple[int, int, int, int]:
    """Return AppleScript-style bounds (left, top, right, bottom)."""
    ml, mt, mr, mb = monitor_bounds(one_based_index)
    if windowed is None:
        return (ml, mt, mr, mb)
    ww, wh = windowed
    w = min(ww, max(320, mr - ml))
    h = min(wh, max(240, mb - mt))
    x = ml + max(0, (mr - ml - w) // 2)
    y = mt + max(0, (mb - mt - h) // 2)
    return (x, y, x + w, y + h)