Skip to content

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.

fix(jarvisbar): keep the bar the same physical size on every display

Ruben Lütkee822cd7bdd76
diff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.py
index 0bb57e1f1e..901c0ffa33 100644
--- a/jarvis/ui/jarvisbar/overlay.py
+++ b/jarvis/ui/jarvisbar/overlay.py
@@ -600,24 +600,40 @@ class JarvisBarOverlay:
root = _create_hidden_tk_root(tk)
self._root = root
- # Screen-adaptive geometry (a dictation app-style): 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".
+ # Screen-adaptive geometry: keep the bar the same PHYSICAL size on
+ # every display. Must run BEFORE the renderer and any window geometry
+ # are derived from the module constants. Tk reports the screen's
+ # millimetres via winfo_screenmm* — real EDID values on a DPI-aware
+ # Windows (GetDeviceCaps HORZSIZE) and on X11/RandR. On macOS aqua-Tk
+ # SYNTHESIZES the mm from a fixed 72-dpi assumption, so the physical
+ # path must not be fed there (the macOS bar is Qt-hosted anyway, see
+ # host.py); the renderer's plausibility gates catch the remaining
+ # bogus-EDID cases and fall back to the resolution-relative scale.
try:
+ physical_w_mm: float | None = None
+ physical_h_mm: float | None = None
+ if sys.platform != "darwin":
+ try:
+ physical_w_mm = float(root.winfo_screenmmwidth())
+ physical_h_mm = float(root.winfo_screenmmheight())
+ except Exception: # noqa: BLE001 — mm probe is best-effort
+ log.debug("Tk screen-mm probe failed", exc_info=True)
renderer.apply_display_scale(
- renderer.compute_display_scale(
- int(root.winfo_screenwidth()), int(root.winfo_screenheight())
+ renderer.resolve_display_scale(
+ int(root.winfo_screenwidth()),
+ int(root.winfo_screenheight()),
+ physical_w_mm,
+ physical_h_mm,
)
)
if renderer.DISPLAY_SCALE != 1.0:
log.info(
- "jarvisbar display scale %.3f for screen %sx%s",
+ "jarvisbar display scale %.3f for screen %sx%s px / %sx%s mm",
renderer.DISPLAY_SCALE,
root.winfo_screenwidth(),
root.winfo_screenheight(),
+ physical_w_mm,
+ physical_h_mm,
)
except Exception: # noqa: BLE001 — sizing is cosmetic; 1.0 is the degrade
log.debug("jarvisbar display-scale probe failed", exc_info=True)
@@ -658,7 +674,7 @@ class JarvisBarOverlay:
root.configure(bg=COLOR_KEY_HEX)
# Window-level alpha ON TOP of the color key: the magenta stays fully
# keyed out (verified — no bleed) while the pill itself goes
- # semi-transparent, so the desktop shows through it (a dictation app-like).
+ # semi-transparent, so the desktop shows through it (glass look).
try:
root.wm_attributes("-alpha", self._opacity)
except tk.TclError:
diff --git a/jarvis/ui/jarvisbar/qt_overlay.py b/jarvis/ui/jarvisbar/qt_overlay.py
index b8dc6a84dc..b49ef30eb3 100644
--- a/jarvis/ui/jarvisbar/qt_overlay.py
+++ b/jarvis/ui/jarvisbar/qt_overlay.py
@@ -551,9 +551,34 @@ class QtJarvisBarOverlay:
screen = app.primaryScreen()
if screen is not None:
geometry = screen.geometry()
+ # Constant-physical-size bar: QScreen.physicalSize() is real
+ # millimetres from the OS display info; renderer plausibility
+ # gates fall back to the resolution-relative scale on bogus data.
+ physical_w_mm: float | None = None
+ physical_h_mm: float | None = None
+ try:
+ physical = screen.physicalSize()
+ physical_w_mm = float(physical.width())
+ physical_h_mm = float(physical.height())
+ except Exception: # noqa: BLE001 — sizing is cosmetic, never block
+ log.debug("QScreen physicalSize probe failed", exc_info=True)
renderer.apply_display_scale(
- renderer.compute_display_scale(geometry.width(), geometry.height())
+ renderer.resolve_display_scale(
+ geometry.width(),
+ geometry.height(),
+ physical_w_mm,
+ physical_h_mm,
+ )
)
+ if renderer.DISPLAY_SCALE != 1.0:
+ log.info(
+ "jarvisbar display scale %.3f for screen %sx%s px / %sx%s mm",
+ renderer.DISPLAY_SCALE,
+ geometry.width(),
+ geometry.height(),
+ physical_w_mm,
+ physical_h_mm,
+ )
self._renderer = renderer.JarvisBarRenderer(accent=self._accent)
window_type = _window_class()
diff --git a/jarvis/ui/jarvisbar/renderer.py b/jarvis/ui/jarvisbar/renderer.py
index 5ce11e628c..a08bd3b0de 100644
--- a/jarvis/ui/jarvisbar/renderer.py
+++ b/jarvis/ui/jarvisbar/renderer.py
@@ -55,7 +55,7 @@ MUTED_RED = (220, 80, 72)
# Size factors. ``_SCALE`` is the overall shrink (1.0 was the original, far too
# big). ``_W`` / ``_H`` then stretch width / height independently on top of it:
# _W < 1 narrows, _H > 1 makes it taller. Tune these three numbers to resize.
-_SCALE = 0.30 # overall size (was 0.336; -10% per a dictation app feedback)
+_SCALE = 0.30 # overall size (was 0.336; -10% per maintainer feedback)
_W = 0.8 # 20% narrower than the uniform _SCALE
_H = 1.2 # taller than the uniform _SCALE (was 1.5; -20% per feedback)
_IDLE_W = 1.2 # standby pill length — a touch longer so the standby dots fit
@@ -63,26 +63,32 @@ _IDLE_H = 0.7 # standby pill is slimmer (less "fat") than the active height
_SW = _SCALE * _W # combined horizontal factor
_SH = _SCALE * _H # combined vertical factor
-# --- screen-adaptive display scale (a dictation app-style relative sizing) -------------
+# --- screen-adaptive display scale (constant PHYSICAL size) ------------------
# The pill sizes below were tuned on a desktop monitor and are RAW pixels
-# (Tk points on macOS). On a small laptop screen (a 14" MacBook is ~1512 Tk
-# points wide) the same fixed size occupies nearly twice the relative width
-# and reads as clunky. ``DISPLAY_SCALE`` adapts the whole geometry to the
-# screen the bar actually lives on: 1.0 (the maintainer-approved look) on
-# anything at least REFERENCE_SCREEN_W x REFERENCE_SCREEN_H, proportionally
-# smaller below that, never under MIN_DISPLAY_SCALE so the controls stay
-# clickable. Scaling happens at RENDER time — the frame is drawn crisply at
+# (Tk points on macOS). A raw pixel is a different PHYSICAL size on every
+# display (a 24" 1080p monitor's pixel is ~1.4x the millimetres of a Retina
+# laptop point), so any fixed pixel geometry reads "perfect" on the screen it
+# was tuned on and clunky everywhere else. ``DISPLAY_SCALE`` therefore targets
+# a constant MILLIMETRE size: when the host can report the screen's physical
+# dimensions, ``compute_physical_scale`` converts the approved look into the
+# pixel budget that reproduces the same physical bar on THIS display. When the
+# physical size is unknown or implausible (broken EDID, VMs, projectors), the
+# resolution-relative ``compute_display_scale`` remains the fail-closed
+# fallback. Scaling happens at RENDER time — the frame is drawn crisply at
# the scaled size. This is NOT the blurry DPI bitmap upscaling that was
# explicitly rejected (see overlay.start()'s DPI notes); the DPI strategy
# there is untouched.
REFERENCE_SCREEN_W = 1920
REFERENCE_SCREEN_H = 1080
MIN_DISPLAY_SCALE = 0.55
+# Physical sizing may legitimately EXCEED 1.0 (a 4K screen at 100% OS scaling
+# has physically tiny pixels and needs more of them for the same millimetres).
+MAX_DISPLAY_SCALE = 2.0
DISPLAY_SCALE = 1.0
def compute_display_scale(screen_w: int, screen_h: int) -> float:
- """Scale factor for the screen the bar lives on (pure, unit-testable).
+ """Resolution-relative fallback scale (pure, unit-testable).
Never enlarges beyond 1.0 (big monitors keep the approved look); shrinks
proportionally on screens smaller than the reference in either axis;
@@ -98,6 +104,73 @@ def compute_display_scale(screen_w: int, screen_h: int) -> float:
return max(MIN_DISPLAY_SCALE, round(s, 3))
+# The approved look was signed off on a 14" MacBook Pro (1512x982 points,
+# 302.4x196.4 mm panel): 0.2 mm per point. ``compute_physical_scale``
+# reproduces exactly that millimetre geometry on every other display. The
+# reference scale is derived from ``compute_display_scale`` so the physical
+# path and the fallback path agree byte-identically on the reference laptop.
+_REFERENCE_PITCH_MM_PER_PX = 302.4 / 1512.0
+_REFERENCE_PHYSICAL_SCALE = compute_display_scale(1512, 982)
+# Plausibility bounds for host-reported physical data. Outside these, the
+# EDID/toolkit value is treated as garbage and the caller falls back to the
+# resolution-relative scale (fail closed, never a wildly wrong bar).
+_PLAUSIBLE_WIDTH_MM = (100.0, 1600.0)
+_PLAUSIBLE_HEIGHT_MM = (60.0, 1000.0)
+_PLAUSIBLE_PITCH_MM = (0.05, 0.45)
+_PLAUSIBLE_ASPECT_DRIFT = 0.25
+
+
+def compute_physical_scale(
+ screen_w: int,
+ screen_h: int,
+ physical_w_mm: float,
+ physical_h_mm: float,
+) -> float | None:
+ """Scale that keeps the bar the same PHYSICAL (mm) size on this screen.
+
+ Returns ``None`` whenever the reported physical dimensions are missing or
+ implausible — the caller must then fall back to
+ ``compute_display_scale``. Pure and unit-testable.
+ """
+ try:
+ sw, sh = int(screen_w), int(screen_h)
+ pw, ph = float(physical_w_mm), float(physical_h_mm)
+ except (TypeError, ValueError):
+ return None
+ if sw <= 0 or sh <= 0:
+ return None
+ if not (_PLAUSIBLE_WIDTH_MM[0] <= pw <= _PLAUSIBLE_WIDTH_MM[1]):
+ return None
+ if not (_PLAUSIBLE_HEIGHT_MM[0] <= ph <= _PLAUSIBLE_HEIGHT_MM[1]):
+ return None
+ pitch = pw / sw
+ if not (_PLAUSIBLE_PITCH_MM[0] <= pitch <= _PLAUSIBLE_PITCH_MM[1]):
+ return None
+ # The mm aspect ratio must roughly match the pixel aspect ratio; a large
+ # drift means the toolkit synthesized the mm from a DPI assumption or the
+ # EDID is bogus (both real-world failure modes on Tk/X11).
+ aspect_px = sw / sh
+ aspect_mm = pw / ph
+ if abs(aspect_mm / aspect_px - 1.0) > _PLAUSIBLE_ASPECT_DRIFT:
+ return None
+ s = _REFERENCE_PHYSICAL_SCALE * _REFERENCE_PITCH_MM_PER_PX / pitch
+ return max(MIN_DISPLAY_SCALE, min(MAX_DISPLAY_SCALE, round(s, 3)))
+
+
+def resolve_display_scale(
+ screen_w: int,
+ screen_h: int,
+ physical_w_mm: float | None = None,
+ physical_h_mm: float | None = None,
+) -> float:
+ """One entry point for callers: physical-size scale, else the fallback."""
+ if physical_w_mm is not None and physical_h_mm is not None:
+ s = compute_physical_scale(screen_w, screen_h, physical_w_mm, physical_h_mm)
+ if s is not None:
+ return s
+ return compute_display_scale(screen_w, screen_h)
+
+
# Three pill sizes (width, height), eased between as the state changes:
# - COLLAPSED: the slim idle standby pill (unchanged).
# - OPEN: the hover pill that reveals the X / dictation-square controls.
@@ -129,7 +202,7 @@ def apply_display_scale(scale: float) -> None:
"""
global DISPLAY_SCALE, COLLAPSED_W, COLLAPSED_H, OPEN_W, OPEN_H
global ACTIVE_W, ACTIVE_H, _BOTTOM_PAD, WIN_W, WIN_H
- DISPLAY_SCALE = s = max(MIN_DISPLAY_SCALE, min(1.0, float(scale)))
+ DISPLAY_SCALE = s = max(MIN_DISPLAY_SCALE, min(MAX_DISPLAY_SCALE, float(scale)))
COLLAPSED_W = round(168 * _SW * _IDLE_W * s) # standby pill (slightly longer)
COLLAPSED_H = round(30 * _SH * _IDLE_H * s) # standby pill (slim)
OPEN_W = round(284 * _SW * s) # hover/controls pill (the former "expanded")
@@ -145,18 +218,18 @@ def apply_display_scale(scale: float) -> None:
apply_display_scale(1.0)
-N_BARS = 10 # slim strokes, count matched to a dictation app (was 15 = too many)
+N_BARS = 10 # slim strokes (was 15 = too many)
# Inner animation geometry is expressed as fractions of the LIVE pill size, so
# the equalizer bars / wave grow together with the pill instead of staying a
# fixed size and looking lost in the big active bar.
_BAR_MAX_FRAC = 0.66 # equalizer max height / pill height
_BAR_MIN_FRAC = 0.10
_BARS_SPAN_FRAC = 0.62 # equalizer span / pill width (wider → room for more bars)
-_BAR_HALF_W_FRAC = 0.008 # half bar thickness / pill width (slim a dictation app strokes)
+_BAR_HALF_W_FRAC = 0.008 # half bar thickness / pill width (slim strokes)
_STROKE_W = max(2, round(3.0 * _SCALE)) # control stroke thickness (px)
# Standby dots: when nothing is said the pill shows a quiet row of dots
-# (a dictation app-style) instead of an empty pill. Muted so they read as "at rest".
+# instead of an empty pill. Muted so they read as "at rest".
DOT_COLOR = (150, 140, 120)
_N_DOTS = 7 # dots in the standby row
_DOT_R_FRAC = 0.16 # dot radius / pill height (small round dots, not chunky)
diff --git a/tests/unit/ui/jarvisbar/test_display_scale.py b/tests/unit/ui/jarvisbar/test_display_scale.py
index 1d57b78fec..40cab8400d 100644
--- a/tests/unit/ui/jarvisbar/test_display_scale.py
+++ b/tests/unit/ui/jarvisbar/test_display_scale.py
@@ -1,15 +1,23 @@
-"""Screen-adaptive bar geometry (a dictation app-style relative sizing).
-
-The bar's pill/window sizes are raw pixels tuned on a desktop monitor; on a
-small laptop screen the same fixed size reads as clunky (maintainer feedback,
-14" MacBook 2026-07-17). ``compute_display_scale`` derives a screen-relative
-factor and ``apply_display_scale`` recomputes the module geometry. These tests
-pin three contracts:
+"""Screen-adaptive bar geometry (constant physical size across displays).
+
+The bar's pill/window sizes are raw pixels; a raw pixel is a different
+physical size on every display, so a fixed pixel geometry reads "perfect"
+only on the screen it was tuned on (maintainer feedback, 14" MacBook
+2026-07-17; "way too big" on the desktop monitor 2026-07-21).
+``compute_physical_scale`` converts the approved look into the pixel budget
+that reproduces the same MILLIMETRE size on the actual display;
+``compute_display_scale`` stays the resolution-relative fallback for hosts
+with missing/implausible physical data; ``apply_display_scale`` recomputes
+the module geometry. These tests pin four contracts:
1. Screens at least as big as the reference keep the EXACT historical look
- (scale 1.0 must reproduce the old constants byte-identically).
+ under the fallback (scale 1.0 reproduces the old constants
+ byte-identically).
2. Small screens shrink proportionally, bounded by ``MIN_DISPLAY_SCALE``.
-3. The renderer picks up a rescale at instantiation time (no import-time
+3. Physical sizing is self-consistent on the reference laptop, shrinks on
+ physically-coarse monitors, may exceed 1.0 on physically-fine panels, and
+ REFUSES implausible physical data (``None`` → fallback).
+4. The renderer picks up a rescale at instantiation time (no import-time
freeze) and renders frames at the recomputed window size.
"""
from __future__ import annotations
@@ -58,6 +66,78 @@ def test_invalid_screen_degrades_to_one():
assert renderer.compute_display_scale(None, None) == 1.0 # type: ignore[arg-type]
+# --------------------------------------------------------------------------- #
+# compute_physical_scale / resolve_display_scale #
+# --------------------------------------------------------------------------- #
+# The reference laptop panel the approved look was signed off on:
+# 14" MacBook Pro, 1512x982 points on a 302.4x196.4 mm panel.
+_REF = (1512, 982, 302.4, 196.4)
+
+
+def test_physical_scale_reproduces_the_approved_look_on_the_reference_laptop():
+ s = renderer.compute_physical_scale(*_REF)
+ assert s == pytest.approx(renderer.compute_display_scale(1512, 982), abs=0.005)
+
+
+def test_physical_scale_shrinks_on_a_coarse_pixel_desktop_monitor():
+ # 24" 1080p (531x299 mm): each pixel is ~1.4x the reference millimetres,
+ # so the SAME physical bar needs ~40% fewer pixels — this is the exact
+ # "way too big on my monitor" complaint.
+ s = renderer.compute_physical_scale(1920, 1080, 531.0, 299.0)
+ assert s is not None
+ assert s < 0.65
+ ref = renderer.compute_physical_scale(*_REF)
+ assert ref is not None
+ # Same physical width on both screens (pixels x mm-per-pixel).
+ assert s * (531.0 / 1920) == pytest.approx(ref * (302.4 / 1512), rel=0.02)
+
+
+def test_physical_scale_may_exceed_one_on_fine_pixel_panels():
+ # 27" 4K at 100% OS scaling (596x335 mm): physically tiny pixels need
+ # MORE of them for the same millimetres — legal above 1.0 now.
+ s = renderer.compute_physical_scale(3840, 2160, 596.0, 335.0)
+ assert s is not None
+ assert 1.0 < s <= renderer.MAX_DISPLAY_SCALE
+
+
+def test_physical_scale_rejects_implausible_data():
+ assert renderer.compute_physical_scale(1920, 1080, 0.0, 0.0) is None
+ assert renderer.compute_physical_scale(1920, 1080, -531.0, 299.0) is None
+ # Toy values (a projector/VM EDID lying about a 5 cm panel).
+ assert renderer.compute_physical_scale(1920, 1080, 50.0, 30.0) is None
+ # Wall-sized values.
+ assert renderer.compute_physical_scale(1920, 1080, 3000.0, 1700.0) is None
+ # mm aspect wildly off the pixel aspect → synthesized/bogus data.
+ assert renderer.compute_physical_scale(1920, 1080, 531.0, 531.0) is None
+ assert renderer.compute_physical_scale(0, 0, 531.0, 299.0) is None
+ assert (
+ renderer.compute_physical_scale(1920, 1080, "x", "y") # type: ignore[arg-type]
+ is None
+ )
+
+
+def test_physical_scale_clamps_to_the_floor_and_ceiling():
+ # Enormous physical pixels (32"-class 1080p): clamps at the floor.
+ assert (
+ renderer.compute_physical_scale(1920, 1080, 708.0, 398.0)
+ == renderer.MIN_DISPLAY_SCALE
+ )
+
+
+def test_resolve_prefers_physical_and_falls_back_cleanly():
+ # Plausible mm → the physical result.
+ assert renderer.resolve_display_scale(*_REF) == renderer.compute_physical_scale(
+ *_REF
+ )
+ # Missing or implausible mm → the resolution-relative fallback.
+ assert renderer.resolve_display_scale(1512, 982) == renderer.compute_display_scale(
+ 1512, 982
+ )
+ assert renderer.resolve_display_scale(
+ 1512, 982, 50.0, 30.0
+ ) == renderer.compute_display_scale(1512, 982)
+
+
# --------------------------------------------------------------------------- #
# apply_display_scale #
# --------------------------------------------------------------------------- #
@@ -95,11 +175,19 @@ 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_ceiling_and_floor():
+ # Physical sizing may legitimately exceed 1.0 (fine-pixel panels), but
+ # never the ceiling; the floor keeps the controls clickable.
renderer.apply_display_scale(1.4)
- assert renderer.DISPLAY_SCALE == 1.0
+ assert renderer.DISPLAY_SCALE == 1.4
+ renderer.apply_display_scale(3.0)
+ assert renderer.DISPLAY_SCALE == renderer.MAX_DISPLAY_SCALE
renderer.apply_display_scale(0.1)
assert renderer.DISPLAY_SCALE == renderer.MIN_DISPLAY_SCALE
+ # An enlarged geometry still contains its biggest pill.
+ renderer.apply_display_scale(1.4)
+ assert renderer.WIN_W > renderer.ACTIVE_W
+ assert renderer.WIN_H > renderer.ACTIVE_H
# --------------------------------------------------------------------------- #