Application window opens oversized and off-screen on multi-monitor setups
Summary
On opening, the app's window is oversized and ends up partially off-screen in a multi-monitor setup.
Environment
- Currently running OpenHuman v0.61.8
- The measurements below were captured while running v0.61.2
- Primary monitor: 2560×1600 @ 150% scaling
- Secondary monitor: 1920×1080 @ 100% scaling, positioned to the left of the primary monitor
- Diagnostic tool used: WinLister (Nirsoft)
Behavior on Opening the App
- Window size comes in at 3875×1626 px
- WinLister shows the window's origin as (0, 0), but the actual position is estimated closer to (9, 0) - about 9 px to the right of the true left edge of the primary monitor
- Since the window's width (3875 px) is far larger than the primary monitor's width (2560 px), part of the window extends past the right edge of the screen
- The secondary monitor sits to the left of the primary (not the right), so the overflowing part of the window doesn't land on it either
- Vertically, the part of the window that sits too high goes under the PowerTools dock and the Windows taskbar, and extends even further beyond that
Screenshots
Implementation Plan
Triage Assessment
This issue is relevant and not a duplicate. On a Windows multi-monitor setup (primary 2560x1600 @ 150% scaling, secondary 1920x1080 @ 100% scaling to the left), the application window opens at 3875x1626 with origin at (0,0), exceeding the primary monitor's 2560-pixel width. The window is oversized and partially off-screen. The window state management code at app/src-tauri/src/window_state.rs clamps to monitor work areas, but the bug suggests this clamping fails or runs too late on Windows with mixed DPI scaling.
Proposed Scope
In-scope:
- Fix the window size clamping on Windows with mixed-DPI multi-monitor setups.
- Ensure the window never exceeds any single monitor's work area on initial display.
Explicit non-goals:
- Changing how Tauri/CEF initializes the window (the initial window is created by Tauri before our window_state code runs).
- Supporting window spanning across monitors (user intent is single-monitor window).
Implementation Steps
-
Root-cause the 3875x1626 dimension
- The reported width 3875 = ~2560 * 1.514 (close to 150% DPI), and height 1626 = ~1080 * 1.506. This strongly suggests the window size is computed from the logical resolution of the wrong monitor and applied at 1x DPI scale.
- File:
app/src-tauri/src/window_state.rsfunctioncenter_main(line 225-268). This runs on initial window creation when no saved state exists. It callswindow.outer_size()at line 230, which returns the physical size set bytauri.conf.jsondefaults. The clamp at line 238 usesmonitor.width/heightfrom eitherprimary_monitor()orcurrent_monitor(). - On Windows with mixed DPI (150% on primary, 100% on secondary),
current_monitor()might return the secondary monitor (which has its origin at negative x since it's to the left). Theclamp_sizefunction would then clamp to 1920x1080 (secondary's physical size) but the window is already at 3875x1626, suggestingclamp_sizeran BEFOREset_sizeresolved the DPI, or returned a value in logical pixels that was then applied as physical pixels. - The root cause is likely in the Tauri/CEF window initialization: the browser viewport is resolved against the primary monitor's scaled resolution, but the window chrome/chromium compositor computes the window size before the Tauri
setup()hook (wherecenter_mainis called) has a chance to clamp it.
-
Fix clamping -- ensure proper monitor targeting
- File:
app/src-tauri/src/window_state.rsfunctioncenter_main(line 225). Current:primary_or_current_work_areapicks the primary monitor orcurrent_monitor. - On Windows, when the secondary monitor is to the left and
current_monitor()returns the secondary, the window is sized for the wrong monitor. Change the priority: usecurrent_monitor()first (the monitor the window was created on), and if the window is on the virtual desktop boundary (origin near 0,0 on a secondary-to-the-left setup), fall back toprimary_monitor(). - Add a check: if the computed clamped width exceeds 95% of the target monitor's work area width after clamping, re-clamp with a warning log.
- File:
-
Add early clamping in Tauri init
- File:
app/src-tauri/src/lib.rs(the Tauri setup function). Immediately after window creation and beforewindow_state::restore_main/center_main, set an initial maximum size constraint on the window. This prevents the browser compositor from allocating a viewport larger than the target monitor's work area before the Rust geometry code runs. - Use
window.set_max_size(Some(PhysicalSize::new(max_w, max_h)))wheremax_w/max_hcome fromprimary_monitor().work_area().
- File:
-
Add Windows-specific diagnostic logging
- File:
app/src-tauri/src/window_state.rs-- add detailed DPI/monitor logging on Windows when the initial window size exceeds the monitor work area:log::warn!("[window-state] INITIAL window size {}x{} exceeds monitor work area {}x{} (monitor: idx={}, dpi={}, work_area=({},{}))", ...) - Log all available monitors and their work areas + DPI scale factors at startup so the bug can be diagnosed from logs.
- File:
Verification
- Unit tests (Rust):
app/src-tauri/src/window_state.rsinline tests -- add tests forclamp_to_work_areawith:- A window whose physical size exceeds the selected monitor's work area (simulating the 3875x1626 scenario).
- Mixed DPI: monitor A at 150% scale, monitor B at 100%, window origin falling on the virtual desktop boundary.
- Add test that
pick_monitor_for_windowcorrectly handles a multi-monitor layout where the secondary is to the left of the primary.
- Manual verification (Windows with multi-monitor):
- Recreate the user's setup: primary 2560x1600 @ 150%, secondary 1920x1080 @ 100% to the left.
- Launch the app. Window should open at a reasonable size (fit within primary's work area) and be centered on the primary monitor.
- Move the window to the secondary monitor, close, reopen. Window should restore on the correct monitor at correct size.
- E2E verification: The existing desktop E2E test suite (
app/test/e2e/specs/) should include a smoke test that checks the main window's dimensions are withincurrentMonitor.workArea.
Risks and Open Questions
- The Tauri/CEF init order. The window is created by Tauri's native event loop before the Rust
setup()hook runs. The CEF browser viewport may be allocated during Tauri's internal window creation, before we can constrain it. This means even withset_max_sizeinsetup(), the initial frame might already be oversized. The fix may need to use Tauri'son_window_eventto catchResizedevents and clamp post-hoc. - Virtual desktop coordinates on Windows. Windows treats all monitors as a single virtual desktop, with coordinates extending negative for monitors left/above the primary. The origin at (0,0) from WinLister plus a 3875-wide window means the window covers primary.x=0 to primary.x=2560 plus an overflow. The virtual desktop right at the primary's right edge is x=2560, but the window extends to x=3875, meaning it goes off-screen to the right. The clamp should bring this in.
- Secondary monitor to the left of primary. The
MIN_VISIBLE_OVERLAP_PXthreshold (100px) at line 75 should handle this correctly: when saved state is on the secondary monitor,pick_monitor_for_windowmatches by overlap, not by origin proximity.
Acceptance Criteria
- On a multi-monitor Windows setup with mixed DPI scaling, the application window opens at a size that fits within the primary monitor's work area.
- The 3875x1626 oversized window no longer occurs with no saved state (fresh install or after clearing window_state.toml).
- The window is centered on the chosen monitor after initial size resolution.
- Diagnostic logging captures monitor layout and DPI at startup so future edge cases can be debugged from logs.