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): clamp the visible bar, not the window, into the work area
EtienneLescot4004ae8ec752
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex dce4db3b7..81092d3b3 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -441,7 +441,13 @@ interface Window {/** Total pointer travel since `beginHudOverlayDrag`, not a per-frame delta. */dragHudOverlayTo: (deltaX: number, deltaY: number) => void;endHudOverlayDrag: () => void;- setHudOverlaySize: (width: number, height: number) => void;+ /** Resizes the overlay and reports the bar'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;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 c79274312..e12364618 100644--- a/electron/hudWindowBounds.test.ts+++ b/electron/hudWindowBounds.test.ts@@ -1,84 +1,227 @@import { describe, expect, it } from "vitest";-import { clampHudToWorkArea, HUD_WINDOW_MIN, hudDragDestination } from "./hudWindowBounds";+import {+ clampHudBoundsToWorkArea,+ clampHudContentToWorkArea,+ HUD_WINDOW_MIN,+ hudDragDestination,+ hudResizeBounds,+ parseHudContentRect,+} from "./hudWindowBounds";-// 1920x1080 with a 48px taskbar at the bottom: the work area stops above it, so a window-// whose bottom edge reaches 1032 is sitting on the taskbar.+// 1920x1080 with a 48px taskbar at the bottom: the work area stops above it.const WORK_AREA = { x: 0, y: 0, width: 1920, height: 1032 };-// A HUD with room to move: 560x100, well clear of the bottom of the work area.-const HUD = { x: 680, y: 800, width: 560, height: 100 };--/** The drag path as the IPC handler runs it: destination first, then the work-area clamp. */-function dragTo(deltaX: number, deltaY: number, { bounds = HUD, workArea = WORK_AREA } = {}) {- return clampHudToWorkArea(- hudDragDestination({ bounds, origin: bounds, deltaX, deltaY }),- workArea,- );++// A realistic HUD: a 930x696 window whose visible part is a 560x64 bar sitting+// 20px above the window's bottom edge, centred (see LaunchWindow.module.css and+// hudGeometry.ts). Everything else in the window is transparent reserve.+const WINDOW = { x: 680, y: 236, width: 930, height: 696 };+const BAR = { x: 185, y: 612, width: 560, height: 64 };+const BAR_BOTTOM_INSET = 696 - 612 - 64; // 20++/** The bar's rect on screen for a window position. */+function barOnScreen(bounds: { x: number; y: number }) {+ return {+ left: bounds.x + BAR.x,+ top: bounds.y + BAR.y,+ right: bounds.x + BAR.x + BAR.width,+ bottom: bounds.y + BAR.y + BAR.height,+ };+}++/** The drag path as the IPC handler runs it: destination first, then the clamp by the bar. */+function dragTo(+ deltaX: number,+ deltaY: number,+ { bounds = WINDOW, bar = BAR, workArea = WORK_AREA } = {},+) {+ const destination = hudDragDestination({ bounds, origin: bounds, deltaX, deltaY });+ return clampHudContentToWorkArea(destination, bar, workArea);}describe("hud drag bounds", () => {- it("follows the pointer while the window stays on screen", () => {- expect(dragTo(40, -120)).toEqual({ x: 720, y: 680, width: 560, height: 100 });+ it("follows the pointer while the bar stays on screen", () => {+ const next = dragTo(40, -120);+ expect(next).toEqual({ ...WINDOW, x: 720, y: 116 });+ expect(barOnScreen(next)).toEqual({+ left: 905,+ top: 728,+ right: 1465,+ bottom: 792,+ });});- it("stops the bar above the taskbar when the drag aims past the bottom of the screen", () => {- const asked = hudDragDestination({ bounds: HUD, origin: HUD, deltaX: 0, deltaY: 4000 });- // Without the clamp this is where the window would land: 3000px past the taskbar.- expect(asked.y).toBe(4800);+ it("brings the bar flush to the right edge, with the reserve overhanging", () => {+ const next = dragTo(4000, 0);+ expect(barOnScreen(next).right).toBe(WORK_AREA.width);+ // The window itself ends past the screen edge: the overhang is the+ // transparent reserve, not the bar.+ expect(next.x + next.width).toBe(WORK_AREA.width + BAR.x);+ });++ it("brings the bar flush to the left edge", () => {+ const next = dragTo(-4000, 0);+ expect(barOnScreen(next).left).toBe(WORK_AREA.x);+ expect(next.x).toBe(WORK_AREA.x - BAR.x);+ });- const clamped = dragTo(0, 4000);- expect(clamped.y + clamped.height).toBe(WORK_AREA.height);- expect(clamped.x).toBe(HUD.x);+ it("brings the bar to the top of the screen — the window overhangs above it", () => {+ // The whole point of clamping the bar rather than the window: with a+ // ~600px reserve above it, a window-clamped HUD could never leave the+ // bottom third of the display.+ const next = dragTo(0, -4000);+ expect(barOnScreen(next).top).toBe(WORK_AREA.y);+ expect(next.y).toBe(WORK_AREA.y - BAR.y);+ expect(next.y).toBeLessThan(0);});- it("keeps the bar off the left, top and right edges", () => {- expect(dragTo(-4000, 0)).toEqual({ ...HUD, x: 0 });- expect(dragTo(0, -4000)).toEqual({ ...HUD, y: 0 });- expect(dragTo(4000, 0)).toEqual({ ...HUD, x: WORK_AREA.width - HUD.width });+ it("stops the bar above the taskbar, letting only the 20px inset overhang it", () => {+ const next = dragTo(0, 4000);+ expect(barOnScreen(next).bottom).toBe(WORK_AREA.height);+ expect(next.y + next.height).toBe(WORK_AREA.height + BAR_BOTTOM_INSET);});- it("uses the work area of the display the drag lands on, not the one it started on", () => {- // Second display to the left of the primary one, work area 1280x984 starting at- // x = -1280. Dragging left across the boundary must be allowed to follow.+ it("follows the pointer onto a secondary display with negative coordinates", () => {const left = { x: -1280, y: 0, width: 1280, height: 984 };- const destination = hudDragDestination({- bounds: HUD,- origin: HUD,- deltaX: -1500,- deltaY: 0,- });- expect(destination.x).toBe(-820);+ const next = dragTo(-1500, 0, { workArea: left });+ expect(barOnScreen(next).left).toBeLessThan(0);+ expect(barOnScreen(next).left).toBeGreaterThanOrEqual(left.x);+ expect(barOnScreen(next).right).toBeLessThanOrEqual(left.x + left.width);+ });- const clamped = clampHudToWorkArea(destination, left);- expect(clamped).toEqual({ ...HUD, x: -820 });- expect(clamped.x).toBeLessThan(0);+ it("respects a work area inset on every side — menu bar and a side Dock", () => {+ // A typical macOS arrangement: 25px menu bar at the top, 80px Dock on the+ // right. The work area starts below the one and stops short of the other,+ // and the bar must honour both edges exactly, like the Windows taskbar.+ const mac = { x: 0, y: 25, width: 1920 - 80, height: 1080 - 25 };+ const right = dragTo(4000, 0, { workArea: mac });+ expect(barOnScreen(right).right).toBe(mac.x + mac.width);+ const top = dragTo(0, -4000, { workArea: mac });+ expect(barOnScreen(top).top).toBe(mac.y);+ const bottom = dragTo(0, 4000, { workArea: mac });+ expect(barOnScreen(bottom).bottom).toBe(mac.y + mac.height);});- it("shrinks a HUD that cannot fit the work area at all", () => {- const clamped = clampHudToWorkArea(- { x: 900, y: 900, width: 2600, height: 1400 },+ it("respects a Linux panel layout with bars on two sides", () => {+ // GNOME-classic style: a top panel and a left dock, so the work area is+ // inset from both the top and the left before the drag even starts.+ const linux = { x: 64, y: 32, width: 1856, height: 1048 };+ const left = dragTo(-4000, 0, { workArea: linux });+ expect(barOnScreen(left).left).toBe(linux.x);+ const top = dragTo(0, -4000, { workArea: linux });+ expect(barOnScreen(top).top).toBe(linux.y);+ });++ it("pins a bar larger than the work area to its top-left corner", () => {+ const next = clampHudContentToWorkArea(+ { x: 900, y: 900, width: 930, height: 696 },+ { x: 185, y: 612, width: 2600, height: 1400 },{ x: 0, y: 0, width: 1024, height: 768 },);- expect(clamped).toEqual({ x: 0, y: 0, width: 1024, height: 768 });+ expect(next.x).toBe(-185); // bar left edge at the work area's left+ expect(next.y).toBe(-612); // bar top edge at the work area's top});it("never hands a fractional or negative-zero coordinate to the window", () => {- // A fractional, slightly negative delta is routine under fractional display- // scaling, and Math.round turns it into -0 — which the native setter rejects- // (see the comment in hudDragDestination).- const tiny = hudDragDestination({ bounds: HUD, origin: HUD, deltaX: -0.2, deltaY: -0.4 });- expect(Number.isInteger(tiny.x)).toBe(true);- expect(Number.isInteger(tiny.y)).toBe(true);-- const clamped = clampHudToWorkArea(tiny, { ...WORK_AREA, x: 0 });- expect(Object.is(clamped.x, -0)).toBe(false);- expect(Object.is(clamped.y, -0)).toBe(false);+ // The bar is centred, so its window-relative x is fractional whenever the+ // window and bar widths have different parity — routine, not exotic.+ const next = clampHudContentToWorkArea(+ { ...WINDOW, x: 680.4, y: 236.6 },+ { x: 185.5, y: 612.5, width: 560, height: 64 },+ WORK_AREA,+ );+ expect(Number.isInteger(next.x)).toBe(true);+ expect(Number.isInteger(next.y)).toBe(true);+ expect(Object.is(next.x, -0)).toBe(false);+ expect(Object.is(next.y, -0)).toBe(false);});it("is idempotent, so a drag that re-clamps every frame cannot creep", () => {const once = dragTo(0, 4000);- const twice = clampHudToWorkArea(once, WORK_AREA);+ const twice = clampHudContentToWorkArea(once, BAR, WORK_AREA);expect(twice).toEqual(once);});++ it("falls back to whole-window clamping before the renderer reports the bar", () => {+ const destination = hudDragDestination({+ bounds: WINDOW,+ origin: WINDOW,+ deltaX: 0,+ deltaY: 4000,+ });+ const next = clampHudBoundsToWorkArea(destination, null, WORK_AREA);+ expect(next.y + next.height).toBe(WORK_AREA.height);+ });+});++describe("hud resize bounds", () => {+ it("keeps the bar's bottom-centre anchored across a layout flip", () => {+ // Horizontal bar at the bottom of the work area, flipped to the tall+ // vertical tray: the bar must stay put, not the window.+ const atBottom = dragTo(0, 4000);+ const verticalBar = { x: 433, y: 400, width: 64, height: 276 };+ const next = hudResizeBounds({+ bounds: atBottom,+ previousContent: BAR,+ width: 930,+ height: 696,+ nextContent: verticalBar,+ workArea: WORK_AREA,+ });+ // Bar bottom-centre before the flip: x 1145 (window 680 + bar 185 + 280).+ const beforeCenterX = atBottom.x + BAR.x + BAR.width / 2;+ const beforeBottomY = atBottom.y + BAR.y + BAR.height;+ expect(next.x + verticalBar.x + verticalBar.width / 2).toBeCloseTo(beforeCenterX, 0);+ expect(next.y + verticalBar.y + verticalBar.height).toBe(beforeBottomY);+ });++ it("cannot strand the HUD off screen when the bar grows past the top edge", () => {+ // Bar parked at the very top of the screen (window overhanging above),+ // then the vertical tray makes the bar taller than the room it had: the+ // result must keep the whole bar inside the work area.+ const atTop = dragTo(0, -4000);+ const tallBar = { x: 433, y: 300, width: 64, height: 800 };+ const next = hudResizeBounds({+ bounds: atTop,+ previousContent: BAR,+ width: 930,+ height: 1120,+ nextContent: tallBar,+ workArea: WORK_AREA,+ });+ expect(next.y + tallBar.y).toBeGreaterThanOrEqual(WORK_AREA.y);+ expect(next.y + tallBar.y + tallBar.height).toBeLessThanOrEqual(WORK_AREA.y + WORK_AREA.height);+ });++ it("is the identity when neither the size nor the bar changes", () => {+ const next = hudResizeBounds({+ bounds: WINDOW,+ previousContent: BAR,+ width: WINDOW.width,+ height: WINDOW.height,+ nextContent: BAR,+ workArea: WORK_AREA,+ });+ expect(next).toEqual(WINDOW);+ });+});++describe("hud content rect parsing", () => {+ it("accepts a measured rect", () => {+ expect(parseHudContentRect({ x: 185.5, y: 612, width: 560, height: 64 })).toEqual({+ x: 185.5,+ y: 612,+ width: 560,+ height: 64,+ });+ });++ it("rejects garbage, non-finite and non-positive input", () => {+ expect(parseHudContentRect(null)).toBeNull();+ expect(parseHudContentRect("560x64")).toBeNull();+ expect(parseHudContentRect({ x: 0, y: 0, width: Number.NaN, height: 64 })).toBeNull();+ expect(parseHudContentRect({ x: 0, y: 0, width: 0, height: 64 })).toBeNull();+ expect(parseHudContentRect({ x: 0, y: 0, width: 560 })).toBeNull();+ });});describe("hud window minimum", () => {diff --git a/electron/hudWindowBounds.ts b/electron/hudWindowBounds.tsindex 47d773bb7..d2431cc0e 100644--- a/electron/hudWindowBounds.ts+++ b/electron/hudWindowBounds.ts@@ -1,13 +1,22 @@// Where the HUD overlay window is allowed to sit.//-// The HUD is transparent, always-on-top and `skipTaskbar`, and two different inputs move-// it: the drag handle repositions it frame by frame, and a content change re-anchors it-// around its bottom edge. The Windows taskbar and the macOS Dock live *outside* the-// display work area, so a HUD that lands there is painted over them with no taskbar-// entry to bring it back — the tray icon is the only way home.+// The HUD is a transparent, always-on-top, `skipTaskbar` window, and the bar the+// user sees is only the bottom slice of it: everything above the bar is reserve+// for popovers plus growth hysteresis (see src/components/launch/hudGeometry.ts),+// which is why the window is several times taller than the bar. Clamping the+// *window* to the work area therefore over-constrains the bar: it inherits the+// reserve as a phantom margin at every edge and can never leave the bottom of+// 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.//-// Pure geometry on purpose: `screen` and the window are the caller's job, so the rules-// can be tested without an Electron runtime.+// 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+// back — the tray icon is the only way home.+//+// Pure geometry on purpose: `screen` and the window are the caller's job, so the+// rules can be tested without an Electron runtime.import {clampRectToWorkArea,@@ -18,20 +27,139 @@ import {/** The HUD's own floor, matching `minWidth`/`minHeight` at construction. */export const HUD_WINDOW_MIN = { width: 120, height: 80 };-/** Puts HUD bounds inside the work area of the display they belong to. */-export function clampHudToWorkArea(+/**+ * 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.+ */+export type HudContentRect = EditorWindowRect;++/** Screenspace rect of the bar, given the window's position. */+export function hudContentScreenRect(+ bounds: EditorWindowRect,+ content: HudContentRect,+): EditorWindowRect {+ return {+ x: bounds.x + content.x,+ y: bounds.y + content.y,+ width: content.width,+ height: content.height,+ };+}++/**+ * Puts the bar inside the work area of the display it is heading for. The+ * window is translated by the same amount and may end up overhanging — that is+ * the reserve, not the content, and it is invisible.+ */+export function clampHudContentToWorkArea(+ bounds: EditorWindowRect,+ 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);+ // `| 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 {+ ...bounds,+ x: Math.round(x - content.x) | 0,+ y: Math.round(y - content.y) | 0,+ };+}++/**+ * Clamps by the bar when the renderer has reported one, and by the whole window+ * until then (the first frames, or a malformed message). The window fallback is+ * the conservative one: it can only leave the bar further from an edge.+ */+export function clampHudBoundsToWorkArea(bounds: EditorWindowRect,+ content: HudContentRect | null,workArea: DisplayWorkArea,): EditorWindowRect {- return clampRectToWorkArea(bounds, workArea, HUD_WINDOW_MIN);+ return content+ ? clampHudContentToWorkArea(bounds, content, workArea)+ : clampRectToWorkArea(bounds, workArea, HUD_WINDOW_MIN);+}++/**+ * Where a resize re-anchors the window: the bar's bottom-centre stays under+ * where it was, so switching between the horizontal bar and the tall vertical+ * tray resizes the window around the bar instead of moving the bar. The new+ * content rect is supplied by the renderer for the size it is asking for — the+ * stack is centred and pinned `HUD_BAR_BOTTOM` above the window's bottom edge+ * (LaunchWindow.module.css), so the post-resize rect is computed, not guessed.+ * The result keeps the new bar fully inside the work area, so a layout flip+ * cannot strand the HUD off screen.+ */+export function hudResizeBounds(input: {+ bounds: EditorWindowRect;+ /** Bar rect in the window as it currently is; null before the first report. */+ previousContent: HudContentRect | null;+ width: number;+ height: number;+ /** Bar rect in the requested size; null for a malformed message. */+ 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));++ const anchorCenterX = input.previousContent+ ? input.bounds.x + input.previousContent.x + input.previousContent.width / 2+ : input.bounds.x + input.bounds.width / 2;+ const anchorBottomY = input.previousContent+ ? input.bounds.y + input.previousContent.y + input.previousContent.height+ : input.bounds.y + input.bounds.height;++ const x = input.nextContent+ ? anchorCenterX - (input.nextContent.x + input.nextContent.width / 2)+ : anchorCenterX - width / 2;+ const y = input.nextContent+ ? anchorBottomY - (input.nextContent.y + input.nextContent.height)+ : anchorBottomY - height;++ return clampHudBoundsToWorkArea(+ { x: Math.round(x), y: Math.round(y), width, height },+ input.nextContent,+ input.workArea,+ );+}++/**+ * Validates the content rect arriving over IPC. Anything not shaped like a+ * finite rect with positive size is ignored, and the caller falls back to+ * whole-window clamping.+ */+export function parseHudContentRect(raw: unknown): HudContentRect | null {+ if (!raw || typeof raw !== "object") return null;+ const rec = raw as Record<string, unknown>;+ const { x, y, width, height } = rec;+ if (+ typeof x !== "number" ||+ typeof y !== "number" ||+ typeof width !== "number" ||+ typeof height !== "number"+ ) {+ return null;+ }+ if (!Number.isFinite(x) || !Number.isFinite(y)) return null;+ if (!(width > 0) || !Number.isFinite(width) || !(height > 0) || !Number.isFinite(height)) {+ return null;+ }+ return { x, y, width, height };}/**- * Where the drag handle is asking for the window to go, before the work-area clamp.+ * Where the drag handle is asking for the window to go, before the work-area+ * clamp.*- * The caller resolves the display from *this* rect rather than from the window's current- * one, so dragging towards a second display follows the pointer instead of stopping at- * the edge of the display the drag started on.+ * The caller resolves the display from *this* rect rather than from the window's+ * current one, so dragging towards a second display follows the pointer instead+ * of stopping at the edge of the display the drag started on.*/export function hudDragDestination(input: {bounds: EditorWindowRect;diff --git a/electron/preload.ts b/electron/preload.tsindex 7873bef90..a273f89d8 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -94,8 +94,12 @@ contextBridge.exposeInMainWorld("electronAPI", {endHudOverlayDrag: () => {ipcRenderer.send("hud-overlay-drag-end");},- setHudOverlaySize: (width: number, height: number) => {- ipcRenderer.send("hud-overlay-set-size", width, height);+ setHudOverlaySize: (+ width: number,+ height: number,+ content: { x: number; y: number; width: number; height: number },+ ) => {+ ipcRenderer.send("hud-overlay-set-size", width, height, content);},getSources: async (opts: Electron.SourcesOptions) => {return await ipcRenderer.invoke("get-sources", opts);diff --git a/electron/windows.ts b/electron/windows.tsindex 7deaa458b..851d522a0 100644--- a/electron/windows.ts+++ b/electron/windows.ts@@ -8,7 +8,14 @@ import {saveEditorWindowState,shouldTrackEditorWindow,} from "./editorWindowState";-import { clampHudToWorkArea, hudDragDestination } from "./hudWindowBounds";+import {+ clampHudBoundsToWorkArea,+ type HudContentRect,+ hudContentScreenRect,+ hudDragDestination,+ hudResizeBounds,+ parseHudContentRect,+} from "./hudWindowBounds";const __dirname = path.dirname(fileURLToPath(import.meta.url));@@ -103,6 +110,18 @@ 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.+let hudContentRect: HudContentRect | null = null;++/** 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;+}+// 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@@ -115,14 +134,19 @@ function watchHudWorkAreaChanges() {const reclampHud = () => {const win = hudOverlayWindow;- if (!win || win.isDestroyed()) return;+ // 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 = clampHudToWorkArea(bounds, screen.getDisplayMatching(bounds).workArea);+ const next = clampHudBoundsToWorkArea(bounds, hudContentRect, hudWorkAreaFor(bounds));if (next.x !== bounds.x ||next.y !== bounds.y ||@@ -242,36 +266,45 @@ ipcMain.on("hud-overlay-drag-to", (_event, deltaX: number, deltaY: number) => {return;}- // Clamp to the work area of the display the drag is heading *for* — resolved from the- // destination, not from where the window currently sits, so a drag towards a second- // display follows the pointer instead of stopping at the edge it started on.- //- // Without this the drag handle was a one-way trip off the screen: the taskbar and the- // Dock live outside the work area, and an always-on-top, `skipTaskbar` HUD parked- // there covers them, with no taskbar entry to click to get it back. The tray icon was- // the only way home. "hud-overlay-set-size" already clamped for exactly this reason;- // this path did not.+ // Clamp the *bar* into the work area of the display the drag is heading for —+ // resolved from the destination, not from where the window currently sits, so a+ // drag towards a second display follows the pointer instead of stopping at the+ // edge it started on. The window itself may overhang: everything in it except+ // the bar is transparent reserve (see hudWindowBounds.ts), and clamping the+ // window instead would hand the bar the reserve's width and ~600px of height as+ // a margin it can never cross — the "stuck at the bottom of the screen" trap.const bounds = hudOverlayWindow.getBounds();const destination = hudDragDestination({ bounds, origin: hudDragOrigin, deltaX, deltaY });- const { workArea } = screen.getDisplayMatching(destination);- hudOverlayWindow.setBounds(clampHudToWorkArea(destination, workArea), false);+ hudOverlayWindow.setBounds(+ clampHudBoundsToWorkArea(destination, hudContentRect, hudWorkAreaFor(destination)),+ false,+ );});ipcMain.on("hud-overlay-drag-end", () => {hudDragOrigin = null;});-// Resize the HUD to fit its rendered content. Anchored by its bottom-centre so it-// stays where the user dragged it while only growing/shrinking, which lets the-// vertical tray layout grow tall instead of scrolling inside a fixed window.+// Resize the HUD to fit its rendered content. The renderer also sends the bar's+// rect inside the requested size (the stack layout is deterministic: centred,+// pinned HUD_BAR_BOTTOM above the window's bottom edge), and every positioning+// decision below is made on that rect rather than on the window — anchored on+// the bar's bottom-centre so a horizontal↔vertical flip resizes the window+// 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// snaps anyway — tweening the window across 10 frames just meant 10 frames of the// bar sitting at an offset that didn't match the content it was drawn with.-ipcMain.on("hud-overlay-set-size", (_event, width: number, height: number) => {+ipcMain.on("hud-overlay-set-size", (_event, width: number, height: number, content: unknown) => {if (!hudOverlayWindow ||hudOverlayWindow.isDestroyed() ||@@ -282,48 +315,37 @@ ipcMain.on("hud-overlay-set-size", (_event, width: number, height: number) => {}// A resize re-anchors from the window's current bounds, which would fight the- // position an in-flight drag is applying. The renderer re-measures on release.+ // position an in-flight drag is applying. The renderer re-measures on release,+ // which re-sends the rect that matched the size actually in force.if (hudDragOrigin) {return;}const bounds = hudOverlayWindow.getBounds();+ const nextContent = parseHudContentRect(content);+ const next = hudResizeBounds({+ bounds,+ previousContent: hudContentRect,+ width,+ height,+ nextContent,+ workArea: hudWorkAreaFor(bounds),+ });+ // A malformed rect must not clobber the last good one: the stored rect is+ // what every later positioning decision clamps by.+ if (nextContent) {+ hudContentRect = nextContent;+ }- // Clamp to the work area of the display the HUD sits on; on a short screen the- // vertical layout can exceed the display, where the bar's own overflow scroll takes over.- const { workArea } = screen.getDisplayMatching(bounds);- const nextWidth = Math.min(workArea.width, Math.max(1, Math.round(width)));- const nextHeight = Math.min(workArea.height, Math.max(1, Math.round(height)));-- if (bounds.width === nextWidth && bounds.height === nextHeight) {+ if (+ next.x === bounds.x &&+ next.y === bounds.y &&+ next.width === bounds.width &&+ next.height === bounds.height+ ) {return;}-- const centerX = bounds.x + bounds.width / 2;- const bottomY = bounds.y + bounds.height;-- // Growing height keeps the bottom edge anchored (so the vertical tray grows- // upward from where the user left it), but that alone can push the top edge- // above the screen — e.g. switching to the tall vertical layout while sitting- // low/mid-screen. The drag handle lives at the tray's start (top, in vertical- // mode), so an off-screen top edge makes the HUD both invisible and- // undraggable back into view. Clamp both axes to the display's work area so- // the window (and its drag handle) always stays fully reachable.- const nextX = Math.min(- Math.max(workArea.x, Math.round(centerX - nextWidth / 2)),- workArea.x + workArea.width - nextWidth,- );- const nextY = Math.min(- Math.max(workArea.y, Math.round(bottomY - nextHeight)),- workArea.y + workArea.height - nextHeight,- );-- hudOverlayWindow.setBounds({- x: nextX,- y: nextY,- width: nextWidth,- height: nextHeight,- });+ hudOverlayWindow.setBounds(next, false);});/**diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsxindex ea1573028..9929df5d2 100644--- a/src/components/launch/LaunchWindow.tsx+++ b/src/components/launch/LaunchWindow.tsx@@ -349,6 +349,14 @@ 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.+ const lastSentHudContentRef = useRef<{+ x: number;+ y: number;+ width: number;+ height: number;+ } | null>(null);const isDraggingHudRef = useRef(false);useLayoutEffect(() => {@@ -418,14 +426,48 @@ export function LaunchWindow() {required.height > allocated.height ||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.+ const currentContent = {+ x: barRect.x,+ y: barRect.y,+ width: barWidth,+ height: barHeight,+ };+ const grantedContent = {+ x: (granted.width - barWidth) / 2,+ y: granted.height - HUD_BAR_BOTTOM - barHeight,+ width: barWidth,+ height: barHeight,+ };+if (!needsResize) {+ const last = lastSentHudContentRef.current;+ const contentChanged =+ !last ||+ last.width !== currentContent.width ||+ last.height !== currentContent.height ||+ 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.+ lastSentHudContentRef.current = currentContent;+ window.electronAPI.setHudOverlaySize(allocated.width, allocated.height, currentContent);return;}allocated.orientation = trayLayout;allocated.width = granted.width;allocated.height = granted.height;- window.electronAPI.setHudOverlaySize(granted.width, granted.height);+ lastSentHudContentRef.current = grantedContent;+ window.electronAPI.setHudOverlaySize(granted.width, granted.height, grantedContent);}, [trayLayout]);// One persistent observer; elements wire themselves up via callback refs as