Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
feat(jarvisbar): physical-size-consistent scaling + 135% default
Ruben Lütke74d7566d3e35
diff --git a/jarvis/core/config.py b/jarvis/core/config.pyindex ebf7b39a87..b8a76ddd00 100644--- a/jarvis/core/config.py+++ b/jarvis/core/config.py@@ -1432,12 +1432,13 @@ class UIConfig(BaseModel):bar_persistent: bool = True# Hex accent the bar lights up with during activity (gold on-brand).bar_accent: str = "#e7c46e"- # Jarvis bar size multiplier (Settings → "Bar size" slider). 1.0 = the- # signed-off default look; the whole bar scales proportionally (width AND- # height together, shape preserved) below/above it, on top of the- # screen-adaptive scale. Range mirrors renderer.USER_SIZE_MIN/MAX (0.5–2.0);- # the renderer re-clamps, so this validator only sanitizes a corrupt value.- bar_size_scale: float = 1.0+ # Jarvis bar size multiplier (Settings → "Bar size" slider). The whole bar+ # scales proportionally (width AND height together, shape preserved) on top+ # of the physical-size-consistent base scale. Default 1.35 (135%) — the bar+ # reads a touch small at 100% on high-DPI monitors. Range mirrors+ # renderer.USER_SIZE_MIN/MAX (0.5–2.0); the renderer re-clamps, so this+ # validator only sanitizes a corrupt value.+ bar_size_scale: float = 1.35# Follow the mouse across monitors: when on, the on-screen bar hops to# whichever monitor the mouse cursor is currently on, keeping the SAME# relative spot (so different-sized monitors line up). Off pins it to onediff --git a/jarvis/platform/monitors.py b/jarvis/platform/monitors.pyindex 54b95d1328..02ef8752a2 100644--- a/jarvis/platform/monitors.py+++ b/jarvis/platform/monitors.py@@ -398,6 +398,154 @@ def _x11_work_area_at(x: int, y: int) -> tuple[int, int, int, int] | None:return fallback+def primary_monitor_raw_dpi() -> float | None:+ """Best-effort TRUE physical DPI (raw dots-per-inch, from EDID) of the OS+ primary monitor — the reliable input for sizing the on-screen bar to a+ consistent PHYSICAL size across monitors of different physical size.++ Deliberately the monitor's RAW physical DPI, NOT the user's display-scaling+ (effective DPI) and NOT Tk's ``winfo_screenmm`` — the latter returns a+ 96-DPI-derived FAKE on Windows (mm mirror the resolution, so every monitor+ looks the same size). ``None`` when it cannot be read (macOS, Wayland,+ headless, missing/implausible EDID); the caller then keeps the+ resolution-relative fallback. Never raises.++ - Windows: ``GetDpiForMonitor(primary, MDT_RAW_DPI)``.+ - Linux/X11: derived from ``xrandr``'s physical-mm report on the primary.+ - macOS: ``None`` (the Qt bar keeps resolution sizing; macOS points already+ normalise perceived size — see ``renderer.resolve_screen_scale``).+ """+ try:+ if sys.platform == "win32":+ return _win_primary_raw_dpi()+ if sys.platform == "darwin":+ return None+ from jarvis.platform.probes import is_wayland # noqa: PLC0415++ if is_wayland():+ return None+ return _x11_primary_raw_dpi()+ except Exception: # noqa: BLE001 — best-effort probe; caller keeps a fallback+ return None+++def _win_primary_raw_dpi() -> float | None:+ """``GetDpiForMonitor(primary, MDT_RAW_DPI)`` — the monitor's true physical+ DPI from EDID, independent of the display-scaling setting.++ The primary monitor's top-left is ``(0, 0)`` by Windows convention, so+ ``MonitorFromPoint((0,0), MONITOR_DEFAULTTOPRIMARY)`` resolves it. ``shcore``+ (8.1+) is required; older Windows / any failure → ``None``.++ CRITICAL: ``MDT_RAW_DPI`` is DPI-AWARENESS-dependent — an UNAWARE caller sees+ the monitor's VIRTUALISED (scaled) resolution and gets a wrong raw DPI (e.g.+ 103 instead of the physical 154 on a 4K@150% panel). A thread-scoped+ per-monitor DPI pin (restored afterwards, mirroring :func:`_win_work_area_at`)+ forces the physical reading, matching the DPI-aware Tk thread that renders the+ bar in physical pixels — so the result is correct no matter the caller's+ ambient awareness.+ """+ import ctypes # noqa: PLC0415+ from ctypes import wintypes # noqa: PLC0415++ user32 = ctypes.windll.user32+ try:+ shcore = ctypes.windll.shcore+ except OSError: # pre-8.1: no GetDpiForMonitor+ return None++ class _POINT(ctypes.Structure):+ _fields_ = [("x", ctypes.c_long), ("y", ctypes.c_long)]++ _MONITOR_DEFAULTTOPRIMARY = 0x00000001+ _MDT_RAW_DPI = 2++ set_ctx = None+ prev = None+ try:+ set_ctx = user32.SetThreadDpiAwarenessContext+ set_ctx.restype = ctypes.c_void_p+ set_ctx.argtypes = [ctypes.c_void_p]+ for context in (-4, -3): # PER_MONITOR_AWARE_V2, then V1 (1607)+ prev = set_ctx(ctypes.c_void_p(context))+ if prev is not None:+ break+ except (OSError, AttributeError): # pre-1607: read unpinned (best-effort)+ set_ctx = None+ try:+ # HMONITOR is pointer-sized: set restype so ctypes doesn't truncate it+ # on Win64, then re-wrap when passing it on (mirrors _win_work_area_at).+ user32.MonitorFromPoint.restype = wintypes.HMONITOR+ hmon = user32.MonitorFromPoint(_POINT(0, 0), _MONITOR_DEFAULTTOPRIMARY)+ dpi_x = ctypes.c_uint()+ dpi_y = ctypes.c_uint()+ hr = shcore.GetDpiForMonitor(+ wintypes.HMONITOR(hmon), _MDT_RAW_DPI, ctypes.byref(dpi_x), ctypes.byref(dpi_y)+ )+ finally:+ if set_ctx is not None and prev is not None:+ try:+ set_ctx(ctypes.c_void_p(prev))+ except Exception: # noqa: BLE001,S110 — best-effort DPI-context restore+ pass+ if hr != 0 or dpi_x.value <= 0:+ return None+ return float(dpi_x.value)+++def _dpi_from_xrandr_line(line: str) -> float | None:+ """Raw DPI from one ``xrandr`` ``connected`` line (pure, unit-testable).++ Reads the pixel width from the geometry token (``3840x2160+0+0``) and the+ physical width from the trailing ``NNNmm x NNNmm``; ``DPI = 25.4 * px / mm``.+ ``None`` when either is missing or implausible (0mm is common on virtual /+ unknown outputs).+ """+ import re # noqa: PLC0415++ px_w: int | None = None+ for tok in line.split():+ if "x" in tok and "+" in tok:+ try:+ px_w = int(tok.split("+")[0].split("x")[0])+ except (IndexError, ValueError):+ px_w = None+ break+ m = re.search(r"(\d+)\s*mm\s*x\s*(\d+)\s*mm", line)+ if px_w is None or px_w <= 0 or m is None:+ return None+ mm_w = int(m.group(1))+ if mm_w <= 0:+ return None+ return 25.4 * px_w / mm_w+++def _x11_primary_raw_dpi() -> float | None:+ """Raw DPI of the primary ``xrandr`` output from its physical-mm report.++ Prefers the ``connected primary`` line, falling back to the first+ ``connected`` line. ``None`` when ``xrandr`` is missing or reports no size.+ """+ from jarvis.core.process_utils import NO_WINDOW_CREATIONFLAGS # noqa: PLC0415++ if shutil.which("xrandr") is None:+ return None+ try:+ out = subprocess.run(+ ["xrandr", "--query"], capture_output=True, text=True, timeout=3.0,+ creationflags=NO_WINDOW_CREATIONFLAGS,+ ).stdout+ except Exception: # noqa: BLE001 — xrandr missing / no display+ return None+ connected = [ln for ln in out.splitlines() if " connected " in ln]+ line = next((ln for ln in connected if " connected primary " in ln), None)+ if line is None:+ line = connected[0] if connected else None+ if line is None:+ return None+ return _dpi_from_xrandr_line(line)++def native_primary_origin() -> tuple[int, int] | None:"""Best-effort virtual-desktop top-left ``(x, y)`` of the OS primary monitor,or ``None`` when it cannot be determined (headless / Wayland / missing libs).diff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.pyindex e644223edf..34156eb0f9 100644--- a/jarvis/ui/jarvisbar/overlay.py+++ b/jarvis/ui/jarvisbar/overlay.py@@ -165,6 +165,18 @@ HANGUP_CLICK_GUARD_S = 1.0CURSOR_MONITOR_POLL_MS = 250+def _probe_primary_raw_dpi() -> float | None:+ """True physical DPI of the primary monitor for physical-size scaling, or+ ``None`` (→ resolution fallback). Thin, lazily-imported, never-raising wrapper+ around ``jarvis.platform.monitors.primary_monitor_raw_dpi``."""+ try:+ from jarvis.platform.monitors import primary_monitor_raw_dpi++ return primary_monitor_raw_dpi()+ except Exception: # noqa: BLE001 — sizing is cosmetic; degrade to resolution+ return None++def _primary_work_area() -> tuple[int, int, int, int] | None:"""Primary-monitor work area (left, top, right, bottom) EXCLUDING thetaskbar, via Win32 ``SPI_GETWORKAREA``. None off Windows / on failure so@@ -646,22 +658,23 @@ class JarvisBarOverlay:root = _create_hidden_tk_root(tk)self._root = root- # Screen-adaptive geometry (screen-relative): shrink the whole bar on- # small screens (a 14" laptop) while big monitors keep the approved- # 1.0 look. Must run BEFORE the renderer and any window geometry are- # derived from the module constants. Tk reports points on macOS and- # physical pixels on a DPI-aware Windows/X11 — both are the right- # basis for "how much of this screen would the bar occupy".+ # Base geometry scale. PHYSICAL-size-consistent when the monitor's true+ # DPI is known (Windows/X11 report real physical pixels), so the bar+ # looks the same size on the glass across monitors of different physical+ # size; else the resolution-relative fallback. Must run BEFORE the+ # renderer and any window geometry are derived from the module constants.try:- self._screen_scale = renderer.compute_display_scale(- int(root.winfo_screenwidth()), int(root.winfo_screenheight())+ raw_dpi = _probe_primary_raw_dpi()+ self._screen_scale = renderer.resolve_screen_scale(+ int(root.winfo_screenwidth()), int(root.winfo_screenheight()), raw_dpi)renderer.apply_display_scale(self._screen_scale, user_size=self._user_size_scale)if renderer.DISPLAY_SCALE != 1.0 or self._user_size_scale != 1.0:log.info(- "jarvisbar display scale %.3f (user size %.2f) for screen %sx%s",+ "jarvisbar scale %.3f (user size %.2f, raw dpi %s) for screen %sx%s",renderer.DISPLAY_SCALE,self._user_size_scale,+ raw_dpi,root.winfo_screenwidth(),root.winfo_screenheight(),)diff --git a/jarvis/ui/jarvisbar/qt_overlay.py b/jarvis/ui/jarvisbar/qt_overlay.pyindex 635a116cab..24cca88eb7 100644--- a/jarvis/ui/jarvisbar/qt_overlay.py+++ b/jarvis/ui/jarvisbar/qt_overlay.py@@ -590,7 +590,12 @@ class QtJarvisBarOverlay:screen = app.primaryScreen()if screen is not None:geometry = screen.geometry()- self._screen_scale = renderer.compute_display_scale(+ # macOS keeps resolution-relative sizing (no raw_dpi): its points are+ # already OS-normalised for perceived size, and QScreen.geometry() is+ # in points, not physical pixels — mixing a physical-DPI anchor here+ # would regress the signed-off Mac look. Physical sizing on macOS is a+ # documented follow-up (renderer.resolve_screen_scale accepts a dpi).+ self._screen_scale = renderer.resolve_screen_scale(geometry.width(), geometry.height())renderer.apply_display_scale(self._screen_scale, user_size=self._user_size_scale)diff --git a/jarvis/ui/jarvisbar/renderer.py b/jarvis/ui/jarvisbar/renderer.pyindex 129a597319..577a37ded3 100644--- a/jarvis/ui/jarvisbar/renderer.py+++ b/jarvis/ui/jarvisbar/renderer.py@@ -88,6 +88,68 @@ MIN_DISPLAY_SCALE = 0.55BASE_DISPLAY_SCALE = 0.85DISPLAY_SCALE = 1.0+# --- physical-size-consistent scaling (true per-monitor DPI) ------------------+# The screen-adaptive scale above is RESOLUTION-relative, so two monitors of the+# SAME resolution but DIFFERENT physical size render the bar at the same pixel+# size — physically bigger on the bigger monitor. To make the bar look the SAME+# PHYSICAL SIZE on the glass everywhere, ``compute_physical_scale`` scales by the+# monitor's TRUE physical DPI instead (from EDID via GetDpiForMonitor(MDT_RAW_DPI)+# on Windows / xrandr mm on X11 — NOT the OS scaling, and NOT Tk's winfo_screenmm+# which returns a 96-DPI-derived FAKE on Windows). A physical-mm model was tried+# and reverted once as "too small" (2026-07-21) because it anchored to a 14"+# laptop; the fix is anchoring to the maintainer's monitor DPI below, so THAT+# monitor keeps its exact current look and only physically different monitors+# adjust. When the true DPI is unavailable/implausible (macOS, Wayland, headless,+# missing EDID) the caller falls back to the resolution-relative scale.+REFERENCE_RAW_DPI = 154.0 # calibrated reference physical DPI (~28in 4K desktop);+# compute_physical_scale returns exactly BASE_DISPLAY_SCALE at this DPI, so the+# reference monitor is unchanged. Measured live via GetDpiForMonitor(MDT_RAW_DPI).+MAX_DISPLAY_SCALE = 1.6 # physical sizing may exceed 1.0 on dense (4K/Retina)+# monitors; bounded so a very dense or MISREPORTED monitor can't produce an absurd+# bar. The resolution path is separately capped at BASE_DISPLAY_SCALE, so raising+# this ceiling only affects the physical path.+PHYSICAL_DPI_MIN = 60.0 # plausibility gate: below → treat DPI as unknown+PHYSICAL_DPI_MAX = 350.0 # (fail-closed to the resolution fallback)+++def compute_physical_scale(raw_dpi: float) -> float | None:+ """Screen scale that holds the bar's PHYSICAL size constant across monitors.++ ``raw_dpi`` is the monitor's TRUE physical dots-per-inch (EDID), NOT the OS+ display-scaling. Returns ``BASE_DISPLAY_SCALE * raw_dpi / REFERENCE_RAW_DPI``+ so a denser monitor draws MORE pixels (same physical size) and a coarser one+ FEWER, clamped to ``[MIN_DISPLAY_SCALE, MAX_DISPLAY_SCALE]``. At+ ``REFERENCE_RAW_DPI`` it returns exactly ``BASE_DISPLAY_SCALE`` (the reference+ monitor is unchanged). ``None`` when ``raw_dpi`` is missing / non-finite /+ implausible, so the caller falls back to ``compute_display_scale``.+ """+ try:+ d = float(raw_dpi)+ except (TypeError, ValueError):+ return None+ if not math.isfinite(d) or not (PHYSICAL_DPI_MIN <= d <= PHYSICAL_DPI_MAX):+ return None+ raw = BASE_DISPLAY_SCALE * d / REFERENCE_RAW_DPI+ return max(MIN_DISPLAY_SCALE, min(MAX_DISPLAY_SCALE, round(raw, 4)))+++def resolve_screen_scale(+ screen_w: int, screen_h: int, raw_dpi: float | None = None+) -> float:+ """The bar's base screen scale: physical-size-consistent when the monitor's+ true DPI is known + plausible, else the resolution-relative fallback.++ This is the single entry point the surfaces call — Windows/X11 pass the real+ per-monitor ``raw_dpi``; macOS (and any host that can't read it) passes+ ``None`` and gets today's resolution-relative behaviour unchanged.+ """+ if raw_dpi is not None:+ phys = compute_physical_scale(raw_dpi)+ if phys is not None:+ return phys+ return compute_display_scale(screen_w, screen_h)++# --- user size preference (the "Bar size" slider) ----------------------------# A multiplier applied ON TOP of the screen-adaptive DISPLAY_SCALE, chosen by# the user in Settings → "Bar size". 1.0 reproduces the signed-off default@@ -185,7 +247,11 @@ def apply_display_scale(scale: float, user_size: float | None = None) -> None:"""global DISPLAY_SCALE, USER_SIZE_SCALE, COLLAPSED_W, COLLAPSED_H, OPEN_W, OPEN_Hglobal ACTIVE_W, ACTIVE_H, _BOTTOM_PAD, WIN_W, WIN_H- DISPLAY_SCALE = s = max(MIN_DISPLAY_SCALE, min(1.0, float(scale)))+ # Upper clamp is MAX_DISPLAY_SCALE (not 1.0): the physical-size path may+ # legitimately exceed 1.0 on a dense (4K/Retina) monitor. The resolution+ # path is separately capped at BASE_DISPLAY_SCALE by compute_display_scale,+ # so this wider ceiling only ever admits a physical scale.+ DISPLAY_SCALE = s = max(MIN_DISPLAY_SCALE, min(MAX_DISPLAY_SCALE, float(scale)))if user_size is not None:USER_SIZE_SCALE = clamp_user_size(user_size)g = s * USER_SIZE_SCALE # effective geometry factor (screen × user size)diff --git a/jarvis/ui/web/settings_routes.py b/jarvis/ui/web/settings_routes.pyindex 4b533d0be4..ac9f56c8ba 100644--- a/jarvis/ui/web/settings_routes.py+++ b/jarvis/ui/web/settings_routes.py@@ -1992,7 +1992,7 @@ async def put_bar_follow_cursor(# release. Range mirrors renderer.USER_SIZE_MIN/MAX (0.5–2.0).# ----------------------------------------------------------------------------_BAR_SIZE_DEFAULT = 1.0+_BAR_SIZE_DEFAULT = 1.35class BarSizeBody(BaseModel):diff --git a/tests/integration/test_settings_routes.py b/tests/integration/test_settings_routes.pyindex 05566a5607..e951368f67 100644--- a/tests/integration/test_settings_routes.py+++ b/tests/integration/test_settings_routes.py@@ -101,7 +101,8 @@ def test_bar_size_get_returns_default_and_range(server: WebServer) -> None:resp = client.get("/api/settings/bar-size")assert resp.status_code == 200body = resp.json()- assert body["scale"] == 1.0+ assert body["scale"] == 1.35 # product default+ assert body["default"] == 1.35assert body["min"] == 0.5assert body["max"] == 2.0diff --git a/tests/unit/platform/test_monitors.py b/tests/unit/platform/test_monitors.pyindex 2917f7e0df..05be175a49 100644--- a/tests/unit/platform/test_monitors.py+++ b/tests/unit/platform/test_monitors.py@@ -8,6 +8,8 @@ decision logic is what these pin — the native query is monkeypatched."""from __future__ import annotations+import pytest+from jarvis.platform import monitors as mon# mss-style: monitors[0] = virtual bounding box, [1:] = physical screens.@@ -78,3 +80,33 @@ def test_native_primary_origin_never_raises():isinstance(result, tuple) and len(result) == 2and all(isinstance(v, int) for v in result))+++# --------------------------------------------------------------------------- #+# primary_monitor_raw_dpi — physical DPI for physical-size bar scaling #+# --------------------------------------------------------------------------- #+def test_dpi_from_xrandr_line_parses_px_and_mm():+ # A real "connected primary" line: 3840 px over 630 mm → 25.4*3840/630.+ line = "DP-1 connected primary 3840x2160+0+0 (normal left inverted) 630mm x 360mm"+ dpi = mon._dpi_from_xrandr_line(line)+ assert dpi == pytest.approx(25.4 * 3840 / 630, abs=0.1)+++def test_dpi_from_xrandr_line_offset_output():+ # A secondary output offset into the virtual desktop still parses its own px.+ line = "HDMI-2 connected 2560x1440+3840+0 (normal) 597mm x 336mm"+ dpi = mon._dpi_from_xrandr_line(line)+ assert dpi == pytest.approx(25.4 * 2560 / 597, abs=0.1)+++def test_dpi_from_xrandr_line_none_when_no_physical_size():+ # 0mm (common on virtual/unknown outputs) or a missing mm report → None.+ assert mon._dpi_from_xrandr_line("VIRTUAL1 connected 1920x1080+0+0 0mm x 0mm") is None+ assert mon._dpi_from_xrandr_line("DP-1 connected primary 1920x1080+0+0 (normal)") is None+ assert mon._dpi_from_xrandr_line("DP-1 disconnected") is None+++def test_primary_monitor_raw_dpi_never_raises():+ # Best-effort: a real physical DPI (plausible float) or None on any host.+ result = mon.primary_monitor_raw_dpi()+ assert result is None or (isinstance(result, float) and 30.0 < result < 600.0)diff --git a/tests/unit/ui/jarvisbar/test_display_scale.py b/tests/unit/ui/jarvisbar/test_display_scale.pyindex dec4fa34db..e746fcf3c8 100644--- a/tests/unit/ui/jarvisbar/test_display_scale.py+++ b/tests/unit/ui/jarvisbar/test_display_scale.py@@ -112,13 +112,80 @@ def test_scale_recomputes_geometry_and_restores_cleanly():assert getattr(renderer, name) == value, name-def test_scale_never_enlarges_and_never_undershoots_the_floor():+def test_scale_clamps_to_the_physical_ceiling_and_the_floor():+ # The upper clamp is now MAX_DISPLAY_SCALE (not 1.0): the physical-size path+ # may legitimately exceed 1.0 on a dense monitor. A value inside the band+ # passes through; above it clamps to the ceiling; below floors at MIN.+ assert renderer.MAX_DISPLAY_SCALE == 1.6renderer.apply_display_scale(1.4)- assert renderer.DISPLAY_SCALE == 1.0+ assert renderer.DISPLAY_SCALE == 1.4+ renderer.apply_display_scale(2.0)+ assert renderer.DISPLAY_SCALE == renderer.MAX_DISPLAY_SCALErenderer.apply_display_scale(0.1)assert renderer.DISPLAY_SCALE == renderer.MIN_DISPLAY_SCALE+# --------------------------------------------------------------------------- #+# physical-size-consistent scaling (compute_physical_scale / resolve_screen_scale)+# --------------------------------------------------------------------------- #+def test_physical_scale_is_base_at_the_reference_dpi():+ # The reference monitor is unchanged: at REFERENCE_RAW_DPI the physical scale+ # equals the resolution ceiling BASE_DISPLAY_SCALE (0.85) exactly — the fix+ # for the prior "too small" revert (anchor to the maintainer's own monitor).+ assert renderer.compute_physical_scale(renderer.REFERENCE_RAW_DPI) == pytest.approx(+ renderer.BASE_DISPLAY_SCALE+ )+++def test_physical_scale_holds_physical_size_constant_across_monitors():+ # Same resolution, DIFFERENT physical size (25" vs 30" 1440p) → different+ # pixel scale but the SAME physical size on the glass. This is the whole+ # point of the feature.+ import math++ def dpi(diag_in, w=2560, h=1440):+ return math.hypot(w, h) / diag_in++ sizes = []+ for diag in (25, 27, 30):+ d = dpi(diag)+ s = renderer.compute_physical_scale(d)+ physical_mm = (82 * s) * 25.4 / d # WIN_W(1.0 baseline)=82 px × scale, in mm+ sizes.append(physical_mm)+ # All within a small tolerance (integer-pixel + floor rounding at 30").+ assert max(sizes) - min(sizes) < 0.5, sizes+++def test_denser_monitor_gets_more_pixels_coarser_gets_fewer():+ dense = renderer.compute_physical_scale(220.0) # e.g. a small 4K panel+ coarse = renderer.compute_physical_scale(90.0) # e.g. a big 1080p panel+ assert dense > renderer.BASE_DISPLAY_SCALE+ assert coarse < renderer.BASE_DISPLAY_SCALE+++def test_physical_scale_clamps_and_rejects_implausible_dpi():+ # A plausible-but-very-dense DPI (≤ PHYSICAL_DPI_MAX) whose raw scale exceeds+ # the ceiling clamps to MAX; a plausible-but-coarse one floors at MIN.+ assert renderer.compute_physical_scale(340.0) == renderer.MAX_DISPLAY_SCALE+ assert renderer.compute_physical_scale(80.0) == renderer.MIN_DISPLAY_SCALE+ # Outside the plausibility gate / non-finite / non-numeric → None (fallback).+ for bad in (0, -5, 5, 400, 1000, float("nan"), float("inf"), None, "oops"):+ assert renderer.compute_physical_scale(bad) is None # type: ignore[arg-type]+++def test_resolve_screen_scale_prefers_physical_else_falls_back():+ # With a plausible dpi → physical; without / implausible → resolution model.+ assert renderer.resolve_screen_scale(+ 3840, 2160, renderer.REFERENCE_RAW_DPI+ ) == pytest.approx(renderer.BASE_DISPLAY_SCALE)+ assert renderer.resolve_screen_scale(3840, 2160, None) == renderer.compute_display_scale(+ 3840, 2160+ )+ assert renderer.resolve_screen_scale(3840, 2160, 5.0) == renderer.compute_display_scale(+ 3840, 2160+ )++# --------------------------------------------------------------------------- ## renderer integration ## --------------------------------------------------------------------------- #