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
fix(jarvisbar): pin PER_MONITOR_AWARE, not UNAWARE - original size on every monitor
Ruben Lütke2f735d6e1108
diff --git a/jarvis/core/win32_dpi.py b/jarvis/core/win32_dpi.pyindex 258ce5ab60..75d8e8b427 100644--- a/jarvis/core/win32_dpi.py+++ b/jarvis/core/win32_dpi.py@@ -58,23 +58,31 @@ def ensure_dpi_awareness() -> None:_DPI_AWARENESS_SET = True-def pin_thread_dpi_unaware() -> bool:- """Pin the CALLING thread's DPI-awareness context to UNAWARE (Windows).-- Every top-level window the thread creates afterwards carries the UNAWARE- context PER WINDOW: Windows bitmap-scales it to the monitor's scale factor- (the familiar upscaled look on a 150 % display) and virtualises its- coordinate space — and, critically, a later PROCESS-level awareness flip- (pywebview's ``webview.start()`` calls ``user32.SetProcessDPIAware()`` at- runtime, ``webview/platforms/winforms.py``) can no longer strip that- scaling off the window. That flip is what made the JarvisBar shrink to- ~2/3, jump position, and drag with a large cursor offset (recurring,- boot-race dependent).-- The pin only survives such a flip when the process is ALREADY DPI-aware,- so call :func:`ensure_dpi_awareness` first. The context is deliberately- NOT restored — call this only from a thread fully owned by the unaware- surface (e.g. the bar's dedicated Tk mainloop thread).+def pin_thread_dpi_per_monitor() -> bool:+ """Pin the CALLING thread's DPI context to PER_MONITOR_AWARE (Windows).++ Every top-level window the thread creates afterwards carries that context+ PER WINDOW, which gives a fixed-pixel overlay (the JarvisBar) exactly the+ stable behaviour the maintainer wants:++ - it renders its RAW pixels on every monitor (the bar's original look) —+ DWM never bitmap-scales it, so moving it onto a monitor with a different+ scale factor (100 % secondary next to the 150 % primary) no longer+ shrinks it to ~2/3 with a drag cursor offset;+ - a later PROCESS-level awareness flip (pywebview's ``webview.start()``+ calls ``user32.SetProcessDPIAware()`` at runtime,+ ``webview/platforms/winforms.py``) cannot re-interpret the window —+ no more mid-session size/position jumps.++ Deliberately PER_MONITOR_AWARE and NOT unaware: an UNAWARE pin makes+ Windows upscale the window (a blurry, oversized "fat bar" on a scaled+ display) — the maintainer rejected that look twice (2026-07-01 session,+ commit 5c7a5d15). Do not "fix" this by pinning UNAWARE again.++ The pin only survives a later process flip when the process is ALREADY+ DPI-aware, so call :func:`ensure_dpi_awareness` first. The context is+ deliberately NOT restored — call this only from a thread fully owned by+ the pinned surface (e.g. the bar's dedicated Tk mainloop thread).Returns True when the pin took effect; False (graceful no-op) off Windowsor when the API is unavailable (pre-Windows-10-1607).@@ -87,12 +95,16 @@ def pin_thread_dpi_unaware() -> bool:set_ctx = ctypes.windll.user32.SetThreadDpiAwarenessContextset_ctx.restype = ctypes.c_void_pset_ctx.argtypes = [ctypes.c_void_p]- # DPI_AWARENESS_CONTEXT_UNAWARE == (DPI_AWARENESS_CONTEXT)-1- prev = set_ctx(ctypes.c_void_p(-1))- if prev is None:- logger.debug("SetThreadDpiAwarenessContext(-1) returned NULL")- return False- return True+ # Prefer PER_MONITOR_AWARE_V2 (-4, Win10 1703+); fall back to+ # PER_MONITOR_AWARE (-3, Win10 1607). Both prevent DWM bitmap scaling+ # and pin the context per-window; V2 additionally covers child windows+ # and non-client areas.+ for context in (-4, -3):+ prev = set_ctx(ctypes.c_void_p(context))+ if prev is not None:+ return True+ logger.debug("SetThreadDpiAwarenessContext(-4/-3) returned NULL")+ return Falseexcept (OSError, AttributeError):logger.debug("SetThreadDpiAwarenessContext unavailable", exc_info=True)return Falsediff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.pyindex 24191cebd3..127f464360 100644--- a/jarvis/ui/jarvisbar/overlay.py+++ b/jarvis/ui/jarvisbar/overlay.py@@ -241,27 +241,30 @@ class JarvisBarOverlay:# the per-window pin below can hold. Also fixes the HiDPI# "drag-teleport" (geometry vs pointer-event space drift) when the# bar wins the boot race.- # 2. ``pin_thread_dpi_unaware()`` — pin THIS thread (the bar's- # dedicated Tk mainloop thread) to the UNAWARE context so the Tk- # root created below carries it per-window: Windows scales the bar- # to the monitor's factor (its familiar size on a 150 % display)- # and keeps its coordinate space virtualised/consistent. Without- # the pin the window follows the PROCESS context, and pywebview's- # ``webview.start()`` flips that at runtime- # (``user32.SetProcessDPIAware()``) — a boot race that shrank the- # bar to ~2/3 raw pixels, jumped its position, and desynced- # dragging (recurring bug, GIF forensic 2026-07-02). With the pin- # the bar looks identical to its historical (unaware-built) self- # and is immune to any later process-level flip.+ # 2. ``pin_thread_dpi_per_monitor()`` — pin THIS thread (the bar's+ # dedicated Tk mainloop thread) so the Tk root created below+ # carries a PER-WINDOW per-monitor context: the bar renders its+ # RAW pixels (its original, maintainer-approved look) on every+ # monitor, DWM never bitmap-scales it, and pywebview's runtime+ # ``SetProcessDPIAware()`` flip can no longer re-interpret it.+ # Without the pin the window follows the PROCESS context: it+ # DWM-shrank to ~2/3 when moved onto the 100 % secondary monitor+ # (next to the 150 % primary) and jumped size/position on the+ # boot-race flip (GIF forensics 2026-07-02).+ #+ # NEVER pin UNAWARE here: Windows then upscales the bar into a blurry+ # oversized "fat bar" — explicitly rejected by the maintainer twice+ # (2026-07-01 session, commit 5c7a5d15). The original look is RAW+ # pixels at a fixed size on every monitor.try:from jarvis.core.win32_dpi import (ensure_dpi_awareness,- pin_thread_dpi_unaware,+ pin_thread_dpi_per_monitor,)ensure_dpi_awareness()- if pin_thread_dpi_unaware():- log.debug("jarvisbar Tk thread pinned DPI-UNAWARE (per-window)")+ if pin_thread_dpi_per_monitor():+ log.debug("jarvisbar Tk thread pinned PER_MONITOR_AWARE (per-window)")except Exception: # noqa: BLE001 — never block the bar on a DPI hiccuplog.debug("jarvisbar DPI-awareness setup skipped", exc_info=True)diff --git a/tests/unit/ui/jarvisbar/test_dpi_awareness.py b/tests/unit/ui/jarvisbar/test_dpi_awareness.pyindex c85abb3e14..72f45b2d1d 100644--- a/tests/unit/ui/jarvisbar/test_dpi_awareness.py+++ b/tests/unit/ui/jarvisbar/test_dpi_awareness.py@@ -50,7 +50,7 @@ def _run_start_with_probes(monkeypatch) -> list[str]:lambda: order.append("dpi"),)monkeypatch.setattr(- "jarvis.core.win32_dpi.pin_thread_dpi_unaware",+ "jarvis.core.win32_dpi.pin_thread_dpi_per_monitor",lambda: order.append("pin") or True,)@@ -83,36 +83,38 @@ def test_start_sets_dpi_awareness_before_creating_tk_root(monkeypatch) -> None:)-def test_start_pins_thread_unaware_after_awareness_before_tk_root(monkeypatch) -> None:- """Regression (bar shrinks to ~2/3 / jumps / drag-offset, recurring): the- bar window used to follow the PROCESS DPI context, so it lost its 150 %- upscaling whenever pywebview's ``webview.start()`` flipped the process- awareness at runtime — a boot race that shrank the bar to raw pixels and- desynced the drag coordinates. The fix pins the bar's Tk thread (and thus- its window, per-window) to the UNAWARE context so Windows scales it- permanently and later process flips cannot touch it. Order matters: the- pin only holds when the process is already aware (ensure first), and it- must happen BEFORE the Tk root exists."""+def test_start_pins_thread_per_monitor_after_awareness_before_tk_root(monkeypatch) -> None:+ """Regression (bar shrinks ~1/3 when it moves / jumps / drag-offset): the+ bar window used to follow the PROCESS DPI context, so (a) pywebview's+ runtime ``SetProcessDPIAware()`` flip could re-interpret it mid-session and+ (b) as a system-aware window it was DWM-downscaled to 2/3 on the 100 %+ monitor next to the 150 % primary — the "shrinks when it changes position"+ bug. The fix pins the bar's Tk thread (and thus its window, per-window) to+ PER_MONITOR_AWARE so the bar renders its raw pixels (the ORIGINAL look —+ maintainer-confirmed 2026-07-02; an UNAWARE pin upscales it into the "fat+ bar" and was explicitly rejected) on EVERY monitor, immune to process+ flips and DWM bitmap scaling. Order matters: ensure first (the pin only+ holds in an aware process), pin BEFORE the Tk root exists."""order = _run_start_with_probes(monkeypatch)- assert "pin" in order, "start() must pin the bar thread DPI-UNAWARE"+ assert "pin" in order, "start() must pin the bar thread PER_MONITOR_AWARE"assert order.index("dpi") < order.index("pin") < order.index("tk"), (- "expected ensure_dpi_awareness -> pin_thread_dpi_unaware -> tk.Tk(); "+ "expected ensure_dpi_awareness -> pin_thread_dpi_per_monitor -> tk.Tk(); "f"got {order}")-def test_pin_thread_dpi_unaware_is_safe_everywhere() -> None:+def test_pin_thread_dpi_per_monitor_is_safe_everywhere() -> None:"""The pin helper never raises: True (pinned) on Windows with the modernAPI, False on other platforms / old Windows. Run in a throwaway thread sothe test runner's own thread context is never mutated."""import osimport threading- from jarvis.core.win32_dpi import pin_thread_dpi_unaware+ from jarvis.core.win32_dpi import pin_thread_dpi_per_monitorresult: list[bool] = []- t = threading.Thread(target=lambda: result.append(pin_thread_dpi_unaware()))+ t = threading.Thread(target=lambda: result.append(pin_thread_dpi_per_monitor()))t.start()t.join(timeout=5)@@ -121,3 +123,12 @@ def test_pin_thread_dpi_unaware_is_safe_everywhere() -> None:assert result[0] is False # graceful no-op off Windowselse:assert isinstance(result[0], bool)+++def test_unaware_pin_is_gone() -> None:+ """The UNAWARE pin produced the upscaled "fat bar" (maintainer-rejected+ twice: 2026-07-01 session and commit 5c7a5d15). It must not exist as an+ importable helper anyone could wire back in."""+ import jarvis.core.win32_dpi as dpi++ assert not hasattr(dpi, "pin_thread_dpi_unaware")