Skip to content

fix(desktop): re-assert zoom on display topology changes - #76908

Open
kaishi00 wants to merge 1 commit into
NousResearch:mainfrom
kaishi00:fix/desktop-zoom-display-events
Open

kaishi00 wants to merge 1 commit into
NousResearch:mainfrom
kaishi00:fix/desktop-zoom-display-events

Conversation

@kaishi00

@kaishi00 kaishi00 commented Aug 2, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes a remaining trigger for the long-standing zoom reset bug (#60693): Chromium silently resets webContents zoom when the display topology changes — monitors going to sleep, waking with stagger, or being connected/disconnected.

These events fire on Electron's screen module, not on the BrowserWindow, so the existing window-level reassert in installZoomReassertOnWindowEvents (added in #66988) never runs. On multi-monitor setups with staggered wake (common on Windows), window-level resized/moved events may also arrive before all displays have settled, causing the persisted zoom to be applied and immediately overwritten by a later display change.

Root Cause

The existing zoom reassert covers three trigger categories:

Trigger Where it fires Covered by
Window resize, minimize/restore, cross-display move BrowserWindow events installZoomReassertOnWindowEvents (#66988)
Renderer load / reload / crash recovery webContents.did-finish-load #46429 / #61925
Display topology change (monitor sleep/wake/connect/disconnect) screen module events ❌ Not covered → this PR

The codebase already uses this exact screen.on() pattern for the macOS wake indicator repositioning (main.ts:11835-11839), so this PR follows an established precedent.

Changes Made

  • apps/desktop/electron/zoom.ts: Add installZoomReassertOnDisplayEvents(screen, win, reassert) — subscribes to display-metrics-changed, display-added, and display-removed on the screen module with a 300ms debounce (vs 100ms for window resize) to absorb staggered multi-monitor wake. Cleans up all listeners on window close.
  • apps/desktop/electron/main.ts: Call the new function in wireCommonWindowHandlers alongside the existing window-level reassert, passing the already-imported screen from Electron.
  • apps/desktop/electron/zoom.test.ts: 5 new tests covering: event wiring, debounce coalescing, destroyed-window skip, listener cleanup on close, and no-op guards.

How to Test

  1. Set UI Scale to 125% in Settings
  2. Let monitors sleep (or disconnect/reconnect a display)
  3. Wake monitors — zoom stays at 125% instead of resetting to default
  4. vitest run apps/desktop/electron/zoom.test.ts — all zoom tests pass

Verified on Windows 11 with a 3-monitor setup over 3 days of daily monitor sleep/wake cycles — zoom persisted correctly after the fix where it previously reset ~50% of the time.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've added tests for my changes (required for bug fixes)
  • I've tested on my platform: Windows 11 (3-monitor setup, staggered wake)

Documentation & Housekeeping

  • N/A — no config keys, architecture changes, or tool behavior changes

Technical Details

Why 300ms debounce (not 100ms)? Multi-monitor wake is staggered: display 1 wakes at T+0, display 2 at T+150ms, display 3 at T+250ms. Each wake fires display-metrics-changed. The existing 100ms window-event debounce is too short — a reassert at T+100ms gets overwritten by the display-2 wake at T+150ms. 300ms lets all monitors settle before re-applying the persisted zoom.

Why pass screen as a parameter instead of importing it? Matches the existing installZoomReassertOnWindowEvents pattern where platform is passed in rather than read from globals — keeps the function pure and testable without booting Electron.

Listener cleanup. Each call to wireCommonWindowHandlers (main window + each session window) registers 3 screen.on() listeners. Without cleanup on win.on('closed'), these would accumulate across session windows and leak stale window references. The closed handler calls screen.off() for all three events.

Chromium silently resets webContents zoom when the display topology
changes — monitors going to sleep, waking with stagger, or being
connected/disconnected. These events fire on Electron's
module, not on the BrowserWindow, so the existing window-level reassert
in installZoomReassertOnWindowEvents never runs.

On multi-monitor setups with staggered wake (common on Windows),
window-level resized/moved events may also arrive before all displays
have settled, causing the persisted zoom to be applied and immediately
overwritten by a later display change.

Add installZoomReassertOnDisplayEvents in zoom.ts that subscribes to
screen.on('display-metrics-changed'), display-added, and
display-removed with a 300ms debounce (vs 100ms for window resize) to
absorb the stagger. Listeners are cleaned up on window close to avoid
leaks across session windows.

Follows the existing pattern already used by the wake indicator
(main.ts:11835-11839) for the same three screen events.

Closes NousResearch#60693
@teknium1

teknium1 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks for isolating the remaining display-topology path. Current main restores persisted zoom only through the BrowserWindow lifecycle hook and did-finish-load in apps/desktop/electron/main.ts:8690-8699; its helper has no screen event registration (apps/desktop/electron/zoom.ts:71-98).

PR commit b13ff3ebe72c75ff3fd123f613e5af99c23c1c79 adds the distinct Electron screen subscriptions, coalesces them with a trailing 300 ms debounce, and removes each listener when the associated chat window closes. The existing zoom: false helper-window exclusions remain intact because the wiring stays inside the existing if (zoom) branch. GitHub reports clean mergeability and passing desktop test/lint checks.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Aug 2, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/desktop Electron desktop app (apps/desktop/*) labels Aug 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/desktop Electron desktop app (apps/desktop/*) P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants