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.

feat(ui): screen-adaptive JarvisBar sizing — small screens shrink, big monitors keep the approved look

Ruben Lütke6804c111796a
diff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.py
index 33da96ef31..dbc8006a86 100644
--- a/jarvis/ui/jarvisbar/overlay.py
+++ b/jarvis/ui/jarvisbar/overlay.py
@@ -565,13 +565,35 @@ class JarvisBarOverlay:
log.debug("jarvisbar DPI-awareness setup skipped", exc_info=True)
self._tk_thread_id = threading.get_ident()
- self._renderer = renderer.JarvisBarRenderer(accent=self._accent)
# Some window managers map Tk's default-size root eagerly. Hide it
# before assigning ``self._root`` or applying any styles so that stale
# backing surface can never flash at the top-left on a later wake.
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".
+ try:
+ renderer.apply_display_scale(
+ renderer.compute_display_scale(
+ int(root.winfo_screenwidth()), int(root.winfo_screenheight())
+ )
+ )
+ if renderer.DISPLAY_SCALE != 1.0:
+ log.info(
+ "jarvisbar display scale %.3f for screen %sx%s",
+ renderer.DISPLAY_SCALE,
+ root.winfo_screenwidth(),
+ root.winfo_screenheight(),
+ )
+ except Exception: # noqa: BLE001 — sizing is cosmetic; 1.0 is the degrade
+ log.debug("jarvisbar display-scale probe failed", exc_info=True)
+ self._renderer = renderer.JarvisBarRenderer(accent=self._accent)
root.title("JarvisBar")
# Give the bar the Jarvis mascot icon on every OS. Tk otherwise inherits
# the interpreter's process icon (pythonw.exe → Python logo on Windows,
diff --git a/jarvis/ui/jarvisbar/renderer.py b/jarvis/ui/jarvisbar/renderer.py
index 8b1e73c8dc..095f286983 100644
--- a/jarvis/ui/jarvisbar/renderer.py
+++ b/jarvis/ui/jarvisbar/renderer.py
@@ -18,7 +18,7 @@ Gold only appears during activity; idle dots stay muted.
from __future__ import annotations
import math
-from dataclasses import dataclass
+from dataclasses import dataclass, field
import numpy as np
from PIL import Image, ImageDraw
@@ -63,35 +63,87 @@ _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) -------------
+# 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
+# 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
+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).
+
+ Never enlarges beyond 1.0 (big monitors keep the approved look); shrinks
+ proportionally on screens smaller than the reference in either axis;
+ clamps at ``MIN_DISPLAY_SCALE``. Invalid input degrades to 1.0.
+ """
+ try:
+ sw, sh = int(screen_w), int(screen_h)
+ except (TypeError, ValueError):
+ return 1.0
+ if sw <= 0 or sh <= 0:
+ return 1.0
+ s = min(1.0, sw / REFERENCE_SCREEN_W, sh / REFERENCE_SCREEN_H)
+ return max(MIN_DISPLAY_SCALE, round(s, 3))
+
+
# 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.
# - ACTIVE: the conversation pill — DOUBLE the open size, shown the whole
# time a voice session is live (listen/speak/think). This is the
# "make the bar much bigger while talking" feature.
-COLLAPSED_W = round(168 * _SW * _IDLE_W) # standby pill (no dots, slightly longer)
-COLLAPSED_H = round(30 * _SH * _IDLE_H) # standby pill (slim)
-OPEN_W = round(284 * _SW) # hover/controls pill (the former "expanded" size)
-OPEN_H = round(52 * _SH)
# Conversation pill: 2x the open pill, then trimmed so it doesn't read as bulky.
# Width loses 15% off EACH side (→ 0.70 of 2x = 30% narrower); height loses 5%
# off top AND bottom (→ 0.90 of 2x = 10% shorter). The pill stays centred, so
# the idle bar keeps its middle resting spot.
_ACTIVE_SIDE_TRIM = 0.15 # fraction removed from each side of the 2x width
_ACTIVE_VERT_TRIM = 0.05 # fraction removed from top and bottom of the 2x height
-ACTIVE_W = round(2 * OPEN_W * (1.0 - 2 * _ACTIVE_SIDE_TRIM)) # 2x * 0.70
-ACTIVE_H = round(2 * OPEN_H * (1.0 - 2 * _ACTIVE_VERT_TRIM)) # 2x * 0.90
# The pill is anchored by its BOTTOM edge this many px above the window bottom,
# so the idle pill keeps its usual resting spot and the active pill grows
-# UPWARD (never down into the taskbar). Tune to nudge the resting height.
-_BOTTOM_PAD = 10
+# UPWARD (never down into the taskbar). Tune _BASE_BOTTOM_PAD to nudge the
+# resting height.
+_BASE_BOTTOM_PAD = 10
-# The fixed Tk window must contain the largest (ACTIVE) pill + its 2px outline
-# and the flanking hover controls. overlay.py reads these dynamically, so the
-# window auto-resizes when the pill sizes change.
-WIN_W = ACTIVE_W + 12
-WIN_H = ACTIVE_H + _BOTTOM_PAD + 4
+
+def apply_display_scale(scale: float) -> None:
+ """Recompute every derived geometry constant for ``scale``.
+
+ Called once by ``overlay.start()`` (one bar per process) before any
+ window geometry or renderer state derives from these values; module load
+ applies 1.0, which reproduces the historical constants byte-identically.
+ ``overlay.py`` reads the module attributes dynamically, so the window
+ follows the recomputed sizes.
+ """
+ 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)))
+ 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")
+ OPEN_H = round(52 * _SH * s)
+ ACTIVE_W = round(2 * OPEN_W * (1.0 - 2 * _ACTIVE_SIDE_TRIM)) # 2x * 0.70
+ ACTIVE_H = round(2 * OPEN_H * (1.0 - 2 * _ACTIVE_VERT_TRIM)) # 2x * 0.90
+ _BOTTOM_PAD = max(4, round(_BASE_BOTTOM_PAD * s))
+ # The fixed Tk window must contain the largest (ACTIVE) pill + its 2px
+ # outline and the flanking hover controls.
+ WIN_W = ACTIVE_W + 12
+ WIN_H = ACTIVE_H + _BOTTOM_PAD + 4
+
+
+apply_display_scale(1.0)
N_BARS = 10 # slim strokes, count matched to a dictation app (was 15 = too many)
# Inner animation geometry is expressed as fractions of the LIVE pill size, so
@@ -406,9 +458,13 @@ def orbit_trail(
@dataclass
class _RenderState:
+ # default_factory (not a plain default): the collapsed size must be read
+ # at INSTANTIATION time, after apply_display_scale() may have rescaled
+ # the module geometry — a plain default would freeze the import-time value.
display_level: float = 0.0
- pw: float = float(COLLAPSED_W) # live pill width, eased toward the target
- ph: float = float(COLLAPSED_H) # live pill height, eased toward the target
+ # live pill width/height, eased toward the target
+ pw: float = field(default_factory=lambda: float(COLLAPSED_W))
+ ph: float = field(default_factory=lambda: float(COLLAPSED_H))
class JarvisBarRenderer:
diff --git a/tests/unit/ui/jarvisbar/test_display_scale.py b/tests/unit/ui/jarvisbar/test_display_scale.py
new file mode 100644
index 0000000000..1d57b78fec
--- /dev/null
+++ b/tests/unit/ui/jarvisbar/test_display_scale.py
@@ -0,0 +1,121 @@
+"""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:
+
+1. Screens at least as big as the reference keep the EXACT historical look
+ (scale 1.0 must reproduce 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
+ freeze) and renders frames at the recomputed window size.
+"""
+from __future__ import annotations
+
+import pytest
+
+from jarvis.ui.jarvisbar import renderer
+
+
[email protected](autouse=True)
+def _restore_scale():
+ """Every test leaves the module at the default 1.0 geometry."""
+ yield
+ renderer.apply_display_scale(1.0)
+
+
+# --------------------------------------------------------------------------- #
+# compute_display_scale #
+# --------------------------------------------------------------------------- #
+def test_reference_and_bigger_screens_keep_scale_one():
+ assert renderer.compute_display_scale(1920, 1080) == 1.0
+ assert renderer.compute_display_scale(2560, 1440) == 1.0
+ assert renderer.compute_display_scale(3840, 2160) == 1.0
+
+
+def test_small_laptop_screen_shrinks_proportionally():
+ # A 14" MacBook is ~1512 Tk points wide → width is the binding axis.
+ s = renderer.compute_display_scale(1512, 982)
+ assert s == pytest.approx(1512 / 1920, abs=0.001)
+ assert s < 1.0
+
+
+def test_height_can_be_the_binding_axis():
+ # Ultra-wide but flat screen: the height ratio must win.
+ s = renderer.compute_display_scale(2560, 900)
+ assert s == pytest.approx(900 / 1080, abs=0.001)
+
+
+def test_tiny_screen_clamps_at_the_floor():
+ assert renderer.compute_display_scale(800, 600) == renderer.MIN_DISPLAY_SCALE
+
+
+def test_invalid_screen_degrades_to_one():
+ assert renderer.compute_display_scale(0, 0) == 1.0
+ assert renderer.compute_display_scale(-1, 1080) == 1.0
+ assert renderer.compute_display_scale(None, None) == 1.0 # type: ignore[arg-type]
+
+
+# --------------------------------------------------------------------------- #
+# apply_display_scale #
+# --------------------------------------------------------------------------- #
+# The maintainer-approved desktop look — scale 1.0 must reproduce these
+# byte-identically (regression guard for "my monitor size was perfect").
+_HISTORICAL = {
+ "COLLAPSED_W": 48,
+ "COLLAPSED_H": 8,
+ "OPEN_W": 68,
+ "OPEN_H": 19,
+ "ACTIVE_W": 95,
+ "ACTIVE_H": 34,
+ "WIN_W": 107,
+ "WIN_H": 48,
+}
+
+
+def test_scale_one_is_the_historical_geometry():
+ renderer.apply_display_scale(1.0)
+ for name, value in _HISTORICAL.items():
+ assert getattr(renderer, name) == value, name
+
+
+def test_scale_recomputes_geometry_and_restores_cleanly():
+ renderer.apply_display_scale(0.6)
+ assert renderer.DISPLAY_SCALE == 0.6
+ assert renderer.OPEN_W == round(68.16 * 0.6)
+ assert renderer.WIN_W < _HISTORICAL["WIN_W"]
+ assert renderer.WIN_H < _HISTORICAL["WIN_H"]
+ # Window still contains the biggest pill.
+ assert renderer.WIN_W > renderer.ACTIVE_W
+ assert renderer.WIN_H > renderer.ACTIVE_H
+ renderer.apply_display_scale(1.0)
+ for name, value in _HISTORICAL.items():
+ assert getattr(renderer, name) == value, name
+
+
+def test_scale_never_enlarges_and_never_undershoots_the_floor():
+ renderer.apply_display_scale(1.4)
+ assert renderer.DISPLAY_SCALE == 1.0
+ renderer.apply_display_scale(0.1)
+ assert renderer.DISPLAY_SCALE == renderer.MIN_DISPLAY_SCALE
+
+
+# --------------------------------------------------------------------------- #
+# renderer integration #
+# --------------------------------------------------------------------------- #
+def test_render_state_reads_scale_at_instantiation_time():
+ renderer.apply_display_scale(0.6)
+ r = renderer.JarvisBarRenderer()
+ assert r._st.pw == float(renderer.COLLAPSED_W) # noqa: SLF001
+ assert r._st.ph == float(renderer.COLLAPSED_H) # noqa: SLF001
+
+
+def test_render_produces_frames_at_the_scaled_window_size():
+ renderer.apply_display_scale(0.6)
+ img = renderer.JarvisBarRenderer().render(0.5, "listen", 0.4)
+ assert img.size == (renderer.WIN_W, renderer.WIN_H)
+ renderer.apply_display_scale(1.0)
+ img = renderer.JarvisBarRenderer().render(0.5, "listen", 0.4)
+ assert img.size == (_HISTORICAL["WIN_W"], _HISTORICAL["WIN_H"])