Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(hud): keep open popovers on screen and harden the work-area clamp
EtienneLescotdbcf03e26510
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex 81092d3b3..d742d2d09 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -441,13 +441,21 @@ interface Window {/** Total pointer travel since `beginHudOverlayDrag`, not a per-frame delta. */dragHudOverlayTo: (deltaX: number, deltaY: number) => void;endHudOverlayDrag: () => void;- /** Resizes the overlay and reports the bar's rect inside the requested+ /** Resizes the overlay and reports the visible stack's rect inside the requested* size (window-relative); positioning decisions are made on that rect. */setHudOverlaySize: (width: number,height: number,content: { x: number; y: number; width: number; height: number },) => void;+ /** The visible stack's rect changed without a resize (a popover opened, the bar+ * grew into its reserve); the overlay is re-clamped by it. */+ setHudOverlayContent: (content: {+ x: number;+ y: number;+ width: number;+ height: number;+ }) => void;showCountdownOverlay: (value: number, runId: number) => Promise<void>;setCountdownOverlayValue: (value: number, runId: number) => Promise<void>;hideCountdownOverlay: (runId: number) => Promise<void>;diff --git a/electron/hudWindowBounds.test.ts b/electron/hudWindowBounds.test.tsindex e12364618..a60a993aa 100644--- a/electron/hudWindowBounds.test.ts+++ b/electron/hudWindowBounds.test.ts@@ -2,7 +2,6 @@ import { describe, expect, it } from "vitest";import {clampHudBoundsToWorkArea,clampHudContentToWorkArea,- HUD_WINDOW_MIN,hudDragDestination,hudResizeBounds,parseHudContentRect,@@ -203,6 +202,22 @@ describe("hud resize bounds", () => {});expect(next).toEqual(WINDOW);});++ it("does not cap the window to the work area, so the renderer's rect stays exact", () => {+ // A capped height would shift the bar by the difference while main still+ // stored the rect computed for the requested size.+ const next = hudResizeBounds({+ bounds: WINDOW,+ previousContent: BAR,+ width: 930,+ height: 1200,+ nextContent: { ...BAR, y: 1200 - BAR_BOTTOM_INSET - BAR.height },+ workArea: WORK_AREA,+ });+ expect(next.height).toBe(1200);+ // The bar's bottom edge stays exactly where it was.+ expect(next.y + next.height - BAR_BOTTOM_INSET).toBe(WINDOW.y + BAR.y + BAR.height);+ });});describe("hud content rect parsing", () => {@@ -223,10 +238,3 @@ describe("hud content rect parsing", () => {expect(parseHudContentRect({ x: 0, y: 0, width: 560 })).toBeNull();});});--describe("hud window minimum", () => {- it("matches the window's own floor, not the editor's", () => {- // browserWindow minWidth/minHeight at construction (electron/windows.ts).- expect(HUD_WINDOW_MIN).toEqual({ width: 120, height: 80 });- });-});diff --git a/electron/hudWindowBounds.ts b/electron/hudWindowBounds.tsindex d2431cc0e..25ecd3a39 100644--- a/electron/hudWindowBounds.ts+++ b/electron/hudWindowBounds.ts@@ -9,7 +9,7 @@// the screen. So the invariant is stated on the bar, not on the window: the// content rect the renderer measures must sit fully inside the work area, and// the window around it may overhang any edge — the overhang is transparent and-// click-through.+// click-through (not on Linux, where windows.ts clamps the whole window instead).//// The Windows taskbar and the macOS Dock live *outside* the work area, so a HUD// whose bar lands there is painted over them with no taskbar entry to bring it@@ -28,12 +28,17 @@ import {export const HUD_WINDOW_MIN = { width: 120, height: 80 };/**- * The bar's rect relative to the window, as measured by the renderer. The- * viewport of the frameless window is the whole window, so a- * `getBoundingClientRect()` on the bar is already in these coordinates.+ * The visible stack's rect relative to the window, as measured by the renderer:+ * the bar plus any popover or notice open above it, which is just as visible as+ * the bar. The viewport of the frameless window is the whole window, so a+ * `getBoundingClientRect()` is already in these coordinates.*/export type HudContentRect = EditorWindowRect;+export function sameRect(a: EditorWindowRect, b: EditorWindowRect): boolean {+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;+}+/** Screenspace rect of the bar, given the window's position. */export function hudContentScreenRect(bounds: EditorWindowRect,@@ -57,10 +62,9 @@ export function clampHudContentToWorkArea(content: HudContentRect,workArea: DisplayWorkArea,): EditorWindowRect {- const maxX = workArea.x + Math.max(0, workArea.width - content.width);- const maxY = workArea.y + Math.max(0, workArea.height - content.height);- const x = Math.min(Math.max(bounds.x + content.x, workArea.x), maxX);- const y = Math.min(Math.max(bounds.y + content.y, workArea.y), maxY);+ // The content's own size as the floor leaves its size untouched: only the+ // position is clamped.+ const { x, y } = clampRectToWorkArea(hudContentScreenRect(bounds, content), workArea, content);// `| 0` collapses the negative zero Math.round can produce and pins the value// to int32 for the native setter — same reasons as in hudDragDestination.return {@@ -105,8 +109,10 @@ export function hudResizeBounds(input: {nextContent: HudContentRect | null;workArea: DisplayWorkArea;}): EditorWindowRect {- const width = Math.max(1, Math.min(Math.round(input.width), input.workArea.width));- const height = Math.max(1, Math.min(Math.round(input.height), input.workArea.height));+ // Not capped to the work area: the window may overhang, and capping it would move+ // the content away from the rect the renderer computed for this exact size.+ const width = Math.max(1, Math.round(input.width));+ const height = Math.max(1, Math.round(input.height));const anchorCenterX = input.previousContent? input.bounds.x + input.previousContent.x + input.previousContent.width / 2diff --git a/electron/preload.ts b/electron/preload.tsindex a273f89d8..6b29edd87 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -101,6 +101,9 @@ contextBridge.exposeInMainWorld("electronAPI", {) => {ipcRenderer.send("hud-overlay-set-size", width, height, content);},+ setHudOverlayContent: (content: { x: number; y: number; width: number; height: number }) => {+ ipcRenderer.send("hud-overlay-content", content);+ },getSources: async (opts: Electron.SourcesOptions) => {return await ipcRenderer.invoke("get-sources", opts);},diff --git a/electron/windows.ts b/electron/windows.tsindex 851d522a0..baa66e4ee 100644--- a/electron/windows.ts+++ b/electron/windows.ts@@ -10,11 +10,13 @@ import {} from "./editorWindowState";import {clampHudBoundsToWorkArea,+ HUD_WINDOW_MIN,type HudContentRect,hudContentScreenRect,hudDragDestination,hudResizeBounds,parseHudContentRect,+ sameRect,} from "./hudWindowBounds";const __dirname = path.dirname(fileURLToPath(import.meta.url));@@ -110,18 +112,38 @@ let hudOverlayWindow: BrowserWindow | null = null;// self-corrects on the next one instead of leaving the window permanently offset.let hudDragOrigin: { x: number; y: number } | null = null;-// The bar's rect inside the window, as last measured by the renderer. Everything-// that positions the HUD clamps this rect — not the window — into the work area,-// because the window around the bar is transparent reserve that may overhang any-// edge (see hudWindowBounds.ts). Null until the renderer's first measurement.+// The visible stack's rect inside the window (the bar plus anything open above it), as+// last measured by the renderer. Everything that positions the HUD clamps this rect —+// not the window — into the work area, because the window around it is transparent+// reserve that may overhang any edge (see hudWindowBounds.ts). Null until the+// renderer's first measurement.let hudContentRect: HudContentRect | null = null;+// Linux never makes the HUD click-through (setHudMouseEventsEnabled in LaunchWindow), so+// an overhanging reserve would swallow clicks on the panels and docks under it. There the+// content rect is ignored and the whole window stays inside the work area.+const HUD_CLAMPS_CONTENT = process.platform !== "linux";+/** Work area of the display the bar is on (or heading for), not the window. */function hudWorkAreaFor(bounds: Electron.Rectangle): Electron.Rectangle {const reference = hudContentRect ? hudContentScreenRect(bounds, hudContentRect) : bounds;return screen.getDisplayMatching(reference).workArea;}+// Re-clamps a HUD nobody is dragging: a drag owns the position frame by frame, and the+// renderer re-measures on release. Skipped while minimized, where moving the window is+// platform-defined; "restore" runs it instead.+function reclampHud() {+ const win = hudOverlayWindow;+ if (!win || win.isDestroyed() || win.isMinimized() || hudDragOrigin) return;++ const bounds = win.getBounds();+ const next = clampHudBoundsToWorkArea(bounds, hudContentRect, hudWorkAreaFor(bounds));+ if (!sameRect(next, bounds)) {+ win.setBounds(next, false);+ }+}+// The work area can shrink under a HUD nobody is touching: the taskbar stops auto-hiding// (or is revealed), the Dock moves, the resolution or the scale changes. A bar parked at// the bottom edge would then be left sitting on the taskbar until the next drag — and the@@ -132,31 +154,6 @@ function watchHudWorkAreaChanges() {if (isWatchingHudWorkArea) return;isWatchingHudWorkArea = true;- const reclampHud = () => {- const win = hudOverlayWindow;- // Minimized is skipped per platform for different reasons: Windows reports- // sentinel bounds (−32000,−32000) for a minimized window and clamping those- // would teleport the HUD somewhere in the work area on restore; macOS keeps- // real bounds, so skipping only delays the re-clamp to the next display- // event. Either way the position was legal when the window was minimized.- if (!win || win.isDestroyed() || win.isMinimized()) return;- // A drag owns the position frame by frame; moving the window out from under it- // would fight the gesture. The renderer re-measures on release, and the next- // metric change re-clamps it anyway.- if (hudDragOrigin) return;-- const bounds = win.getBounds();- const next = clampHudBoundsToWorkArea(bounds, hudContentRect, hudWorkAreaFor(bounds));- if (- next.x !== bounds.x ||- next.y !== bounds.y ||- next.width !== bounds.width ||- next.height !== bounds.height- ) {- win.setBounds(next, false);- }- };-screen.on("display-metrics-changed", reclampHud);screen.on("display-added", reclampHud);screen.on("display-removed", reclampHud);@@ -276,10 +273,11 @@ ipcMain.on("hud-overlay-drag-to", (_event, deltaX: number, deltaY: number) => {const bounds = hudOverlayWindow.getBounds();const destination = hudDragDestination({ bounds, origin: hudDragOrigin, deltaX, deltaY });- hudOverlayWindow.setBounds(- clampHudBoundsToWorkArea(destination, hudContentRect, hudWorkAreaFor(destination)),- false,- );+ const next = clampHudBoundsToWorkArea(destination, hudContentRect, hudWorkAreaFor(destination));++ // Position only: a per-frame setBounds round-trips the size through DIP rounding,+ // which can creep it a pixel at a time under fractional scaling.+ hudOverlayWindow.setPosition(next.x, next.y, false);});ipcMain.on("hud-overlay-drag-end", () => {@@ -294,11 +292,6 @@ ipcMain.on("hud-overlay-drag-end", () => {// around the bar instead of moving it, and clamped so the bar cannot end up off// screen. The window around it may overhang; the reserve is invisible.//-// The same message doubles as a content-rect update: when only the bar changed-// (growth into the reserve costs no resize), the size is unchanged and the-// handler just refreshes the rect — repositioning only if the bar now overhangs-// an edge it sits flush against.-//// Applied in one shot rather than tweened. The renderer now reserves space for// everything that can float above the bar, so a resize only ever accompanies a// discrete content change (orientation flip, recording controls appearing) that@@ -322,7 +315,7 @@ ipcMain.on("hud-overlay-set-size", (_event, width: number, height: number, conte}const bounds = hudOverlayWindow.getBounds();- const nextContent = parseHudContentRect(content);+ const nextContent = HUD_CLAMPS_CONTENT ? parseHudContentRect(content) : null;const next = hudResizeBounds({bounds,previousContent: hudContentRect,@@ -337,15 +330,18 @@ ipcMain.on("hud-overlay-set-size", (_event, width: number, height: number, contehudContentRect = nextContent;}- if (- next.x === bounds.x &&- next.y === bounds.y &&- next.width === bounds.width &&- next.height === bounds.height- ) {- return;+ if (!sameRect(next, bounds)) {+ hudOverlayWindow.setBounds(next, false);}- hudOverlayWindow.setBounds(next, false);+});++// The visible stack changed without a resize: the bar grew into its reserve, or a+// popover or notice opened above it. Re-clamp so none of it is left off screen.+ipcMain.on("hud-overlay-content", (_event, content: unknown) => {+ const nextContent = HUD_CLAMPS_CONTENT ? parseHudContentRect(content) : null;+ if (!nextContent) return;+ hudContentRect = nextContent;+ reclampHud();});/**@@ -370,8 +366,12 @@ export function createHudOverlayWindow(): BrowserWindow {height: windowHeight,// Min/max are intentionally loose: the renderer resizes to fit content via// "hud-overlay-set-size" (above), needed for the vertical tray to grow taller.- minWidth: 120,- minHeight: 80,+ minWidth: HUD_WINDOW_MIN.width,+ minHeight: HUD_WINDOW_MIN.height,+ // The reserve may overhang the screen (hudWindowBounds.ts). Without this, macOS+ // re-constrains the frame below the menu bar whenever the window is re-ordered,+ // pulling a stack parked at the top down by the whole reserve.+ enableLargerThanScreen: true,x: x,y: y,frame: false,@@ -427,11 +427,15 @@ export function createHudOverlayWindow(): BrowserWindow {hudOverlayWindow = win;watchHudWorkAreaChanges();+ // Display changes while minimized were skipped; catch up on the way back.+ win.on("restore", reclampHud);win.on("closed", () => {if (hudOverlayWindow === win) {hudOverlayWindow = null;hudDragOrigin = null;+ // The next HUD is a new window: a rect measured in this one would misplace it.+ hudContentRect = null;stopHudCursorPoll();}});diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsxindex 55ff1266b..73cc4ea5a 100644--- a/src/components/launch/LaunchWindow.test.tsx+++ b/src/components/launch/LaunchWindow.test.tsx@@ -227,6 +227,7 @@ function stubElectronAPI(getSelectedSource: Window["electronAPI"]["getSelectedSogetAppInfo: vi.fn(async () => appInfoState.value),checkForUpdates: updateCheckMock,setHudOverlaySize: vi.fn(),+ setHudOverlayContent: vi.fn(),setHudOverlayIgnoreMouseEvents: vi.fn(),onHudOverlayCursor: vi.fn((callback) => {hudCursorListeners.push(callback);@@ -786,6 +787,31 @@ describe("LaunchWindow overlay sizing", () => {expect(window.electronAPI.setHudOverlaySize).not.toHaveBeenCalled();});+ it("reports an opened popover as part of the rect kept on screen", async () => {+ renderLaunchWindow();++ const bar = (await screen.findByTestId("hud-drag-handle")).closest(+ "[data-tray-layout]",+ ) as HTMLElement;+ stubBox(bar, 400, 56);+ await flushResizeObservers();++ fireEvent.click(screen.getByRole("button", { name: "English" }));+ await screen.findByTestId("hud-language-menu");+ // The anchor wraps the bar and the stack above it: with the menu open it is+ // taller than the bar, and that whole height must stay inside the work area.+ const stackHeight = 56 + HUD_POPOVER_GAP + 300;+ stubBox(bar.parentElement as HTMLElement, 400, stackHeight);+ await flushResizeObservers();++ expect(window.electronAPI.setHudOverlayContent).toHaveBeenLastCalledWith({+ x: 0,+ y: 0,+ width: 400,+ height: stackHeight,+ });+ });+it("grows the HUD overlay tall enough to fit the system language prompt", async () => {i18nState.value.systemLocaleSuggestion = "zh-CN";diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsxindex b722a195c..c8f989755 100644--- a/src/components/launch/LaunchWindow.tsx+++ b/src/components/launch/LaunchWindow.tsx@@ -59,6 +59,10 @@ function getAvailableScreenHeight(): number {return available && available > 0 ? available : FALLBACK_SCREEN_HEIGHT;}+function hudBarMaxHeightCss(): string {+ return `${computeHudBarMaxHeight(getAvailableScreenHeight())}px`;+}+/** Launches the floating recording HUD and its recorder controls. */export function LaunchWindow() {const t = useScopedT("launch");@@ -346,8 +350,8 @@ export function LaunchWindow() {// down as CSS custom properties.// ---------------------------------------------------------------------------const hudAllocatedSizeRef = useRef({ width: 0, height: 0, orientation: trayLayout });- // Last bar rect sent to the main process, so a measurement that changed nothing- // (a popover opening in reserved space) costs no IPC either.+ // Last stack rect sent to the main process, so a measurement that changed nothing+ // costs no IPC.const lastSentHudContentRef = useRef<{x: number;y: number;@@ -362,10 +366,7 @@ export function LaunchWindow() {anchor.style.setProperty("--hud-bar-bottom", `${HUD_BAR_BOTTOM}px`);anchor.style.setProperty("--hud-popover-gap", `${HUD_POPOVER_GAP}px`);anchor.style.setProperty("--hud-stack-gap", `${HUD_STACK_GAP}px`);- anchor.style.setProperty(- "--hud-bar-max-h",- `${computeHudBarMaxHeight(getAvailableScreenHeight())}px`,- );+ anchor.style.setProperty("--hud-bar-max-h", hudBarMaxHeightCss());}, []);const measureHudSize = useCallback(() => {@@ -424,24 +425,29 @@ export function LaunchWindow() {granted.width + HUD_GROWTH_RESERVE < allocated.width ||granted.height + HUD_GROWTH_RESERVE < allocated.height;- // The main process positions the HUD by this rect, not by the window: the- // window is mostly transparent reserve, and clamping it would strand the- // bar at the bottom of the screen. `barRect` is already window-relative- // (the frameless viewport is the whole window), and since the stack is- // centred and pinned HUD_BAR_BOTTOM above the window's bottom edge- // (LaunchWindow.module.css), the rect the granted size will produce is- // computed exactly rather than measured a frame late.+ // The main process keeps this rect on screen, not the window: the window is+ // mostly transparent reserve, and clamping it would strand the bar at the+ // bottom of the screen. It is the whole stack, the bar plus any popover or+ // notice open above it, because those are just as visible as the bar. Rects+ // are already window-relative (the frameless viewport is the whole window),+ // and since the stack is centred and pinned HUD_BAR_BOTTOM above the window's+ // bottom edge (LaunchWindow.module.css), the rect the granted size will+ // produce is computed exactly rather than measured a frame late.+ const anchorRect = anchorEl?.getBoundingClientRect();+ const stackRect = anchorRect?.width && anchorRect.height ? anchorRect : barRect;+ const stackWidth = stackRect.width || barWidth;+ const stackHeight = stackRect.height || barHeight;const currentContent = {- x: barRect.x,- y: barRect.y,- width: barWidth,- height: barHeight,+ x: stackRect.x,+ y: stackRect.y,+ width: stackWidth,+ height: stackHeight,};const grantedContent = {- x: (granted.width - barWidth) / 2,- y: granted.height - HUD_BAR_BOTTOM - barHeight,- width: barWidth,- height: barHeight,+ x: (granted.width - stackWidth) / 2,+ y: granted.height - HUD_BAR_BOTTOM - stackHeight,+ width: stackWidth,+ height: stackHeight,};if (!needsResize) {@@ -453,10 +459,10 @@ export function LaunchWindow() {Math.abs(last.x - currentContent.x) >= 1 ||Math.abs(last.y - currentContent.y) >= 1;if (!contentChanged) return;- // No resize — but the bar grew inside the reserve, and the main process- // must know before that growth pushes it past an edge it sits flush on.+ // No resize, but the stack changed inside the reserve (the bar grew, a+ // popover opened), and the main process must keep it on screen.lastSentHudContentRef.current = currentContent;- window.electronAPI.setHudOverlaySize(allocated.width, allocated.height, currentContent);+ window.electronAPI.setHudOverlayContent?.(currentContent);return;}@@ -468,14 +474,16 @@ export function LaunchWindow() {}, [trayLayout]);// One persistent observer; elements wire themselves up via callback refs as- // they mount/unmount. Only the bar and the notice column are observed — the- // popovers deliberately are not, since their space is already reserved.+ // they mount/unmount. The bar and the notice column size the window; the anchor+ // (the whole stack) only feeds the content rect, so a popover opening costs a+ // re-clamp but never a native resize.const hudResizeObserverRef = useRef<ResizeObserver | null>(null);useEffect(() => {const observer = new ResizeObserver(() => measureHudSize());hudResizeObserverRef.current = observer;if (hudBarRef.current) observer.observe(hudBarRef.current);if (hudNoticesRef.current) observer.observe(hudNoticesRef.current);+ if (hudAnchorRef.current) observer.observe(hudAnchorRef.current);measureHudSize();return () => {observer.disconnect();@@ -483,6 +491,19 @@ export function LaunchWindow() {};}, [measureHudSize]);+ // Screen-derived caps follow the display the HUD is on: after a drag onto a+ // shorter display, a tall vertical tray would otherwise overflow its work area.+ useEffect(() => {+ const onScreenChange = () => {+ hudAnchorRef.current?.style.setProperty("--hud-bar-max-h", hudBarMaxHeightCss());+ measureHudSize();+ };+ // Chromium's Screen is an EventTarget; TypeScript's DOM lib does not say so yet.+ const hudScreen = window.screen as Screen & Partial<EventTarget>;+ hudScreen.addEventListener?.("change", onScreenChange);+ return () => hudScreen.removeEventListener?.("change", onScreenChange);+ }, [measureHudSize]);+const observeHudElement = useCallback(<T extends HTMLElement>(el: T | null, ref: React.MutableRefObject<T | null>) => {const observer = hudResizeObserverRef.current;diff --git a/src/components/launch/hudGeometry.ts b/src/components/launch/hudGeometry.tsindex e59c3cd1c..3800fef86 100644--- a/src/components/launch/hudGeometry.ts+++ b/src/components/launch/hudGeometry.ts@@ -135,7 +135,7 @@ export function computeHudWindowSize(input: HudSizeInput): {noticeBlock +HUD_EDGE_SLACK;- // The main process clamps to the display's work area, so clamp here too:+ // The main process clamps the whole window to the work area on Linux, so clamp here too:// otherwise the caller would record an allocation the window never actually// got, then skip a resize it genuinely needs later on.const ceiling = input.availableHeight > 0 ? input.availableHeight : Number.POSITIVE_INFINITY;