feat(desktop): support Ctrl/Cmd + mouse wheel zoom (#40295)

Ground-truth reapply of PR #40414 by @liuhao1024. The original branch
predates the ts-ify migration and implemented the gesture by injecting
a DOM wheel listener via executeJavaScript + a new IPC channel. Current
Electron surfaces the modifier+wheel gesture natively as the main-process
webContents 'zoom-changed' event, so the salvage uses that instead:
no renderer injection, no new preload surface, no new IPC channel.

The handler routes through setAndPersistZoomLevel — the same
persist+notify funnel as the keyboard shortcuts — so wheel zoom uses
the same 0.1 half-step, persists to zoom-state.json across restarts,
and keeps the settings Scale control in sync. Session windows get the
gesture automatically via wireCommonWindowHandlers; the pet overlay
stays opted out via zoomWiringForWindowKind.
This commit is contained in:
liuhao1024 2026-07-18 10:05:30 -07:00 committed by Teknium
parent 5988fe6cd5
commit ad0ddfb15d

View file

@ -4984,6 +4984,18 @@ function installZoomShortcuts(window) {
setAndPersistZoomLevel(window, window.webContents.getZoomLevel() - ZOOM_STEP)
}
})
// Ctrl/Cmd + mouse wheel — the standard desktop/browser zoom gesture
// (#40295). Chromium surfaces it as the main-process 'zoom-changed' event
// (wheel events are DOM-side, so before-input-event never sees them).
// Route through the same persist+notify funnel as the keyboard shortcuts
// so wheel zoom survives restarts and the settings Scale control stays in
// sync, and use the same half step for consistency.
window.webContents.on('zoom-changed', (event, zoomDirection) => {
event.preventDefault()
const delta = zoomDirection === 'in' ? ZOOM_STEP : -ZOOM_STEP
setAndPersistZoomLevel(window, window.webContents.getZoomLevel() + delta)
})
}
function installContextMenu(window) {