The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): scale the native window-controls overlay with zoom
Brooklyn Nicholson7c65f2d20f53
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex 855f9f3d4c0..56a06b23134 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -1384,7 +1384,7 @@ const TITLEBAR_OVERLAY_COLOR = 'rgba(1, 0, 0, 0)'// Electron's own overlay drifts its hit-region under RAIL, so the renderer// paints its own min/max/close (wslg-window-controls.tsx) over the// hermes:window-control IPC channel. See titleBarOverlayOptions.-function getTitleBarOverlayOptions() {+function getTitleBarOverlayOptions(win?) {return titleBarOverlayOptions({platform: IS_MAC ? 'mac' : IS_WINDOWS ? 'windows' : IS_WSL ? 'wslg' : 'linux',darwinMajor: DARWIN_MAJOR,@@ -1392,7 +1392,10 @@ function getTitleBarOverlayOptions() {color: TITLEBAR_OVERLAY_COLOR,foreground:rendererTitleBarTheme && isHexColor(rendererTitleBarTheme.foreground) ? rendererTitleBarTheme.foreground : null,- dark: nativeTheme.shouldUseDarkColors+ dark: nativeTheme.shouldUseDarkColors,+ // The native WCO buttons don't scale with the page; scale the overlay so+ // its height tracks the zoomed renderer titlebar (#81086).+ zoomFactor: win?.webContents?.getZoomFactor?.()})}@@ -1401,7 +1404,7 @@ function getTitleBarOverlayOptions() {// returns false; the try/catch additionally guards builds where// setTitleBarOverlay isn't supported.function applyTitleBarOverlay(win) {- const options = getTitleBarOverlayOptions()+ const options = getTitleBarOverlayOptions(win)if (!options || typeof options !== 'object') {return@@ -7080,6 +7083,10 @@ function setAndPersistZoomLevel(window, zoomLevel) {// changes made via the keyboard shortcuts or the View menu.const next = applyZoomLevel(window.webContents, zoomLevel)+ // The native window-controls overlay doesn't scale with the page; re-apply+ // it at the new zoom so its height tracks the zoomed titlebar (#81086).+ applyTitleBarOverlay(window)+// Primary store: main-process JSON (survives crash recovery — #56726).writeZoomState(next)// Secondary mirror: renderer localStorage (legacy store; kept in sync so a@@ -7118,6 +7125,7 @@ function restorePersistedZoomLevel(window) {}applyZoomLevel(window.webContents, saved)+ applyTitleBarOverlay(window)return}@@ -7126,6 +7134,7 @@ function restorePersistedZoomLevel(window) {// doesn't flash Chromium 100%, then try localStorage for pre-JSON installs// and overwrite if a legacy value is there.applyZoomLevel(window.webContents, DEFAULT_ZOOM_LEVEL)+ applyTitleBarOverlay(window)window.webContents.executeJavaScript(@@ -7139,6 +7148,7 @@ function restorePersistedZoomLevel(window) {const level = stored == null ? DEFAULT_ZOOM_LEVEL : Number(stored)const applied = applyZoomLevel(window.webContents, level)writeZoomState(applied)+ applyTitleBarOverlay(window)}).catch(error => rememberLog(`[zoom] restore failed: ${error?.message || error}`))}diff --git a/apps/desktop/electron/titlebar-overlay-width.test.ts b/apps/desktop/electron/titlebar-overlay-width.test.tsindex a7b6b99dce8..8d7ff448343 100644--- a/apps/desktop/electron/titlebar-overlay-width.test.ts+++ b/apps/desktop/electron/titlebar-overlay-width.test.ts@@ -7,6 +7,7 @@ import {macTitleBarOverlayHeight,nativeOverlayWidth,OVERLAY_FALLBACK_WIDTH,+ scaledOverlayHeight,titleBarOverlayOptions} from './titlebar-overlay-width'@@ -85,3 +86,66 @@ test('Tahoe (Darwin 25+) drops the overlay height to 0 to avoid electron#49183',test('macTitleBarOverlayHeight tolerates missing args (unknown platform → 0)', () => {assert.equal(macTitleBarOverlayHeight(), 0)})++// -- zoom-scaled overlay height (#81086) -------------------------------------++test('scaledOverlayHeight tracks the zoom factor in whole pixels', () => {+ assert.equal(scaledOverlayHeight(34, 1), 34)+ assert.equal(scaledOverlayHeight(34, 1.2), 41)+ assert.equal(scaledOverlayHeight(34, 0.9), 31)+})++test('scaledOverlayHeight clamps garbage input instead of breaking the overlay', () => {+ assert.equal(scaledOverlayHeight(34, NaN), 34)+ assert.equal(scaledOverlayHeight(34, 0), 34)+ assert.equal(scaledOverlayHeight(34, -2), 34)+ assert.equal(scaledOverlayHeight(NaN, 1.5), NaN)+})++test('scaledOverlayHeight never returns a zero-height overlay', () => {+ // Extreme zoom-out: the overlay API is integer-based and 0 would collapse it.+ assert.equal(scaledOverlayHeight(34, 0.01), 1)+})++test('titleBarOverlayOptions scales the Windows/Linux overlay height with zoom', () => {+ const base = { titlebarHeight: 34, color: 'transparent', foreground: '#ffffff', dark: false }++ assert.deepEqual(titleBarOverlayOptions({ platform: 'windows', ...base, zoomFactor: 1 }), {+ color: 'transparent',+ height: 34,+ symbolColor: '#ffffff'+ })+ assert.deepEqual(titleBarOverlayOptions({ platform: 'windows', ...base, zoomFactor: 1.2 }), {+ color: 'transparent',+ height: 41,+ symbolColor: '#ffffff'+ })+})++test('titleBarOverlayOptions keeps WSLg and macOS untouched by zoom', () => {+ // WSLg: renderer paints its own scaled controls. macOS: traffic lights,+ // positioned separately; a zoomed height would shove them out of place.+ assert.equal(+ titleBarOverlayOptions({ platform: 'wslg', titlebarHeight: 34, color: 'transparent', zoomFactor: 1.5 }),+ false+ )+ assert.deepEqual(+ titleBarOverlayOptions({+ platform: 'mac',+ darwinMajor: MACOS_TAHOE_DARWIN_MAJOR,+ titlebarHeight: 34,+ zoomFactor: 1.5+ }),+ { height: 0 }+ )+})++test('default zoom leaves the overlay byte-identical to today', () => {+ // zoomFactor defaults to 1: no caller change, no height change.+ const base = { titlebarHeight: 34, color: 'transparent', foreground: '#ffffff', dark: false }+ assert.deepEqual(titleBarOverlayOptions({ platform: 'windows', ...base }), {+ color: 'transparent',+ height: 34,+ symbolColor: '#ffffff'+ })+})diff --git a/apps/desktop/electron/titlebar-overlay-width.ts b/apps/desktop/electron/titlebar-overlay-width.tsindex ddb65e36ef7..71b7eed6559 100644--- a/apps/desktop/electron/titlebar-overlay-width.ts+++ b/apps/desktop/electron/titlebar-overlay-width.ts@@ -7,6 +7,8 @@ interface TitleBarOverlayOptionsInput {color?: stringforeground?: string | nulldark?: boolean+ /** Current webContents zoom factor (1 = 100%); scales the overlay height. */+ zoomFactor?: number}/**@@ -43,7 +45,8 @@ export function titleBarOverlayOptions({titlebarHeight = 0,color,foreground,- dark = false+ dark = false,+ zoomFactor = 1}: TitleBarOverlayOptionsInput = {}) {// Electron's Linux overlay keeps a narrow, unscaled three-button cluster// under WSLg. The renderer owns larger Windows-shaped controls there while@@ -58,11 +61,28 @@ export function titleBarOverlayOptions({return {color,- height: titlebarHeight,+ height: scaledOverlayHeight(titlebarHeight, zoomFactor),symbolColor: foreground || (dark ? '#f7f7f7' : '#242424')}}+/**+ * Scale the native window-controls overlay height with the webContents zoom+ * factor. Chromium scales the page (including the renderer's titlebar) but+ * not the native WCO buttons, so at any zoom other than 100% the fixed-height+ * overlay mismatches the titlebar it sits inside (#81086). Rounds to whole+ * pixels (the overlay API is integer-based) and never returns less than 1.+ */+export function scaledOverlayHeight(titlebarHeight: number, zoomFactor: number): number {+ if (!Number.isFinite(titlebarHeight) || titlebarHeight <= 0) {+ return titlebarHeight+ }++ const factor = Number.isFinite(zoomFactor) && zoomFactor > 0 ? zoomFactor : 1++ return Math.max(1, Math.round(titlebarHeight * factor))+}+// macOS Tahoe ships as Darwin 25 (Sequoia is 24); the Darwin number is truthful,// unlike the product version which macOS reports as 16 or 26 depending on the// build SDK.