From 1e84c6c317997e536a0d40f4dc135d0e0107a631 Mon Sep 17 00:00:00 2001 From: katipally Date: Sat, 21 Nov 2026 15:52:16 -0800 Subject: [PATCH 1/4] fix(desktop): keyboard zoom, UI scale and layouts for low vision (#60) Ctrl/Cmd + = (and +), -, 0 and the numpad keys zoom the main window through 75 to 300 percent, with an explicit View menu and a UI scale row in Settings. The scale is kept in appearance.json; every window runs an isolated zoom and the orb and owner are held at 100 percent. The window now opens no larger than the work area of its display, and its minimum size follows the display it is on. The call stage, top bar, home footer, text tokens and settings nav adapt to the room they have. --- CHANGELOG.md | 15 +++ apps/desktop/README.md | 9 ++ apps/desktop/electron-builder.yml | 1 + apps/desktop/main.cjs | 99 +++++++++++++-- apps/desktop/preload.cjs | 8 ++ apps/desktop/window-state.cjs | 28 ++++- apps/desktop/window-state.test.ts | 39 +++++- apps/desktop/zoom.cjs | 44 +++++++ apps/desktop/zoom.test.ts | 115 ++++++++++++++++++ apps/web/src/app/globals.css | 40 +++--- apps/web/src/app/page.tsx | 6 +- apps/web/src/components/ShortcutsSheet.tsx | 9 +- apps/web/src/components/live/AgentBar.tsx | 2 +- .../web/src/components/live/AgentControls.tsx | 2 +- apps/web/src/components/live/HintChips.tsx | 4 +- apps/web/src/components/live/InCall.tsx | 44 +++++-- apps/web/src/components/live/TopBar.tsx | 7 +- .../components/settings/GeneralSettings.tsx | 26 +++- .../src/components/settings/SettingsPage.tsx | 2 +- apps/web/src/lib/settingsSearch.ts | 1 + apps/web/src/lib/zoom.ts | 48 ++++++++ docs/DESIGN.md | 2 +- 22 files changed, 497 insertions(+), 54 deletions(-) create mode 100644 apps/desktop/zoom.cjs create mode 100644 apps/desktop/zoom.test.ts create mode 100644 apps/web/src/lib/zoom.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6eec38..da3eb8e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,21 @@ Releases before 0.1.9 predate this file — see the ## [Unreleased] +### Added +- **UI scale and zoom shortcuts.** Ctrl or Cmd with `=` (or `+`), `-` and `0` zoom the + window in, out and back to 100%, from 75% up to 300%, and Settings > General > UI scale + picks a size too. It is remembered, and the orb stays at its own size. (#60) + +### Fixed +- **Ctrl+= now zooms in.** Only Ctrl+- worked before, because the menu's zoom in needed Shift. +- **The window fits small and scaled screens.** A first launch opens at most as large as the + screen's usable area, centered, and the window can always be resized down to fit the screen + it is on, such as a 1080p laptop at 150% scaling. +- **Layouts hold up at large zoom.** The call's orb shrinks to the room it has instead of + overlapping the hints and controls, the top bar folds its chips to icons in a narrow window, + the home page's version no longer sits over the buttons, and text sizes follow the root + size. (#60) + ## [0.4.1] - 2026-11-11 ### Changed diff --git a/apps/desktop/README.md b/apps/desktop/README.md index 8fc3618e..2c946b6e 100644 --- a/apps/desktop/README.md +++ b/apps/desktop/README.md @@ -76,6 +76,15 @@ NSIS installers run unsigned (users see a SmartScreen warning). To sign, provide code-signing cert via electron-builder's `win.certificateFile` + `CSC_KEY_PASSWORD`, or an Azure Trusted Signing / EV cert. Not required to ship. +## Zoom + +`Ctrl`/`Cmd` + `=` (or `+`) zooms in, `-` zooms out, `0` resets, on the main window +only (also the numpad keys, and View in the menu). It moves through 75, 90, 100, +110, 125, 150, 175, 200, 250 and 300 percent, and Settings > General > UI scale +picks one too. The scale is kept in `/state/appearance.json`. The orb stays +at 100 percent. On a first launch the window opens at most as large as the work +area of the screen it is on, and its minimum size follows the screen it moves to. + ## What's in the package ``` diff --git a/apps/desktop/electron-builder.yml b/apps/desktop/electron-builder.yml index ec6ac489..65bb3eab 100644 --- a/apps/desktop/electron-builder.yml +++ b/apps/desktop/electron-builder.yml @@ -40,6 +40,7 @@ files: - splash.html - telemetry-map.cjs - window-state.cjs + - zoom.cjs - login-item.cjs - update-gate.cjs - prev-exit.cjs diff --git a/apps/desktop/main.cjs b/apps/desktop/main.cjs index 4d47d3db..c06d42f0 100644 --- a/apps/desktop/main.cjs +++ b/apps/desktop/main.cjs @@ -17,7 +17,8 @@ const flowRuntime = require("./flow-runtime.cjs"); const { osHasGlass, glassSupport, effectiveLook } = require("./look.cjs"); const orbPointer = require("./orb-pointer.cjs"); const { isExternalUrl } = require("./external-url.cjs"); -const { restoreWindow, windowSnapshot } = require("./window-state.cjs"); +const { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot } = require("./window-state.cjs"); +const { sameZoom, sanitizeZoom, nextZoom, zoomKeyAction, ZOOM_STEPS } = require("./zoom.cjs"); const { trayTemplate, orbOwner } = require("./tray-menu.cjs"); const { talkBindings, pttRouter } = require("./talk.cjs"); const { loginDefaultReady } = require("./login-item.cjs"); @@ -435,6 +436,7 @@ function agentArgs() { // ── window bounds: remember size, position, maximized and fullscreen ───────── const windowStateFile = () => stateFile("window-state.json"); const MAIN_MIN = { width: 940, height: 640 }; +const MAIN_PREFERRED = { width: 1180, height: 800 }; function loadWindowState() { let saved = null; try { saved = JSON.parse(fs.readFileSync(windowStateFile(), "utf8")); } catch { /* no saved state */ } @@ -444,6 +446,21 @@ function saveWindowState() { if (!mainWin || mainWin.isDestroyed()) return; try { writeAtomic(fs, windowStateFile(), JSON.stringify(windowSnapshot(mainWin))); } catch { /* best-effort */ } } +/** The work area of the display `bounds` sits on, or the primary's for a window with no place yet. */ +const workAreaOf = (bounds) => (bounds?.x != null ? screen.getDisplayMatching(bounds) : screen.getPrimaryDisplay()).workArea; +/** Keeps the window usable on the display it is on: its minimum never exceeds that + * work area and, when `reclamp`, a window that no longer fits is brought back inside it. + * Not on every move: pulling a window back mid-drag would fight the person dragging it. */ +function fitMainWindow(reclamp = true) { + if (!mainWin || mainWin.isDestroyed()) return; + const bounds = mainWin.getBounds(); + const work = workAreaOf(bounds); + const min = minFor(MAIN_MIN, work); + mainWin.setMinimumSize(min.width, min.height); + if (!reclamp || mainWin.isMaximized() || mainWin.isFullScreen() || mainWin.isMinimized()) return; + const fit = fitRect(bounds, work, MAIN_MIN); + if (["x", "y", "width", "height"].some((k) => fit[k] !== bounds[k])) mainWin.setBounds(fit); +} // ── one-time things (first ⌘Q notice, the login-item default) ──────────────── const onceFile = () => stateFile("once.json"); @@ -475,13 +492,15 @@ const CLEAR = "#00000000"; const PAGE_BG = { dark: "#0b0b0c", light: "#efede8" }; // --background in .dark / :root const THEMES = new Set(["system", "light", "dark"]); const appearanceFile = () => stateFile("appearance.json"); -let appearance = {}; // { theme, look, probe: { version, slow } } +let appearance = {}; // { theme, look, zoom, probe: { version, slow } } let look = "flat"; // what the main window wears right now let lookTimer = null; let winTransparencyOff = false; +let zoom = 1; // the main window's UI scale, one of ZOOM_STEPS function loadAppearance() { try { appearance = JSON.parse(fs.readFileSync(appearanceFile(), "utf8")) || {}; } catch { appearance = {}; } + zoom = sanitizeZoom(appearance.zoom); // Native surfaces (the material's tint, the title bar) follow the app's theme, not the OS's. nativeTheme.themeSource = THEMES.has(appearance.theme) ? appearance.theme : "system"; readWinTransparency(); @@ -602,6 +621,39 @@ function wireAppearance() { app.on("gpu-info-update", refreshLook); } +// ── zoom: the main window's UI scale, kept in appearance.json beside the theme ─ +// Chromium zooms per origin and every window here is on the same one, so a level +// set on the main window would scale the orb and the hidden owner with it. Every +// window therefore opens `zoomMode: "isolated"` (its own level), and the orb and +// the owner are held at 100% (holdZoom). +const zoomState = () => ({ factor: zoom, steps: ZOOM_STEPS }); + +/** Holds `wc` at `factor()` now and after every load, so a reload never leaves it at the origin's level. */ +function holdZoom(wc, factor) { + const apply = () => { if (!wc.isDestroyed() && !sameZoom(wc.getZoomFactor(), factor())) wc.setZoomFactor(factor()); }; + apply(); + wc.on("dom-ready", apply); +} + +function setZoom(v) { + const next = sanitizeZoom(v); + if (next !== zoom) { + zoom = next; + appearance.zoom = next; + saveAppearance(); + if (mainWin && !mainWin.isDestroyed()) { + mainWin.webContents.setZoomFactor(zoom); + mainWin.webContents.send("openlive:zoom-changed", zoomState()); + } + } + return zoomState(); +} + +function wireZoom() { + ipcMain.on("openlive:zoom", (e) => { e.returnValue = zoomState(); }); + ipcMain.handle("openlive:zoom-set", (e, v) => (isMainWc(e.sender) ? setZoom(v) : zoomState())); +} + // ── windows ────────────────────────────────────────────────────────────────── function createSplash() { splashWin = new BrowserWindow({ @@ -617,9 +669,11 @@ function createSplash() { function createMainWindow() { const saved = loadWindowState(); + const start = saved ?? firstRunWindow(MAIN_PREFERRED, screen.getDisplayNearestPoint(screen.getCursorScreenPoint()).workArea, MAIN_MIN); + const min = minFor(MAIN_MIN, workAreaOf(start)); mainWin = new BrowserWindow({ - width: saved?.width || 1180, height: saved?.height || 800, minWidth: MAIN_MIN.width, minHeight: MAIN_MIN.height, - ...(saved && saved.x != null ? { x: saved.x, y: saved.y } : {}), + width: start.width, height: start.height, minWidth: min.width, minHeight: min.height, + ...(start.x != null ? { x: start.x, y: start.y } : {}), show: false, // Never `transparent: true`: transparent windows take a slower macOS compositing // path that competes with the on-device WebGPU voice models (adds turn latency), @@ -641,6 +695,8 @@ function createMainWindow() { // in-origin) — keep it in the Chromium sandbox. The preload only uses // contextBridge/ipcRenderer, which are available in sandboxed preloads. sandbox: true, + // The UI scale is this window's own (see the zoom section), set before its first frame. + zoomMode: "isolated", zoomFactor: zoom, // A call keeps running while this window is minimised or hidden, and its // renderer runs the whole voice pipeline: throttled timers would wreck // turn-taking (hold timers, TTS drain). @@ -657,6 +713,18 @@ function createMainWindow() { }, }); for (const ev of ["resize", "move", "close", "maximize", "unmaximize", "enter-full-screen", "leave-full-screen"]) mainWin.on(ev, saveWindowState); + // A new display brings its own work area, so its minimum size has to follow. + mainWin.on("moved", () => fitMainWindow(false)); + holdZoom(mainWin.webContents, () => zoom); + // The menu's zoom accelerators are display only (menu click below). A key + // handled here is claimed, which stops the menu's own accelerator for it, so + // one press steps once, and it works on layouts where the menu's does not. + mainWin.webContents.on("before-input-event", (e, input) => { + const action = zoomKeyAction(input, process.platform); + if (!action) return; + e.preventDefault(); + setZoom(nextZoom(zoom, action)); + }); // A backstop for OS settings that change without telling nativeTheme. mainWin.on("focus", refreshLook); mainWin.on("focus", () => telemetry.markActiveDay("main_window")); @@ -727,8 +795,9 @@ function makePanelWindow(route, bounds) { // on Windows, and one the window manager never focuses on Linux. focusable: false, ...(process.platform === "darwin" ? { type: "panel" } : {}), - webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false }, + webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, zoomMode: "isolated", zoomFactor: 1 }, }); + holdZoom(win.webContents, () => 1); win.setAlwaysOnTop(true, "floating", 1); win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true, skipTransformProcessType: true }); // Electron's panel still activates OpenLive on a click, bringing the main @@ -805,8 +874,9 @@ function createOwnerWindow() { if (ownerWin && !ownerWin.isDestroyed()) return ownerWin; ownerWin = new BrowserWindow({ width: 480, height: 320, show: false, skipTaskbar: true, - webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, additionalArguments: agentArgs() }, + webPreferences: { preload: path.join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, backgroundThrottling: false, zoomMode: "isolated", zoomFactor: 1, additionalArguments: agentArgs() }, }); + holdZoom(ownerWin.webContents, () => 1); ownerWin.loadURL(`${WEB_URL}/flow-owner`); ownerWin.webContents.on("did-start-loading", () => { ownerReady = false; }); // Loaded means the web server answers, so Dictate's state can be read for the tray. @@ -1373,6 +1443,7 @@ function wireWindowIpc() { telemetry.track("remote_ollama_prompt", { outcome, scheme: u.protocol === "https:" ? "https" : "http" }); } }); + for (const ev of ["display-added", "display-removed", "display-metrics-changed"]) screen.on(ev, () => fitMainWindow()); ipcMain.on("openlive:win-close", () => { if (mainWin) mainWin.close(); }); ipcMain.on("openlive:win-min", () => { if (mainWin) mainWin.minimize(); }); ipcMain.on("openlive:win-zoom", () => { @@ -1564,6 +1635,11 @@ function buildMenu() { { label: `Close to ${isMac ? "Menu Bar" : "Tray"}`, accelerator: "CmdOrCtrl+Q", click: closeToMenuBar }, { label: "Quit OpenLive", click: () => quitApp("app_menu") }, ]; + // The role's Zoom In wants Shift (its accelerator is Ctrl+Plus), which left Ctrl+= dead. + // The key itself is handled in createMainWindow, so a click is all this item answers. + const zoomItem = (label, accelerator, action) => ({ + label, accelerator, click: (_item, _win, e) => { if (!e.triggeredByAccelerator) setZoom(nextZoom(zoom, action)); }, + }); const template = [ ...(isMac ? [{ role: "appMenu", submenu: [ { role: "about", label: "About OpenLive" }, @@ -1577,7 +1653,15 @@ function buildMenu() { { type: "separator" }, ...closeItems, ] }] : [{ label: "File", submenu: closeItems }]), { role: "editMenu" }, - { role: "viewMenu" }, + { label: "View", submenu: [ + { role: "reload" }, { role: "forceReload" }, { role: "toggleDevTools" }, + { type: "separator" }, + zoomItem("Actual Size", "CommandOrControl+0", "reset"), + zoomItem("Zoom In", "CommandOrControl+=", "in"), + zoomItem("Zoom Out", "CommandOrControl+-", "out"), + { type: "separator" }, + { role: "togglefullscreen" }, + ] }, { role: "windowMenu" }, { role: "help", submenu: [ { label: "OpenLive on GitHub", click: () => shell.openExternal("https://github.com/katipally/openlive") }, @@ -1693,6 +1777,7 @@ async function boot() { loadAppearance(); loadPreferences(); wireAppearance(); + wireZoom(); wirePermissions(); wirePanelIpc(); wireNotifyIpc(); diff --git a/apps/desktop/preload.cjs b/apps/desktop/preload.cjs index 40d328cc..35e889be 100644 --- a/apps/desktop/preload.cjs +++ b/apps/desktop/preload.cjs @@ -54,6 +54,14 @@ contextBridge.exposeInMainWorld("openlive", { set: (patch) => ipcRenderer.invoke("openlive:appearance-set", patch), onChange: (cb) => listen("openlive:appearance-changed", cb), }, + // The main window's UI scale, the same way: `get` is synchronous. Resolves / + // delivers { factor, steps }, `factor` being one of `steps` (1 is 100%). `set` + // takes a factor and snaps it to the nearest step; the shortcuts move it too. + zoom: { + get: () => ipcRenderer.sendSync("openlive:zoom"), + set: (factor) => ipcRenderer.invoke("openlive:zoom-set", factor), + onChange: (cb) => listen("openlive:zoom-changed", cb), + }, // Product-usage telemetry. Main checks every message against its schema and keeps // nothing else; only the main window and Flow's owner are heard. get() resolves to // { active, enabled, noticeSeen, installIdTail, username, feedback, appVersion, osName, osMajor }, and diff --git a/apps/desktop/window-state.cjs b/apps/desktop/window-state.cjs index 7877f8fa..120cf88b 100644 --- a/apps/desktop/window-state.cjs +++ b/apps/desktop/window-state.cjs @@ -35,9 +35,35 @@ function restoreWindow(saved, { displays, primary, min }) { }; } +/** The smallest the window may be on `work`: its minimum, or the whole work + * area where that is smaller, so a small or heavily scaled screen never has a + * window it cannot fit. */ +const minFor = (min, work) => ({ width: Math.min(min.width, work.width), height: Math.min(min.height, work.height) }); + +/** `rect` shrunk to fit `work` (not under `minFor`) and pulled inside it. */ +function fitRect(rect, work, min) { + const m = minFor(min, work); + const width = Math.round(clamp(rect.width, m.width, work.width)); + const height = Math.round(clamp(rect.height, m.height, work.height)); + return { + x: Math.round(clamp(rect.x, work.x, work.x + work.width - width)), + y: Math.round(clamp(rect.y, work.y, work.y + work.height - height)), + width, height, + }; +} + +/** The first launch's window: `preferred` size, shrunk to the work area of the + * display it opens on and centered in it. */ +function firstRunWindow(preferred, work, min) { + const m = minFor(min, work); + const width = Math.round(clamp(preferred.width, m.width, work.width)); + const height = Math.round(clamp(preferred.height, m.height, work.height)); + return { x: work.x + Math.round((work.width - width) / 2), y: work.y + Math.round((work.height - height) / 2), width, height }; +} + /** What to save: the bounds it returns to, whatever state it is in now. */ function windowSnapshot(win) { return { ...win.getNormalBounds(), maximized: win.isMaximized(), fullscreen: win.isFullScreen() }; } -module.exports = { restoreWindow, windowSnapshot }; +module.exports = { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot }; diff --git a/apps/desktop/window-state.test.ts b/apps/desktop/window-state.test.ts index 606d5592..5edf9b79 100644 --- a/apps/desktop/window-state.test.ts +++ b/apps/desktop/window-state.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { createRequire } from "node:module"; -const { restoreWindow, windowSnapshot } = createRequire(import.meta.url)("./window-state.cjs"); +const { restoreWindow, minFor, fitRect, firstRunWindow, windowSnapshot } = createRequire(import.meta.url)("./window-state.cjs"); const display = (x: number, y: number, width: number, height: number) => ({ workArea: { x, y, width, height } }); const laptop = display(0, 25, 1440, 875); // macOS: under the menu bar @@ -45,6 +45,43 @@ describe("restoreWindow", () => { }); }); +describe("minFor", () => { + it("is the minimum where the work area holds it, and the work area where it does not", () => { + expect(minFor(min, laptop.workArea)).toEqual(min); + expect(minFor(min, { x: 0, y: 0, width: 640, height: 480 })).toEqual({ width: 640, height: 480 }); + expect(minFor(min, { x: 0, y: 0, width: 1920, height: 400 })).toEqual({ width: 940, height: 400 }); + }); +}); + +describe("fitRect", () => { + it("leaves a window that fits where it is", () => { + expect(fitRect({ x: 100, y: 100, width: 1000, height: 700 }, laptop.workArea, min)).toEqual({ x: 100, y: 100, width: 1000, height: 700 }); + }); + it("shrinks a window the work area cannot hold and pulls it inside", () => { + expect(fitRect({ x: 300, y: 300, width: 1180, height: 800 }, { x: 0, y: 0, width: 1024, height: 576 }, min)) + .toEqual({ x: 0, y: 0, width: 1024, height: 576 }); + expect(fitRect({ x: -200, y: 900, width: 1000, height: 700 }, laptop.workArea, min)).toEqual({ x: 0, y: 200, width: 1000, height: 700 }); + }); + it("never goes under the minimum the work area allows", () => { + expect(fitRect({ x: 0, y: 0, width: 100, height: 100 }, laptop.workArea, min)).toMatchObject({ width: 940, height: 640 }); + }); +}); + +describe("firstRunWindow", () => { + const preferred = { width: 1180, height: 800 }; + it("opens the preferred size centered in a work area that holds it", () => { + expect(firstRunWindow(preferred, laptop.workArea, min)).toEqual({ x: 130, y: 63, width: 1180, height: 800 }); + expect(firstRunWindow(preferred, external.workArea, min)).toEqual({ x: 2130, y: 300, width: 1180, height: 800 }); + }); + it("shrinks to a work area that cannot hold it, such as 1080p at 150 percent", () => { + expect(firstRunWindow(preferred, { x: 0, y: 0, width: 1280, height: 672 }, min)).toEqual({ x: 50, y: 0, width: 1180, height: 672 }); + expect(firstRunWindow(preferred, { x: 0, y: 0, width: 1000, height: 600 }, min)).toEqual({ x: 0, y: 0, width: 1000, height: 600 }); + }); + it("fills a work area smaller than the minimum, never spilling off it", () => { + expect(firstRunWindow(preferred, { x: 10, y: 20, width: 800, height: 500 }, min)).toEqual({ x: 10, y: 20, width: 800, height: 500 }); + }); +}); + describe("windowSnapshot", () => { it("keeps the normal bounds under a maximized or fullscreen window", () => { const win = { getNormalBounds: () => ({ x: 10, y: 20, width: 1000, height: 700 }), isMaximized: () => false, isFullScreen: () => true }; diff --git a/apps/desktop/zoom.cjs b/apps/desktop/zoom.cjs new file mode 100644 index 00000000..1b883188 --- /dev/null +++ b/apps/desktop/zoom.cjs @@ -0,0 +1,44 @@ +"use strict"; +// The main window's UI scale: the steps it moves in, and the keys that move it. +// Pure, so the main process and its tests share one answer. + +/** Zoom factors as Chromium takes them (1.25 is 125 percent), 75 to 300 percent. */ +const ZOOM_STEPS = [0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3]; + +/** A zoom level round-trips through a logarithm, so a factor read back is only + * this close to the one set. The steps are much further apart. */ +const sameZoom = (a, b) => Math.abs(a - b) < 1e-3; + +const num = (v) => typeof v === "number" && Number.isFinite(v); + +/** The step nearest `v`, or 100 percent for anything that is not a number. Ties go to the smaller. */ +function sanitizeZoom(v) { + if (!num(v)) return 1; + return ZOOM_STEPS.reduce((best, s) => (Math.abs(s - v) < Math.abs(best - v) ? s : best)); +} + +/** Where "in", "out" or "reset" takes `current`, which may sit between steps or + * outside the range: the next step in that direction, held at the ends. */ +function nextZoom(current, action) { + if (action === "reset") return 1; + const from = num(current) ? current : 1; + if (action === "in") return ZOOM_STEPS.find((s) => s > from && !sameZoom(s, from)) ?? ZOOM_STEPS.at(-1); + if (action === "out") return ZOOM_STEPS.findLast((s) => s < from && !sameZoom(s, from)) ?? ZOOM_STEPS[0]; + return sanitizeZoom(from); +} + +const BY_KEY = { "=": "in", "+": "in", "-": "out", _: "out", 0: "reset" }; +// The numpad reports its own code whatever NumLock does to its key. +const BY_CODE = { NumpadAdd: "in", NumpadSubtract: "out", Numpad0: "reset" }; + +/** What a `before-input-event` key press asks of the zoom: "in", "out", "reset" + * or null. Ctrl on Windows and Linux, Cmd on a Mac; Shift is allowed, since + * "+" is Shift and "=" on most keyboards. By `key`, not `code`, so a layout + * with "+" or "-" elsewhere still works. */ +function zoomKeyAction(input, platform) { + if (input.type !== "keyDown" || input.alt) return null; + const mod = platform === "darwin" ? input.meta && !input.control : input.control && !input.meta; + return mod ? BY_CODE[input.code] ?? BY_KEY[input.key] ?? null : null; +} + +module.exports = { ZOOM_STEPS, sameZoom, sanitizeZoom, nextZoom, zoomKeyAction }; diff --git a/apps/desktop/zoom.test.ts b/apps/desktop/zoom.test.ts new file mode 100644 index 00000000..6d0ab57b --- /dev/null +++ b/apps/desktop/zoom.test.ts @@ -0,0 +1,115 @@ +import { describe, expect, it } from "vitest"; +import { createRequire } from "node:module"; + +const { ZOOM_STEPS, sameZoom, sanitizeZoom, nextZoom, zoomKeyAction } = createRequire(import.meta.url)("./zoom.cjs"); + +describe("ZOOM_STEPS", () => { + it("run from 75 to 300 percent, ascending, with 100 among them", () => { + expect(ZOOM_STEPS[0]).toBe(0.75); + expect(ZOOM_STEPS.at(-1)).toBe(3); + expect(ZOOM_STEPS).toContain(1); + expect([...ZOOM_STEPS].sort((a: number, b: number) => a - b)).toEqual(ZOOM_STEPS); + }); +}); + +describe("sanitizeZoom", () => { + it("keeps a step as it is", () => { + for (const s of ZOOM_STEPS) expect(sanitizeZoom(s)).toBe(s); + }); + it("snaps anything else to the nearest step, held inside the range", () => { + expect(sanitizeZoom(1.12)).toBe(1.1); + expect(sanitizeZoom(1.4)).toBe(1.5); + expect(sanitizeZoom(0.1)).toBe(0.75); + expect(sanitizeZoom(-4)).toBe(0.75); + expect(sanitizeZoom(50)).toBe(3); + expect(sanitizeZoom(Infinity)).toBe(1); + }); + it("answers 100 percent for what is not a number", () => { + for (const v of [NaN, undefined, null, "1.5", {}, [], true]) expect(sanitizeZoom(v)).toBe(1); + }); +}); + +describe("sameZoom", () => { + it("forgives the logarithm's rounding and nothing near a step", () => { + expect(sameZoom(1.1, 1.1000000000000003)).toBe(true); + expect(sameZoom(1, 1.1)).toBe(false); + }); +}); + +describe("nextZoom", () => { + it("moves one step at a time", () => { + expect(nextZoom(1, "in")).toBe(1.1); + expect(nextZoom(1, "out")).toBe(0.9); + expect(nextZoom(0.9, "out")).toBe(0.75); + expect(nextZoom(2, "in")).toBe(2.5); + }); + it("holds at the ends", () => { + expect(nextZoom(3, "in")).toBe(3); + expect(nextZoom(0.75, "out")).toBe(0.75); + }); + it("goes to the next step from between two, and from outside the range", () => { + expect(nextZoom(1.05, "in")).toBe(1.1); + expect(nextZoom(1.05, "out")).toBe(1); + expect(nextZoom(5, "in")).toBe(3); + expect(nextZoom(5, "out")).toBe(3); + expect(nextZoom(0.5, "in")).toBe(0.75); + expect(nextZoom(0.5, "out")).toBe(0.75); + }); + it("is not thrown by a factor read back a hair off its step", () => { + expect(nextZoom(1.1000000000000003, "in")).toBe(1.25); + expect(nextZoom(1.0999999999999999, "out")).toBe(1); + }); + it("resets to 100 percent from anywhere, and treats a broken current as 100", () => { + for (const c of [0.75, 1, 1.37, 3, NaN, undefined]) expect(nextZoom(c, "reset")).toBe(1); + expect(nextZoom(NaN, "in")).toBe(1.1); + expect(nextZoom(undefined, "out")).toBe(0.9); + }); + it("snaps for an action it does not know", () => { + expect(nextZoom(1.4, "sideways")).toBe(1.5); + }); +}); + +describe("zoomKeyAction", () => { + const key = (o: object) => ({ type: "keyDown", key: "", code: "", control: false, meta: false, shift: false, alt: false, ...o }); + const ctrl = (o: object) => key({ control: true, ...o }); + const cmd = (o: object) => key({ meta: true, ...o }); + + it("reads Ctrl on Windows and Linux", () => { + for (const p of ["win32", "linux"]) { + expect(zoomKeyAction(ctrl({ key: "=", code: "Equal" }), p)).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "+", code: "Equal", shift: true }), p)).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "Minus" }), p)).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "_", code: "Minus", shift: true }), p)).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "0", code: "Digit0" }), p)).toBe("reset"); + } + }); + it("reads Cmd on a Mac", () => { + expect(zoomKeyAction(cmd({ key: "=", code: "Equal" }), "darwin")).toBe("in"); + expect(zoomKeyAction(cmd({ key: "-", code: "Minus" }), "darwin")).toBe("out"); + expect(zoomKeyAction(cmd({ key: "0", code: "Digit0" }), "darwin")).toBe("reset"); + }); + it("reads the numpad by its code, with NumLock on or off", () => { + expect(zoomKeyAction(ctrl({ key: "+", code: "NumpadAdd" }), "win32")).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "NumpadSubtract" }), "win32")).toBe("out"); + expect(zoomKeyAction(ctrl({ key: "0", code: "Numpad0" }), "win32")).toBe("reset"); + expect(zoomKeyAction(ctrl({ key: "Insert", code: "Numpad0" }), "win32")).toBe("reset"); + expect(zoomKeyAction(cmd({ key: "+", code: "NumpadAdd" }), "darwin")).toBe("in"); + }); + it("finds a layout's own plus and minus by what they type", () => { + expect(zoomKeyAction(ctrl({ key: "+", code: "BracketRight" }), "linux")).toBe("in"); + expect(zoomKeyAction(ctrl({ key: "-", code: "Slash" }), "linux")).toBe("out"); + }); + it("needs the platform's modifier and no other", () => { + expect(zoomKeyAction(key({ key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(cmd({ key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "=" }), "darwin")).toBeNull(); + expect(zoomKeyAction(key({ key: "=", control: true, meta: true }), "darwin")).toBeNull(); + // AltGr arrives as Ctrl+Alt on Windows and types characters. + expect(zoomKeyAction(ctrl({ key: "-", alt: true }), "win32")).toBeNull(); + }); + it("answers a press, not its release, and no other key", () => { + expect(zoomKeyAction(ctrl({ type: "keyUp", key: "=" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "r", code: "KeyR" }), "win32")).toBeNull(); + expect(zoomKeyAction(ctrl({ key: "1", code: "Digit1" }), "win32")).toBeNull(); + }); +}); diff --git a/apps/web/src/app/globals.css b/apps/web/src/app/globals.css index cfb03003..aaea1360 100644 --- a/apps/web/src/app/globals.css +++ b/apps/web/src/app/globals.css @@ -98,27 +98,27 @@ /* ── Type scale — the ONLY font sizes in the app. Each token is a Tailwind text-* utility (text-micro, text-caption, …). Desktop-app scale: denser than web defaults, aligned to the SF/Segoe optical sizes. ────────────── */ - --text-micro: 10px; /* smallest legal size: keycaps, badges */ - --text-micro--line-height: 14px; - --text-caption: 11px; /* secondary metadata, eyebrows, timestamps */ - --text-caption--line-height: 15px; - --text-label: 12px; /* control labels, list secondary text */ - --text-label--line-height: 16px; - --text-body: 13px; /* default UI + chat text */ - --text-body--line-height: 20px; - --text-callout: 14px; /* emphasized body, primary buttons */ - --text-callout--line-height: 20px; - --text-title-sm: 15px; /* card titles, section headers */ - --text-title-sm--line-height: 21px; - --text-title: 17px; /* page/panel titles */ - --text-title--line-height: 23px; - --text-title-lg: 22px; /* screen headlines */ - --text-title-lg--line-height: 27px; - --text-display: 32px; /* the hero wordmark only */ - --text-display--line-height: 38px; + --text-micro: 0.625rem; /* smallest legal size: keycaps, badges */ + --text-micro--line-height: 0.875rem; + --text-caption: 0.6875rem; /* secondary metadata, eyebrows, timestamps */ + --text-caption--line-height: 0.9375rem; + --text-label: 0.75rem; /* control labels, list secondary text */ + --text-label--line-height: 1rem; + --text-body: 0.8125rem; /* default UI + chat text */ + --text-body--line-height: 1.25rem; + --text-callout: 0.875rem; /* emphasized body, primary buttons */ + --text-callout--line-height: 1.25rem; + --text-title-sm: 0.9375rem; /* card titles, section headers */ + --text-title-sm--line-height: 1.3125rem; + --text-title: 1.0625rem; /* page/panel titles */ + --text-title--line-height: 1.4375rem; + --text-title-lg: 1.375rem; /* screen headlines */ + --text-title-lg--line-height: 1.6875rem; + --text-display: 2rem; /* the hero wordmark only */ + --text-display--line-height: 2.375rem; /* legacy alias — same metrics as body */ - --text-chat: 13px; - --text-chat--line-height: 21px; + --text-chat: 0.8125rem; + --text-chat--line-height: 1.3125rem; /* One radius system. sm: chips' inner marks, badges, checkboxes, tooltips, menu items. md: fields, selects, segmented tracks, list rows. lg: cards and diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index 6babdbcf..6f29481f 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -168,7 +168,7 @@ export default function Home() { ) : ( -
+
{/* Frameless-window drag handle: a title-bar-high strip clear of the macOS traffic lights and the Windows/Linux caption buttons, both (the server cannot tell which this window has). Desktop only (.desktop). Settings lives in the hero CTA row @@ -177,7 +177,7 @@ export default function Home() {
-
+

OpenLive

@@ -207,7 +207,7 @@ export default function Home() {
-
+
{appVersion ? `v${appVersion}` : "dev"} diff --git a/apps/web/src/components/ShortcutsSheet.tsx b/apps/web/src/components/ShortcutsSheet.tsx index 6d4e9531..7a02a28f 100644 --- a/apps/web/src/components/ShortcutsSheet.tsx +++ b/apps/web/src/components/ShortcutsSheet.tsx @@ -15,8 +15,8 @@ import { useMotionTokens } from "@/lib/motion"; type Row = { label: string; keys: string[] }; type Group = { title: string; note?: string; rows: Row[] }; -// Only what is really bound. Settings and ⌘Q are native menu accelerators and -// the talk keys live in the desktop shell, so the browser build leaves them out. +// Only what is really bound. Settings and ⌘Q are native menu accelerators, zoom is the +// desktop shell's, and the talk keys live there too, so the browser build leaves them out. // Flow's, Dictate's and push to talk's groups come from the person's own keys. const APP_GROUPS: Group[] = [ { title: "Anywhere in OpenLive", rows: [ @@ -24,6 +24,11 @@ const APP_GROUPS: Group[] = [ ...(isDesktop ? [{ label: "Settings", keys: [MOD, ","] }] : []), { label: "Keyboard shortcuts", keys: ["?"] }, ...(isDesktop ? [{ label: `Close to ${isMac ? "menu bar" : "tray"}`, keys: [MOD, "Q"] }] : []), + ...(isDesktop ? [ + { label: "Zoom in", keys: [MOD, "="] }, + { label: "Zoom out", keys: [MOD, "-"] }, + { label: "Reset zoom", keys: [MOD, "0"] }, + ] : []), ] }, ]; const CALL_GROUPS: Group[] = [ diff --git a/apps/web/src/components/live/AgentBar.tsx b/apps/web/src/components/live/AgentBar.tsx index 105ea4ff..4bb0829a 100644 --- a/apps/web/src/components/live/AgentBar.tsx +++ b/apps/web/src/components/live/AgentBar.tsx @@ -33,7 +33,7 @@ function PillMenu({ icon: Icon, label, title, items, current, onPick, footer }: diff --git a/apps/web/src/components/live/AgentControls.tsx b/apps/web/src/components/live/AgentControls.tsx index 1894b6c8..d059b5bf 100644 --- a/apps/web/src/components/live/AgentControls.tsx +++ b/apps/web/src/components/live/AgentControls.tsx @@ -96,7 +96,7 @@ export function AgentSelect({ up = false, pending = false }: { up?: boolean; pen {pending ? null : boundAgent ? : } - {label} + {label} {mounted && ( diff --git a/apps/web/src/components/live/HintChips.tsx b/apps/web/src/components/live/HintChips.tsx index 62355426..00e93124 100644 --- a/apps/web/src/components/live/HintChips.tsx +++ b/apps/web/src/components/live/HintChips.tsx @@ -28,7 +28,9 @@ export function HintChips({ className }: { className?: string }) { {hints.map((h) => ( + className={cn("pointer-events-auto flex max-w-md items-center gap-2 rounded-full py-1.5 pl-3 pr-1.5 shadow-card surface-float", + // Tips give way to the orb when the stage is short; an error's fix never does. + !h.id.startsWith("err") && "[@container_stage_(max-height:28rem)]:hidden")}> {h.id.startsWith("err") ? : } {h.text} {h.action && ( diff --git a/apps/web/src/components/live/InCall.tsx b/apps/web/src/components/live/InCall.tsx index d70378d1..c5653918 100644 --- a/apps/web/src/components/live/InCall.tsx +++ b/apps/web/src/components/live/InCall.tsx @@ -104,6 +104,20 @@ export function InCall(props: InCallProps) { }, []); const overlay = bodyW - panelW < STAGE_MIN; + // The orb takes the room its box has, up to that box's own design size (rem), + // so a short or zoomed window shrinks it instead of letting it collide with the + // lines under it. Measured before paint, so it never shows at a stale size. + const orbBox = useRef(null); + const [orbSize, setOrbSize] = useState(0); + useLayoutEffect(() => { + const el = orbBox.current; + if (!el) return; + setOrbSize(Math.min(el.clientWidth, el.clientHeight)); + const ro = new ResizeObserver(([e]) => setOrbSize(Math.floor(Math.min(e!.contentRect.width, e!.contentRect.height)))); + ro.observe(el); + return () => ro.disconnect(); + }, [sharing]); + // In-call keyboard shortcuts (Enter already belongs to hold-commit). // Skipped while Settings, a prompt or any modal is up, when typing or choosing // in a field, and when a modifier is involved, except ⌘E (end). @@ -137,12 +151,16 @@ export function InCall(props: InCallProps) {
{/* stage — orb hero, floating tiles, control bar */} -
+ {/* The stage is a size container, so its secondary lines can give way to the + orb by the stage's own height (not the window's) at any zoom. */} +
{!sharing && ( -
- +
+
+ {orbSize > 0 && } +
-
+
)} @@ -162,10 +180,13 @@ export function InCall(props: InCallProps) { )} - {/* Status pill (orb + caption) while sharing — floats ABOVE the control bar + {/* Stacked in flow above the bottom edge, so whatever is shown (the sharing + pill, hints) takes its own height and nothing can lie over the dock. */} +
+ {/* Status pill (orb + caption) while sharing, above the control bar so toggling a screen/camera share never resizes the bar itself. */} {sharing && ( -
+
@@ -173,12 +194,12 @@ export function InCall(props: InCallProps) { )} {/* contextual hints — above the control bar, quiet, at most two chips */} - + {/* The dock: one capsule of equal controls, glass under the glass look and solid in flat. A stable width regardless of sharing. */}
+ className="flex max-w-full items-center gap-1.5 rounded-full border border-hairline p-1.5 shadow-pop surface-float"> {ptt && } @@ -188,6 +209,7 @@ export function InCall(props: InCallProps) {
+
{/* transcript sidebar — resizable + collapsible */} @@ -258,14 +280,14 @@ function Caption({ phase, pill }: { phase: LivePhase; pill?: boolean }) { const statusBusy = !!toolStatus || warming; if (pill) return ( - + {words ?? {statusLabel}} ); return ( <> -

{words}

-

{statusLabel}

+

{words}

+

{statusLabel}

); } diff --git a/apps/web/src/components/live/TopBar.tsx b/apps/web/src/components/live/TopBar.tsx index 14c146ab..da8a4576 100644 --- a/apps/web/src/components/live/TopBar.tsx +++ b/apps/web/src/components/live/TopBar.tsx @@ -100,7 +100,10 @@ export function TopBar() { // [settings]. The 1fr side columns keep the middle cluster centered // (it expands symmetrically as more selectors appear); the empty side space is // the window drag handle. -
@@ -115,7 +118,7 @@ export function TopBar() { OpenLive
-
+
diff --git a/apps/web/src/components/settings/GeneralSettings.tsx b/apps/web/src/components/settings/GeneralSettings.tsx index 55801484..2c80395f 100644 --- a/apps/web/src/components/settings/GeneralSettings.tsx +++ b/apps/web/src/components/settings/GeneralSettings.tsx @@ -6,11 +6,12 @@ import { useTheme } from "next-themes"; import { Monitor, Sun, Moon, Keyboard } from "lucide-react"; import { api } from "@/lib/api"; import { useUi } from "@/lib/uiStore"; -import { desktopPlatform, isDesktop } from "@/lib/platform"; +import { desktopPlatform, isDesktop, MOD } from "@/lib/platform"; import { toast } from "@/lib/toast"; import type { InsertionMethod } from "@openlive/flow-store"; -import { Switch, Button, ListGroup, ListRow, Segmented, type SegOption, Textarea, Advanced, Slider } from "@/components/ui"; +import { Switch, Button, ListGroup, ListRow, Segmented, type SegOption, Select, Textarea, Advanced, Slider } from "@/components/ui"; import { GLASS_REASON, setLook, useAppearance, type Look } from "@/lib/look"; +import { setZoom, useZoom, zoomLabel } from "@/lib/zoom"; import { useFlowConfig } from "@/lib/flow/useFlowConfig"; import { cn } from "@/lib/cn"; import { Section } from "./Section"; @@ -48,6 +49,26 @@ function LookRow() { ); } +/** How large everything in the window is. Only the desktop app has it (a browser + * has its own zoom), so the row is absent on the web. */ +function ZoomRow() { + const z = useZoom(); + if (!z) return null; + return ( +
+ +
+ + +
+
+
+ ); +} + type Desk = { loginItem?: (v?: boolean) => Promise; endOnLock?: (v?: boolean) => Promise; @@ -158,6 +179,7 @@ export function GeneralSettings() { + diff --git a/apps/web/src/components/settings/SettingsPage.tsx b/apps/web/src/components/settings/SettingsPage.tsx index 3791db07..4ba23347 100644 --- a/apps/web/src/components/settings/SettingsPage.tsx +++ b/apps/web/src/components/settings/SettingsPage.tsx @@ -261,7 +261,7 @@ export function SettingsPage() { {/* side nav: the way back first, then the sections. Esc and ⌘[ go back too (focus trap + history). */} + className={cn("w-[14.75rem] shrink-0 space-y-1 overflow-y-auto overscroll-contain p-3", rail && "@max-3xl/settings:w-auto @max-3xl/settings:p-2")}>