diff --git a/electron/countdownOverlay.ts b/electron/countdownOverlay.ts index 6ddf16064..2a8d47387 100644 --- a/electron/countdownOverlay.ts +++ b/electron/countdownOverlay.ts @@ -16,6 +16,14 @@ /** Sent by the overlay's renderer once a frame without the digit has been painted. */ export const COUNTDOWN_OVERLAY_CLEARED_CHANNEL = "countdown-overlay-cleared"; +/** + * How long the post-countdown marquee sweeps the recorded display before the take starts: + * the CSS animation on the overlay's ring runs ~1.3 s, this gives it the fade-out margin. + * The marquee plays while the capture is not armed yet, so it cannot leak into the video — + * the window is still hidden (and on Linux, clear-frame ordered) before the first frame. + */ +export const RECORDING_MARQUEE_MS = 1_400; + /** * How long to wait for that report before hiding anyway. A cleared frame normally takes a few * display frames; this only bounds a renderer that never answers, which would otherwise keep diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts index f0c93ff95..e8eb89fb3 100644 --- a/electron/electron-env.d.ts +++ b/electron/electron-env.d.ts @@ -548,6 +548,9 @@ interface Window { showCountdownOverlay: (value: number, runId: number) => Promise; setCountdownOverlayValue: (value: number, runId: number) => Promise; hideCountdownOverlay: (runId: number) => Promise; + /** Resolves after the one-shot marquee has swept the recorded display. */ + runRecordingMarquee: (runId: number) => Promise; + onCountdownOverlayMarquee: (callback: (runId: number) => void) => () => void; onCountdownOverlayValue: ( callback: (value: number | null, runId: number) => void, ) => () => void; diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts index e4bab0f5c..8af2f7ffe 100644 --- a/electron/ipc/handlers.ts +++ b/electron/ipc/handlers.ts @@ -77,7 +77,7 @@ import { writeFileReplacing } from "../atomic-rename"; import { bringToFront } from "../bringToFront"; import { CameraPreviewController } from "../cameraPreview"; import { createRunnerHost } from "../cli/runnerHost"; -import { hideCountdownOverlay } from "../countdownOverlay"; +import { hideCountdownOverlay, RECORDING_MARQUEE_MS } from "../countdownOverlay"; import { isDiagnosticModeEnabled, mainLogFile } from "../diagnostics/main-log-file"; import { createZip } from "../diagnostics/zip"; import { mainT } from "../i18n"; @@ -2670,6 +2670,13 @@ export function registerIpcHandlers( return; } + // Bound the overlay to the source the take will capture, so the countdown + // digit (and the marquee after it) land on the recorded display instead of + // the primary one — multi-screen users otherwise read the countdown on the + // wrong screen. A display pick resolves to the display's bounds; a window + // pick to that window's rect, via `getSelectedSourceBounds`. + overlayWindow.setBounds(getSelectedSourceBounds()); + // Wait for the first frame before showing, else Chromium flashes a black // rectangle because it hasn't rendered any pixels yet. if (overlayWindow.webContents.isLoading()) { @@ -2709,6 +2716,22 @@ export function registerIpcHandlers( }); }); + // The one-shot marquee after the last countdown digit: the overlay sweeps a + // ring around the display it is already bounded to, then the take starts. + // Resolving after the sweep is what gates the capture: the ring plays while + // the capture is not armed yet, so it cannot leak into the video, and the + // ordinary hide (clear-frame ordered on Linux, see `countdownOverlay.ts`) + // still runs before the first frame. + ipcMain.handle("countdown-overlay-marquee", async (_, runId: number) => { + const overlayWindow = getCountdownOverlayWindow?.(); + if (!overlayWindow || overlayWindow.isDestroyed()) { + return; + } + + overlayWindow.webContents.send("countdown-overlay-marquee", runId); + await new Promise((resolve) => setTimeout(resolve, RECORDING_MARQUEE_MS)); + }); + ipcMain.handle("is-native-windows-capture-available", async () => { if (!isWindowsGraphicsCaptureOsSupported()) { return { success: true, available: false, reason: "unsupported-os" }; diff --git a/electron/preload.ts b/electron/preload.ts index 3f5716036..72c4d49fc 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -612,6 +612,14 @@ contextBridge.exposeInMainWorld("electronAPI", { hideCountdownOverlay: (runId: number) => { return ipcRenderer.invoke("countdown-overlay-hide", runId); }, + runRecordingMarquee: (runId: number) => { + return ipcRenderer.invoke("countdown-overlay-marquee", runId); + }, + onCountdownOverlayMarquee: (callback: (runId: number) => void) => { + const listener = (_event: unknown, runId: number) => callback(runId); + ipcRenderer.on("countdown-overlay-marquee", listener); + return () => ipcRenderer.removeListener("countdown-overlay-marquee", listener); + }, onCountdownOverlayValue: (callback: (value: number | null, runId: number) => void) => { const listener = (_event: unknown, value: number | null, runId: number) => callback(value, runId); diff --git a/electron/windows.ts b/electron/windows.ts index 386e256cc..41907ab6e 100644 --- a/electron/windows.ts +++ b/electron/windows.ts @@ -800,23 +800,18 @@ export function createSourceSelectorWindow(): BrowserWindow { } /** - * Centered transparent countdown overlay that sits above the HUD during - * recording pre-roll. + * Transparent countdown overlay that sits above the HUD during recording + * pre-roll. It has no fixed size: the show handler (`ipc/handlers.ts`) bounds it + * to the display being recorded, so the countdown digit and the marquee ring + * land on the screen the take will capture, not on the primary one. */ export function createCountdownOverlayWindow(): BrowserWindow { - const { workArea } = screen.getPrimaryDisplay(); const overlayWidth = 420; const overlayHeight = 260; const win = new BrowserWindow({ width: overlayWidth, height: overlayHeight, - minWidth: overlayWidth, - maxWidth: overlayWidth, - minHeight: overlayHeight, - maxHeight: overlayHeight, - x: Math.round(workArea.x + (workArea.width - overlayWidth) / 2), - y: Math.round(workArea.y + (workArea.height - overlayHeight) / 2), frame: false, resizable: false, alwaysOnTop: true, diff --git a/src/components/launch/CountdownOverlay.test.tsx b/src/components/launch/CountdownOverlay.test.tsx index 621bab7bb..dced171e9 100644 --- a/src/components/launch/CountdownOverlay.test.tsx +++ b/src/components/launch/CountdownOverlay.test.tsx @@ -4,9 +4,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { CLEARED_AFTER_FRAMES, CountdownOverlay } from "./CountdownOverlay"; type ValueListener = (value: number | null, runId: number) => void; +type MarqueeListener = (runId: number) => void; describe("CountdownOverlay", () => { let pushValue: ValueListener = () => undefined; + let pushMarquee: MarqueeListener = () => undefined; let frames: FrameRequestCallback[] = []; let textAtFrameRequest: string[] = []; let notifyCleared: ReturnType; @@ -27,6 +29,10 @@ describe("CountdownOverlay", () => { pushValue = listener; return () => undefined; }, + onCountdownOverlayMarquee: (listener: MarqueeListener) => { + pushMarquee = listener; + return () => undefined; + }, notifyCountdownOverlayCleared: notifyCleared, } as typeof window.electronAPI; ({ container } = render()); @@ -70,4 +76,45 @@ describe("CountdownOverlay", () => { expect(frames).toHaveLength(0); expect(notifyCleared).not.toHaveBeenCalled(); }); + + it("replaces the digit with the marquee ring on the marquee event", () => { + act(() => pushValue(1, 7)); + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + + act(() => pushMarquee(7)); + + // The ring is up and the digit is gone — the sweep plays between the countdown + // and the take, so the digit must not linger under it. + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + expect(container.textContent).toBe(""); + }); + + it("drops the ring when the next countdown digit arrives", () => { + act(() => pushMarquee(3)); + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + + act(() => pushValue(3, 3)); + + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(container.textContent).toBe("3"); + }); + + it("clears the ring in the same commit as the cleared frame", () => { + act(() => pushMarquee(5)); + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + + act(() => pushValue(null, 5)); + + // The ring is gone before the first frame is even requested: a cleared frame that + // still painted the ring would let the hide carry it into the take on Linux. + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(textAtFrameRequest[0]).toBe(""); + for (let frame = 1; frame < CLEARED_AFTER_FRAMES; frame += 1) { + nextFrame(); + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(notifyCleared).not.toHaveBeenCalled(); + } + nextFrame(); + expect(notifyCleared).toHaveBeenCalledExactlyOnceWith(5); + }); }); diff --git a/src/components/launch/CountdownOverlay.tsx b/src/components/launch/CountdownOverlay.tsx index 6b5071b72..a91598368 100644 --- a/src/components/launch/CountdownOverlay.tsx +++ b/src/components/launch/CountdownOverlay.tsx @@ -19,11 +19,19 @@ function afterAnimationFrames(count: number, callback: () => void) { export function CountdownOverlay() { const [value, setValue] = useState(null); + /** The one-shot ring that sweeps the display between the last digit and the take. */ + const [marquee, setMarquee] = useState(false); useEffect(() => { const unsubscribe = window.electronAPI.onCountdownOverlayValue((nextValue, runId) => { // Committed now rather than batched, so every frame counted below is already empty. - flushSync(() => setValue(nextValue)); + // The ring clears in the same commit as the digit OR the cleared frame: a null value + // must not leave the previous run's sweep still painted when the cleared frame is + // acknowledged, or the hide can carry that ring into the take on Linux. + flushSync(() => { + setValue(nextValue); + setMarquee(false); + }); if (nextValue === null) { afterAnimationFrames(CLEARED_AFTER_FRAMES, () => window.electronAPI.notifyCountdownOverlayCleared(runId), @@ -31,23 +39,36 @@ export function CountdownOverlay() { } }); - return () => unsubscribe(); + const unsubscribeMarquee = window.electronAPI.onCountdownOverlayMarquee(() => { + setMarquee(true); + }); + + return () => { + unsubscribe(); + unsubscribeMarquee(); + }; }, []); - if (value === null) { + if (value === null && !marquee) { return null; } return (
-
-
- {value} -
-
+ {marquee ? ( + ); } diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts index f4ef51391..cd64f3faa 100644 --- a/src/hooks/useScreenRecorder.ts +++ b/src/hooks/useScreenRecorder.ts @@ -1261,6 +1261,16 @@ export function useScreenRecorder(): UseScreenRecorderReturn { } }; + // Best-effort like every overlay call: a marquee that fails to play must not fail the + // take — the hide below still runs, and recording starts as it always did. + const safeRunRecordingMarquee = async (runId: number) => { + try { + await window.electronAPI.runRecordingMarquee(runId); + } catch (error) { + console.warn("Failed to play the recording marquee:", error); + } + }; + const isCountdownRunActive = (runId?: number) => runId === undefined || countdownRunId.current === runId; @@ -1928,6 +1938,18 @@ export function useScreenRecorder(): UseScreenRecorderReturn { return; } + // After the last digit, the marquee sweeps the display about to be recorded — + // the user's cue for which screen the take lands on. It resolves once the sweep + // has faded; the capture arms only after the hide below, so the ring cannot + // reach the video. + if (overlayShown) { + await safeRunRecordingMarquee(runId); + + if (countdownRunId.current !== runId) { + return; + } + } + setCountdownActive(false); await safeHideCountdownOverlay(runId); overlayHiddenBeforeStart = true; diff --git a/src/index.css b/src/index.css index 2a92cfc26..7483e2009 100644 --- a/src/index.css +++ b/src/index.css @@ -397,3 +397,61 @@ html [data-sonner-toaster] [data-sonner-toast][data-styled="true"] [data-close-b background: color-mix(in oklab, var(--fg) 10%, transparent); color: var(--fg); } + +/* The recording marquee: a ring that sweeps the display about to be recorded, between the + countdown and the first captured frame (`CountdownOverlay.tsx`, `countdown-overlay-marquee` + in `ipc/handlers.ts`). The window covers the whole display, so the ring traces its edges; + the rotating gradient lives on an oversized ::before, clipped to a ring by the padding-box + mask, so the sweep stays a moving highlight instead of a spinning pie. It plays once and + fades — the capture is not armed yet, nothing here can leak into the video. */ +@keyframes recording-marquee-sweep { + from { + transform: rotate(0turn); + } + to { + transform: rotate(1.5turn); + } +} + +@keyframes recording-marquee-fade { + 0%, + 75% { + opacity: 1; + } + 100% { + opacity: 0; + } +} + +.recording-marquee-ring { + position: absolute; + inset: 0; + overflow: hidden; + border-radius: 24px; + padding: 6px; + animation: recording-marquee-fade 1.3s ease-out 1 both; + -webkit-mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + -webkit-mask-composite: xor; + mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + mask-composite: exclude; +} + +.recording-marquee-ring::before { + content: ""; + position: absolute; + inset: -60%; + background: conic-gradient( + from 0deg, + transparent 0deg, + #38bdf8 90deg, + #a5f3fc 160deg, + #38bdf8 230deg, + transparent 320deg, + transparent 360deg + ); + animation: recording-marquee-sweep 1.2s cubic-bezier(0.4, 0, 0.2, 1) 1 both; +}