Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

Pick a window, a screen or an area on screen

Kevinf91d1a128858
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts
index 13ec73ab..b9bc587c 100644
--- a/electron/electron-env.d.ts
+++ b/electron/electron-env.d.ts
@@ -242,6 +242,24 @@ interface Window {
openSourceSelector: () => Promise<void>;
selectSource: (source: ProcessedDesktopSource) => Promise<ProcessedDesktopSource>;
showSourceHighlight: (source: ProcessedDesktopSource) => Promise<{ success: boolean }>;
+ /** Opens the capture picker on every display and resolves when it closes. */
+ pickCaptureTarget: () => Promise<{
+ success: boolean;
+ canceled?: boolean;
+ record?: boolean;
+ source?: ProcessedDesktopSource;
+ message?: string;
+ }>;
+ completeCapturePick: (pick: CapturePick | null) => Promise<void>;
+ getCapturePickerContext: (displayId: number) => Promise<{
+ displayBounds: CaptureArea | null;
+ lastArea: CaptureArea | null;
+ /** On-screen windows on this display, front to back. */
+ windows: CapturePickerWindow[];
+ cursor: { x: number; y: number } | null;
+ }>;
+ /** Reveals the picker window once it has painted its first state. */
+ capturePickerReady: () => void;
getSelectedSource: () => Promise<ProcessedDesktopSource | null>;
onSelectedSourceChanged: (
callback: (source: ProcessedDesktopSource | null) => void,
@@ -1042,6 +1060,32 @@ interface Window {
};
}
+/** A rectangle in global display points (top-left origin). */
+interface CaptureArea {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}
+
+/** A window the capture picker can highlight, framed in global display points. */
+interface CapturePickerWindow extends CaptureArea {
+ /** The window's source id, `window:<windowId>:0`. */
+ id: string;
+ appName: string;
+ title: string;
+ display_id?: string;
+}
+
+/**
+ * What the capture picker reports when the user confirms: an area they drew, a
+ * window they clicked, or a whole screen. `record` starts recording right away.
+ */
+type CapturePick =
+ | (CaptureArea & { kind: "area"; displayId: number; record: boolean })
+ | { kind: "window"; windowId: string; displayId: number; record: boolean }
+ | { kind: "screen"; displayId: number; record: boolean };
+
interface ProcessedDesktopSource {
id: string;
name: string;
@@ -1049,9 +1093,11 @@ interface ProcessedDesktopSource {
thumbnail: string | null;
appIcon: string | null;
originalName?: string;
- sourceType?: "screen" | "window";
+ sourceType?: "screen" | "window" | "area";
appName?: string;
windowTitle?: string;
+ /** For area sources, the recorded part of the display. */
+ area?: CaptureArea;
}
interface CursorTelemetryPoint {
diff --git a/electron/ipc/cursor/bounds.ts b/electron/ipc/cursor/bounds.ts
index 1b8b8eaa..fddbbd0e 100644
--- a/electron/ipc/cursor/bounds.ts
+++ b/electron/ipc/cursor/bounds.ts
@@ -59,6 +59,34 @@ export async function getNativeMacWindowSources(options?: { maxAgeMs?: number })
}
}
+/** On-screen windows ordered front to back, for finding the window under a point. */
+export async function getNativeMacWindowsFrontToBack(): Promise<NativeMacWindowSource[]> {
+ if (process.platform !== "darwin") {
+ return [];
+ }
+
+ try {
+ const binaryPath = await ensureNativeWindowListBinary();
+ const { stdout } = await execFileAsync(binaryPath, ["--z-order"], {
+ timeout: 10000,
+ maxBuffer: 10 * 1024 * 1024,
+ });
+ const parsed: unknown = JSON.parse(stdout);
+ if (!Array.isArray(parsed)) {
+ return [];
+ }
+ return parsed.filter(
+ (entry): entry is NativeMacWindowSource =>
+ Boolean(entry) &&
+ typeof entry === "object" &&
+ typeof (entry as NativeMacWindowSource).id === "string",
+ );
+ } catch (error) {
+ console.warn("Failed to list windows front to back:", error);
+ return [];
+ }
+}
+
export function getWindowBoundsFromNativeSource(
source?: NativeMacWindowSource | null,
): WindowBounds | null {
diff --git a/electron/ipc/cursor/telemetry.ts b/electron/ipc/cursor/telemetry.ts
index 73f62714..8318497b 100644
--- a/electron/ipc/cursor/telemetry.ts
+++ b/electron/ipc/cursor/telemetry.ts
@@ -23,6 +23,7 @@ import {
setPendingCursorSamples,
} from "../state";
import type { CursorInteractionType, CursorTelemetryPoint, CursorVisualType } from "../types";
+import { getSourceArea } from "../sourceArea";
import { getScreen, getTelemetryPathForVideo } from "../utils";
export function clamp(value: number, min: number, max: number) {
@@ -176,7 +177,10 @@ export function getNormalizedCursorPoint() {
? { x: linuxCursorCache.x / primarySf, y: linuxCursorCache.y / primarySf }
: fallbackCursor;
- const windowBounds = selectedSource?.id?.startsWith("window:") ? selectedWindowBounds : null;
+ // Areas are fixed rectangles, so they normalize like a window that never moves.
+ const windowBounds = selectedSource?.id?.startsWith("window:")
+ ? selectedWindowBounds
+ : getSourceArea(selectedSource);
if (windowBounds) {
const sf =
process.platform === "win32" || process.platform === "darwin"
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index e87e677e..3208f8a2 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -1,5 +1,6 @@
import { BrowserWindow } from "electron";
import { registerAnnouncementHandlers } from "./register/announcements";
+import { registerCapturePickerHandlers } from "./register/capturePicker";
import { registerAssetHandlers } from "./register/assets";
import { registerCaptionHandlers } from "./register/captions";
import { registerCloudShareHandlers } from "./register/cloudShare";
@@ -64,6 +65,7 @@ export function registerIpcHandlers(
createSourceSelectorWindow,
getSourceSelectorWindow,
});
+ registerCapturePickerHandlers();
registerRecordingHandlers(onRecordingStateChange);
registerPermissionHandlers();
registerAnnouncementHandlers();
diff --git a/electron/ipc/register/capturePicker.ts b/electron/ipc/register/capturePicker.ts
new file mode 100644
index 00000000..236d7e55
--- /dev/null
+++ b/electron/ipc/register/capturePicker.ts
@@ -0,0 +1,154 @@
+import { ipcMain } from "electron";
+import { closeCapturePickerWindows, createCapturePickerWindows } from "../../windows";
+import { getNativeMacWindowsFrontToBack, stopWindowBoundsCapture } from "../cursor/bounds";
+import { setSelectedSource } from "../state";
+import { createAreaSource, createWindowSource, normalizeCapturePick } from "../sourceArea";
+import type { AreaCapturePick, CapturePick, CapturePickerWindow, SelectedSource } from "../types";
+import { getScreen } from "../utils";
+import { getScreenSourceIdForDisplay } from "./sourceMapping";
+import { bringSelectedWindowForward, broadcastSelectedSourceChange } from "./sources";
+
+/** Windows the picker can offer, front to back, without Recordly's own. */
+async function listPickableWindows(): Promise<CapturePickerWindow[]> {
+ const entries = await getNativeMacWindowsFrontToBack();
+ return entries.flatMap((entry) => {
+ const { x, y, width, height } = entry;
+ if (
+ entry.ownerPid === process.pid ||
+ typeof x !== "number" ||
+ typeof y !== "number" ||
+ typeof width !== "number" ||
+ typeof height !== "number" ||
+ width <= 0 ||
+ height <= 0
+ ) {
+ return [];
+ }
+ return [
+ {
+ id: entry.id,
+ appName: entry.appName ?? "",
+ title: entry.windowTitle ?? entry.name,
+ display_id: entry.display_id,
+ x,
+ y,
+ width,
+ height,
+ },
+ ];
+ });
+}
+
+/** The same source the screen list offers for this display. */
+function createScreenSource(displayId: number): SelectedSource | null {
+ const displays = getScreen().getAllDisplays();
+ const index = displays.findIndex((display) => display.id === displayId);
+ if (index < 0) return null;
+ const isPrimary = getScreen().getPrimaryDisplay().id === displayId;
+ return {
+ id: getScreenSourceIdForDisplay({
+ displayId: String(displayId),
+ platform: process.platform,
+ }),
+ name: isPrimary ? `Screen ${index + 1} (Primary)` : `Screen ${index + 1}`,
+ display_id: String(displayId),
+ sourceType: "screen",
+ };
+}
+
+/**
+ * The capture picker covers every display: hovering highlights the window under
+ * the cursor, a click picks that window or the whole screen, and a drag draws an
+ * area. The pick becomes the selected source.
+ */
+export function registerCapturePickerHandlers() {
+ let resolvePendingPick: ((pick: CapturePick | null) => void) | null = null;
+ let pickableWindows: Promise<CapturePickerWindow[]> = Promise.resolve([]);
+ let lastArea: AreaCapturePick | null = null;
+
+ const finishPick = (pick: CapturePick | null) => {
+ const resolve = resolvePendingPick;
+ resolvePendingPick = null;
+ resolve?.(pick);
+ };
+
+ ipcMain.handle("pick-capture-target", async () => {
+ if (process.platform !== "darwin") {
+ return { success: false, message: "Picking on screen is available on macOS." };
+ }
+
+ finishPick(null);
+ // List windows before the overlays cover them.
+ pickableWindows = listPickableWindows();
+ const pick = await new Promise<CapturePick | null>((resolve) => {
+ resolvePendingPick = resolve;
+ // Closing an overlay without confirming cancels the pick.
+ createCapturePickerWindows(() => finishPick(null));
+ });
+ closeCapturePickerWindows();
+ if (!pick) {
+ return { success: false, canceled: true };
+ }
+
+ let source: SelectedSource | null;
+ if (pick.kind === "area") {
+ lastArea = pick;
+ source = createAreaSource(pick);
+ } else if (pick.kind === "window") {
+ const window = (await pickableWindows).find((entry) => entry.id === pick.windowId);
+ source = window ? createWindowSource(window) : null;
+ } else {
+ source = createScreenSource(pick.displayId);
+ }
+ if (!source) {
+ return { success: false, message: "That window or screen is no longer available." };
+ }
+
+ // Recording raises the window itself, so only raise it here when it is
+ // just being selected.
+ if (source.id?.startsWith("window:") && !pick.record) {
+ await bringSelectedWindowForward(source);
+ }
+ setSelectedSource(source);
+ broadcastSelectedSourceChange();
+ stopWindowBoundsCapture();
+ return { success: true, source, record: pick.record };
+ });
+
+ ipcMain.handle("complete-capture-pick", async (_, input: unknown) => {
+ if (!input) {
+ finishPick(null);
+ return;
+ }
+ const displays = getScreen()
+ .getAllDisplays()
+ .map((display) => ({ id: display.id, bounds: display.bounds }));
+ finishPick(normalizeCapturePick(input, displays, await pickableWindows));
+ });
+
+ ipcMain.handle("get-capture-picker-context", async (_, displayId: unknown) => {
+ const display = getScreen()
+ .getAllDisplays()
+ .find((entry) => entry.id === Number(displayId));
+ if (!display) {
+ return { displayBounds: null, lastArea: null, windows: [], cursor: null };
+ }
+ const { x, y, width, height } = display.bounds;
+ const windows = (await pickableWindows).filter(
+ (window) =>
+ window.x < x + width &&
+ window.x + window.width > x &&
+ window.y < y + height &&
+ window.y + window.height > y,
+ );
+ const previous = lastArea?.displayId === display.id ? lastArea : null;
+ return {
+ displayBounds: display.bounds,
+ lastArea: previous
+ ? { x: previous.x, y: previous.y, width: previous.width, height: previous.height }
+ : null,
+ windows,
+ cursor: getScreen().getCursorScreenPoint(),
+ };
+ });
+}
diff --git a/electron/ipc/register/recording.ts b/electron/ipc/register/recording.ts
index 797f8bad..4c29dded 100644
--- a/electron/ipc/register/recording.ts
+++ b/electron/ipc/register/recording.ts
@@ -14,7 +14,12 @@ import {
} from "electron";
import { getHudCaptureExcludedProcessIds } from "../../../src/lib/hudCaptureProtection";
import { showCursor } from "../../cursorHider";
-import { getHudOverlayCaptureProtectionEnabled, beginHudCaptureProtection } from "../../windows";
+import {
+ beginHudCaptureProtection,
+ getHudOverlayCaptureProtectionEnabled,
+ hideAreaRecordingBorder,
+ showAreaRecordingBorder,
+} from "../../windows";
import { ALLOW_RECORDLY_WINDOW_CAPTURE } from "../constants";
import { startWindowBoundsCapture, stopWindowBoundsCapture } from "../cursor/bounds";
import { startInteractionCapture, stopInteractionCapture } from "../cursor/interaction";
@@ -152,6 +157,7 @@ import {
parseWindowId,
} from "../utils";
import { resolveWindowsCaptureTarget } from "../windowsCaptureSelection";
+import { getSourceArea } from "../sourceArea";
import { bringSelectedWindowForward } from "./sources";
const execFileAsync = promisify(execFile);
@@ -762,8 +768,21 @@ export function registerRecordingHandlers(
const windowId = parseWindowId(source?.id);
const screenId = Number(source?.display_id);
-
- if (Number.isFinite(windowId) && windowId && source?.id?.startsWith("window:")) {
+ const area = getSourceArea(source);
+
+ if (area) {
+ config.regionX = area.x;
+ config.regionY = area.y;
+ config.regionWidth = area.width;
+ config.regionHeight = area.height;
+ if (Number.isFinite(screenId) && screenId > 0) {
+ config.displayId = screenId;
+ }
+ } else if (
+ Number.isFinite(windowId) &&
+ windowId &&
+ source?.id?.startsWith("window:")
+ ) {
config.windowId = windowId;
if (visibleWindowBounds) {
config.windowX = visibleWindowBounds.x;
@@ -1889,6 +1908,12 @@ export function registerRecordingHandlers(
}
const source = selectedSource || { name: "Screen" };
+ const recordingArea = recording ? getSourceArea(selectedSource) : null;
+ if (recordingArea) {
+ showAreaRecordingBorder(recordingArea);
+ } else {
+ hideAreaRecordingBorder();
+ }
BrowserWindow.getAllWindows().forEach((window) => {
if (!window.isDestroyed()) {
window.webContents.send("recording-state-changed", {
diff --git a/electron/ipc/register/sources.ts b/electron/ipc/register/sources.ts
index e5b7cd0b..bf80a5a2 100644
--- a/electron/ipc/register/sources.ts
+++ b/electron/ipc/register/sources.ts
@@ -18,6 +18,7 @@ import {
import { getDisplayBoundsForSource, getDisplayWorkAreaForSource } from "../recording/ffmpeg";
import { selectedSource, setSelectedSource } from "../state";
import type { SelectedSource, WindowBounds } from "../types";
+import { getSourceArea } from "../sourceArea";
import { getScreen, parseWindowId } from "../utils";
import { bringWindowsWindowForward, resolveWindowsWindowBounds } from "../windowsWindowControl";
import { getScreenSourceIdForDisplay } from "./sourceMapping";
@@ -34,7 +35,7 @@ function normalizeDesktopSourceName(value: string) {
return value.trim().replace(/\s+/g, " ").toLowerCase();
}
-function broadcastSelectedSourceChange() {
+export function broadcastSelectedSourceChange() {
for (const window of BrowserWindow.getAllWindows()) {
if (!window.isDestroyed()) {
window.webContents.send("selected-source-changed", selectedSource);
@@ -408,9 +409,12 @@ export function registerSourceHandlers({
const isWindow = source.id?.startsWith("window:");
// ── 1. Resolve bounds ──
- let bounds: { x: number; y: number; width: number; height: number } | null = null;
+ let bounds: { x: number; y: number; width: number; height: number } | null =
+ getSourceArea(source);
- if (source.id?.startsWith("screen:")) {
+ if (bounds) {
+ // An area highlights exactly the rectangle that will be recorded.
+ } else if (source.id?.startsWith("screen:")) {
bounds =
process.platform === "darwin"
? getDisplayWorkAreaForSource(source)
diff --git a/electron/ipc/sourceArea.test.ts b/electron/ipc/sourceArea.test.ts
new file mode 100644
index 00000000..ef245a47
--- /dev/null
+++ b/electron/ipc/sourceArea.test.ts
@@ -0,0 +1,148 @@
+import { describe, expect, it } from "vitest";
+import {
+ createAreaSource,
+ createWindowSource,
+ getSourceArea,
+ normalizeCapturePick,
+} from "./sourceArea";
+
+const displays = [
+ { id: 1, bounds: { x: 0, y: 0, width: 1728, height: 1117 } },
+ { id: 2, bounds: { x: 1728, y: -200, width: 2560, height: 1440 } },
+];
+const windows = [
+ {
+ id: "window:42:0",
+ appName: "Safari",
+ title: "Docs",
+ display_id: "1",
+ x: 10,
+ y: 40,
+ width: 1200,
+ height: 800,
+ },
+];
+
+describe("normalizeCapturePick", () => {
+ it("keeps an area that lies on its display", () => {
+ expect(
+ normalizeCapturePick(
+ {
+ kind: "area",
+ x: 100.4,
+ y: 50,
+ width: 1280,
+ height: 720,
+ displayId: 1,
+ record: true,
+ },
+ displays,
+ windows,
+ ),
+ ).toEqual({
+ kind: "area",
+ x: 100,
+ y: 50,
+ width: 1280,
+ height: 720,
+ displayId: 1,
+ record: true,
+ });
+ });
+
+ it("clips an area to its display, including displays left of or above the origin", () => {
+ expect(
+ normalizeCapturePick(
+ { kind: "area", x: 1700, y: -300, width: 400, height: 400, displayId: 2 },
+ displays,
+ windows,
+ ),
+ ).toEqual({
+ kind: "area",
+ x: 1728,
+ y: -200,
+ width: 372,
+ height: 300,
+ displayId: 2,
+ record: false,
+ });
+ });
+
+ it("trims an area to an even size so it maps onto whole screen pixels", () => {
+ expect(
+ normalizeCapturePick(
+ { kind: "area", x: 10, y: 20, width: 401, height: 301, displayId: 1 },
+ displays,
+ windows,
+ ),
+ ).toMatchObject({ x: 10, y: 20, width: 400, height: 300 });
+ });
+
+ it("rejects areas that are too small, unknown displays and malformed input", () => {
+ const area = { kind: "area", x: 0, y: 0, width: 20, height: 400, displayId: 1 };
+ expect(normalizeCapturePick(area, displays, windows)).toBeNull();
+ expect(
+ normalizeCapturePick({ ...area, width: 400, displayId: 9 }, displays, windows),
+ ).toBeNull();
+ expect(normalizeCapturePick({ ...area, width: "400" }, displays, windows)).toBeNull();
+ expect(normalizeCapturePick({ ...area, kind: "region" }, displays, windows)).toBeNull();
+ expect(normalizeCapturePick(null, displays, windows)).toBeNull();
+ });
+
+ it("accepts only windows the picker offered", () => {
+ expect(
+ normalizeCapturePick(
+ { kind: "window", windowId: "window:42:0", displayId: 1, record: true },
+ displays,
+ windows,
+ ),
+ ).toEqual({ kind: "window", windowId: "window:42:0", displayId: 1, record: true });
+ expect(
+ normalizeCapturePick(
+ { kind: "window", windowId: "window:7:0", displayId: 1 },
+ displays,
+ windows,
+ ),
+ ).toBeNull();
+ });
+
+ it("accepts a connected screen", () => {
+ expect(normalizeCapturePick({ kind: "screen", displayId: 2 }, displays, windows)).toEqual({
+ kind: "screen",
+ displayId: 2,
+ record: false,
+ });
+ });
+});
+
+describe("picked sources", () => {
+ it("round-trips an area's rectangle", () => {
+ const source = createAreaSource({
+ kind: "area",
+ x: 10,
+ y: 20,
+ width: 640,
+ height: 480,
+ displayId: 1,
+ record: false,
+ });
+ expect(source).toMatchObject({ id: "area:1", name: "Area 640×480", display_id: "1" });
+ expect(getSourceArea(source)).toEqual({ x: 10, y: 20, width: 640, height: 480 });
+ });
+
+ it("builds the same window source the window list offers", () => {
+ expect(createWindowSource(windows[0])).toEqual({
+ id: "window:42:0",
+ name: "Docs",
+ display_id: "1",
+ sourceType: "window",
+ appName: "Safari",
+ windowTitle: "Docs",
+ });
+ });
+
+ it("ignores sources that are not areas", () => {
+ expect(getSourceArea({ id: "screen:1:0", name: "Screen" })).toBeNull();
+ expect(getSourceArea(null)).toBeNull();
+ });
+});
diff --git a/electron/ipc/sourceArea.ts b/electron/ipc/sourceArea.ts
new file mode 100644
index 00000000..9e363c24
--- /dev/null
+++ b/electron/ipc/sourceArea.ts
@@ -0,0 +1,107 @@
+import type {
+ AreaCapturePick,
+ CaptureArea,
+ CapturePick,
+ CapturePickerWindow,
+ SelectedSource,
+} from "./types";
+
+/** Smallest area worth recording, in points. */
+export const MIN_CAPTURE_AREA_SIZE = 32;
+
+type PickerDisplay = { id: number; bounds: CaptureArea };
+
+function isFiniteNumber(value: unknown): value is number {
+ return typeof value === "number" && Number.isFinite(value);
+}
+
+/**
+ * Validates what a capture-picker window reports. An area must have a usable size
+ * and lie on the display it was drawn on; a window must be one the picker offered;
+ * a screen must be a connected display.
+ */
+export function normalizeCapturePick(
+ input: unknown,
+ displays: PickerDisplay[],
+ windows: CapturePickerWindow[],
+): CapturePick | null {
+ if (!input || typeof input !== "object") return null;
+ const candidate = input as Record<string, unknown>;
+ const record = candidate.record === true;
+ const display = displays.find((entry) => entry.id === candidate.displayId);
+ if (!display) return null;
+
+ if (candidate.kind === "screen") {
+ return { kind: "screen", displayId: display.id, record };
+ }
+
+ if (candidate.kind === "window") {
+ const window = windows.find((entry) => entry.id === candidate.windowId);
+ return window
+ ? { kind: "window", windowId: window.id, displayId: display.id, record }
+ : null;
+ }
+
+ if (candidate.kind !== "area") return null;
+ const { x, y, width, height } = candidate;
+ if (
+ !isFiniteNumber(x) ||
+ !isFiniteNumber(y) ||
+ !isFiniteNumber(width) ||
+ !isFiniteNumber(height)
+ ) {
+ return null;
+ }
+ const left = Math.max(display.bounds.x, Math.round(x));
+ const top = Math.max(display.bounds.y, Math.round(y));
+ const right = Math.min(display.bounds.x + display.bounds.width, Math.round(x + width));
+ const bottom = Math.min(display.bounds.y + display.bounds.height, Math.round(y + height));
+ // Whole, even sizes map the area onto screen pixels one to one at any display
+ // scale, so the recording is never resampled.
+ const areaWidth = right - left - ((right - left) % 2);
+ const areaHeight = bottom - top - ((bottom - top) % 2);
+ if (areaWidth < MIN_CAPTURE_AREA_SIZE || areaHeight < MIN_CAPTURE_AREA_SIZE) {
+ return null;
+ }
+
+ return {
+ kind: "area",
+ x: left,
+ y: top,
+ width: areaWidth,
+ height: areaHeight,
+ displayId: display.id,
+ record,
+ };
+}
+
+export function createAreaSource(pick: AreaCapturePick): SelectedSource {
+ return {
+ id: `area:${pick.displayId}`,
+ name: `Area ${pick.width}×${pick.height}`,
+ display_id: String(pick.displayId),
+ sourceType: "area",
+ area: { x: pick.x, y: pick.y, width: pick.width, height: pick.height },
+ };
+}
+
+/** The same source the window list offers for this window. */
+export function createWindowSource(window: CapturePickerWindow): SelectedSource {
+ const title = window.title || window.appName || "Window";
+ return {
+ id: window.id,
+ name: title,
+ display_id: window.display_id ?? "",
+ sourceType: "window",
+ appName: window.appName || undefined,
+ windowTitle: title,
+ };
+}
+
+export function getSourceArea(source: SelectedSource | null | undefined): CaptureArea | null {
+ if (!source?.id?.startsWith("area:") || !source.area) return null;
+ const { x, y, width, height } = source.area;
+ return [x, y, width, height].every(Number.isFinite) && width > 0 && height > 0
+ ? { x, y, width, height }
+ : null;
+}
diff --git a/electron/ipc/types.ts b/electron/ipc/types.ts
index 7f022136..5d90df63 100644
--- a/electron/ipc/types.ts
+++ b/electron/ipc/types.ts
@@ -1,13 +1,43 @@
+/** A rectangle in global display points (top-left origin). */
+export type CaptureArea = {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+};
+
export type SelectedSource = {
id?: string;
name: string;
display_id?: string;
- sourceType?: "screen" | "window";
+ sourceType?: "screen" | "window" | "area";
appName?: string;
windowTitle?: string;
+ /** For area sources, the recorded part of the display. */
+ area?: CaptureArea;
[key: string]: unknown;
};
+/** A window the capture picker can highlight, framed in global display points. */
+export type CapturePickerWindow = CaptureArea & {
+ /** The window's source id, `window:<windowId>:0`. */
+ id: string;
+ appName: string;
+ title: string;
+ display_id?: string;
+};
+
+/**
+ * What the capture picker reports when the user confirms: an area they drew, a
+ * window they clicked, or a whole screen. `record` starts recording right away.
+ */
+export type CapturePick =
+ | (CaptureArea & { kind: "area"; displayId: number; record: boolean })
+ | { kind: "window"; windowId: string; displayId: number; record: boolean }
+ | { kind: "screen"; displayId: number; record: boolean };
+
+export type AreaCapturePick = Extract<CapturePick, { kind: "area" }>;
+
export type NativeMacRecordingOptions = {
capturesSystemAudio?: boolean;
capturesMicrophone?: boolean;
@@ -119,6 +149,8 @@ export type NativeMacWindowSource = {
y?: number;
width?: number;
height?: number;
+ /** Process that owns the window. */
+ ownerPid?: number;
};
export type HookEventName = "mousedown" | "mouseup" | "mousemove";
diff --git a/electron/native/ScreenCaptureKitRecorder.swift b/electron/native/ScreenCaptureKitRecorder.swift
index 002b1a67..707813a0 100644
--- a/electron/native/ScreenCaptureKitRecorder.swift
+++ b/electron/native/ScreenCaptureKitRecorder.swift
@@ -12,6 +12,11 @@ struct CaptureConfig: Codable {
let windowY: Double?
let windowWidth: Double?
let windowHeight: Double?
+ /// A fixed area of `displayId` in global display points (top-left origin).
+ let regionX: Double?
+ let regionY: Double?
+ let regionWidth: Double?
+ let regionHeight: Double?
let outputPath: String?
let capturesSystemAudio: Bool?
let capturesMicrophone: Bool?
@@ -130,6 +135,9 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {
excludedProcessIds.contains($0.processID)
}
+ // A window or an area records the part of its display inside a frame, so menus
+ // and popovers over a window are captured just as they appear on screen.
+ let requestedFrame: CGRect?
if let windowId = config.windowId {
trackedWindowId = windowId
guard let window = availableContent.windows.first(where: { $0.windowID == windowId }) else {
@@ -137,22 +145,40 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {
}
// Accessibility reports the visible frame at the native border.
- let visibleFrame: CGRect
if let x = config.windowX,
let y = config.windowY,
let width = config.windowWidth,
let height = config.windowHeight,
width > 0,
height > 0 {
- visibleFrame = CGRect(x: x, y: y, width: width, height: height)
+ requestedFrame = CGRect(x: x, y: y, width: width, height: height)
} else {
- visibleFrame = window.frame
+ requestedFrame = window.frame
}
- guard let display = Self.captureDisplay(for: visibleFrame, from: availableContent.displays) else {
+ } else if let x = config.regionX,
+ let y = config.regionY,
+ let width = config.regionWidth,
+ let height = config.regionHeight,
+ width > 0,
+ height > 0 {
+ trackedWindowId = nil
+ requestedFrame = CGRect(x: x, y: y, width: width, height: height)
+ } else {
+ requestedFrame = nil
+ }
+
+ if let visibleFrame = requestedFrame {
+ let preferredDisplay = config.windowId == nil
+ ? config.displayId.flatMap { displayId in availableContent.displays.first(where: { $0.displayID == displayId }) }
+ : nil
+ guard let display = preferredDisplay ?? Self.captureDisplay(for: visibleFrame, from: availableContent.displays) else {
throw NSError(domain: "RecordlyCapture", code: 4, userInfo: [NSLocalizedDescriptionKey: "Window display not found"])
}
let scaleFactor = ScreenCaptureRecorder.scaleFactor(for: display.displayID)
let captureRect = visibleFrame.intersection(display.frame)
+ guard captureRect.width >= 2, captureRect.height >= 2 else {
+ throw NSError(domain: "RecordlyCapture", code: 18, userInfo: [NSLocalizedDescriptionKey: "Capture area is outside the display"])
+ }
filter = SCContentFilter(
display: display,
excludingApplications: excludedApplications,
diff --git a/electron/native/ScreenCaptureKitRecorder.test.ts b/electron/native/ScreenCaptureKitRecorder.test.ts
index bf787842..edaba7ee 100644
--- a/electron/native/ScreenCaptureKitRecorder.test.ts
+++ b/electron/native/ScreenCaptureKitRecorder.test.ts
@@ -78,7 +78,7 @@ describe("ScreenCaptureKitRecorder window capture", () => {
expect(recorderSource).not.toContain("streamConfig.sourceRect");
expect(recorderSource).not.toContain("desktopIndependentWindow");
expect(recorderSource).toContain(
- "visibleFrame = CGRect(x: x, y: y, width: width, height: height)",
+ "requestedFrame = CGRect(x: x, y: y, width: width, height: height)",
);
expect(recorderSource).toContain(
"let captureRect = visibleFrame.intersection(display.frame)",
@@ -86,6 +86,11 @@ describe("ScreenCaptureKitRecorder window capture", () => {
expect(recorderSource).toContain("appendCroppedVideoFrame(sampleBuffer");
});
+ it("records a fixed area of a display through the same crop", () => {
+ expect(recorderSource).toContain("let regionX: Double?");
+ expect(recorderSource).toContain("} else if let x = config.regionX,");
+ });
+
it("refreshes the crop and capture display while the window moves or resizes", () => {
expect(recorderSource).toContain(
"guard let display = Self.captureDisplay(for: window.frame",
@@ -95,9 +100,11 @@ describe("ScreenCaptureKitRecorder window capture", () => {
});
});
-
describe("ScreenCaptureKitRecorder first frame timing", () => {
- const callback = recorderSource.slice(recorderSource.indexOf("func stream(_ stream:"), recorderSource.indexOf("func stream(_ stream:") + 5000);
+ const callback = recorderSource.slice(
+ recorderSource.indexOf("func stream(_ stream:"),
+ recorderSource.indexOf("func stream(_ stream:") + 5000,
+ );
it("validates a complete frame and writer readiness before setting time zero", () => {
const clock = callback.indexOf("adjustedPresentationTime(for:");
expect(clock).toBeGreaterThan(callback.indexOf("status == .complete"));
diff --git a/electron/native/ScreenCaptureKitWindowList.swift b/electron/native/ScreenCaptureKitWindowList.swift
index cdb2f575..e0b3a6c2 100644
--- a/electron/native/ScreenCaptureKitWindowList.swift
+++ b/electron/native/ScreenCaptureKitWindowList.swift
@@ -13,6 +13,8 @@ struct WindowListEntry: Codable {
let y: Double
let width: Double
let height: Double
+ /// Process that owns the window, so callers can skip their own windows.
+ let ownerPid: Int32?
}
func normalize(_ value: String?) -> String? {
@@ -38,6 +40,10 @@ let excludedWindowTitles: Set<String> = [
"Wallpaper-",
]
+/// `--z-order` lists windows front to back, for hit-testing what is under a point,
+/// instead of alphabetically for menus.
+let listsInZOrder = CommandLine.arguments.contains("--z-order")
+
// Force CoreGraphics Services initialization before asking ScreenCaptureKit for
// shareable content. Without this, the helper can stall sporadically when run
// as a standalone CLI process from Electron.
@@ -104,7 +110,8 @@ Task {
x: Double(frame.origin.x),
y: Double(frame.origin.y),
width: Double(frame.width),
- height: Double(frame.height)
+ height: Double(frame.height),
+ ownerPid: window.owningApplication?.processID
)
return RawWindowEntry(entry: entry, hasRawTitle: windowTitle != nil, bundleId: bundleId)
@@ -120,7 +127,7 @@ Task {
}
}
- let entries = rawEntries
+ let visibleEntries = rawEntries
.filter { raw in
guard let bid = raw.bundleId else { return true }
if let titled = titledCountByBundle[bid], titled > 0 {
@@ -129,7 +136,22 @@ Task {
return true
}
.map { $0.entry }
- .sorted { lhs, rhs in
+
+ // CGWindowList reports on-screen windows front to back; ScreenCaptureKit's
+ // order is unspecified.
+ var frontToBackRank: [String: Int] = [:]
+ if listsInZOrder {
+ let windowInfo = CGWindowListCopyWindowInfo([.optionOnScreenOnly, .excludeDesktopElements], kCGNullWindowID) as? [[String: Any]] ?? []
+ for (rank, info) in windowInfo.enumerated() {
+ if let number = info[kCGWindowNumber as String] as? Int {
+ frontToBackRank["window:\(number):0"] = rank
+ }
+ }
+ }
+
+ let entries = listsInZOrder
+ ? visibleEntries.sorted { (frontToBackRank[$0.id] ?? Int.max) < (frontToBackRank[$1.id] ?? Int.max) }
+ : visibleEntries.sorted { lhs, rhs in
let lhsApp = lhs.appName ?? lhs.name
let rhsApp = rhs.appName ?? rhs.name
if lhsApp != rhsApp {
diff --git a/electron/preload.ts b/electron/preload.ts
index 2ef032e0..f5e20d94 100644
--- a/electron/preload.ts
+++ b/electron/preload.ts
@@ -532,6 +532,18 @@ contextBridge.exposeInMainWorld("electronAPI", {
showSourceHighlight: (source: ProcessedDesktopSource) => {
return ipcRenderer.invoke("show-source-highlight", source);
},
+ pickCaptureTarget: () => {
+ return ipcRenderer.invoke("pick-capture-target");
+ },
+ completeCapturePick: (pick: CapturePick | null) => {
+ return ipcRenderer.invoke("complete-capture-pick", pick);
+ },
+ getCapturePickerContext: (displayId: number) => {
+ return ipcRenderer.invoke("get-capture-picker-context", displayId);
+ },
+ capturePickerReady: () => {
+ ipcRenderer.send("capture-picker-ready");
+ },
getSelectedSource: () => {
return ipcRenderer.invoke("get-selected-source");
},
diff --git a/electron/windows.ts b/electron/windows.ts
index ddcc1c2d..1b60bd11 100644
--- a/electron/windows.ts
+++ b/electron/windows.ts
@@ -42,6 +42,8 @@ let hudOverlayRecordingActive = false;
let hudCaptureStarting = false;
let hudOverlayWebcamPreviewVisible = false;
let countdownWindow: BrowserWindow | null = null;
+let capturePickerWindows: BrowserWindow[] = [];
+let areaRecordingBorderWindow: BrowserWindow | null = null;
let updateToastWindow: BrowserWindow | null = null;
let hudWasVisibleBeforeUpdateToast = false;
@@ -49,6 +51,8 @@ const HUD_OVERLAY_SETTINGS_FILE = path.join(USER_DATA_PATH, "hud-overlay-setting
const HUD_EDGE_MARGIN_DIP = 16;
const UPDATE_TOAST_WIDTH = 420;
const UPDATE_TOAST_HEIGHT = 172;
+/** Shows a capture picker that never reported ready. */
+const CAPTURE_PICKER_READY_TIMEOUT_MS = 1500;
function getEditorWindowQuery(): Record<string, string> {
const query: Record<string, string> = {
@@ -1172,3 +1176,150 @@ export function closeCountdownWindow(): void {
countdownWindow = null;
}
}
+
+/**
+ * Covers every display with a transparent overlay for picking what to record.
+ * Each overlay renders the `capture-picker` window and reports back over IPC.
+ */
+export function createCapturePickerWindows(onClosed: () => void): BrowserWindow[] {
+ closeCapturePickerWindows();
+ const cursorDisplayId = getScreen().getDisplayNearestPoint(
+ getScreen().getCursorScreenPoint(),
+ ).id;
+ capturePickerWindows = getScreen()
+ .getAllDisplays()
+ .map((display) => {
+ const win = new BrowserWindow({
+ ...display.bounds,
+ frame: false,
+ transparent: true,
+ resizable: false,
+ movable: false,
+ minimizable: false,
+ maximizable: false,
+ fullscreenable: false,
+ alwaysOnTop: true,
+ skipTaskbar: true,
+ hasShadow: false,
+ enableLargerThanScreen: true,
+ show: false,
+ backgroundColor: "#00000000",
+ ...(process.platform === "darwin" ? { type: "panel" as const } : {}),
+ webPreferences: {
+ preload: path.join(electronWindowsDir, "preload.mjs"),
+ nodeIntegration: false,
+ contextIsolation: true,
+ },
+ });
+ // Above the menu bar and the HUD, on every Space and over full-screen apps.
+ win.setAlwaysOnTop(true, "screen-saver");
+ win.setVisibleOnAllWorkspaces(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+ win.setBounds(display.bounds);
+ // The page paints the app's opaque background before React makes it
+ // transparent, so the overlay stays hidden until the picker has painted.
+ let shown = false;
+ const show = () => {
+ if (shown || win.isDestroyed()) return;
+ shown = true;
+ win.show();
+ if (display.id === cursorDisplayId) {
+ app.focus({ steal: true });
+ win.focus();
+ }
+ };
+ win.webContents.ipc.once("capture-picker-ready", show);
+ win.webContents.once("did-finish-load", () => {
+ setTimeout(show, CAPTURE_PICKER_READY_TIMEOUT_MS);
+ });
+ win.on("closed", () => {
+ const wasOpen = capturePickerWindows.includes(win);
+ capturePickerWindows = capturePickerWindows.filter(
+ (candidate) => candidate !== win,
+ );
+ if (wasOpen) onClosed();
+ });
+
+ const query = { windowType: "capture-picker", displayId: String(display.id) };
+ if (VITE_DEV_SERVER_URL) {
+ win.loadURL(`${VITE_DEV_SERVER_URL}?${new URLSearchParams(query).toString()}`);
+ } else {
+ win.loadFile(path.join(RENDERER_DIST, "index.html"), { query });
+ }
+ return win;
+ });
+ return capturePickerWindows;
+}
+
+export function closeCapturePickerWindows(): void {
+ const windows = capturePickerWindows;
+ capturePickerWindows = [];
+ for (const win of windows) {
+ if (!win.isDestroyed()) win.close();
+ }
+}
+
+/**
+ * Outlines the area being recorded. The outline sits just outside the recorded
+ * rectangle and belongs to Recordly, which recordings exclude, so it never shows
+ * up in the video.
+ */
+export function showAreaRecordingBorder(area: {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+}): void {
+ hideAreaRecordingBorder();
+ const outset = 3;
+ const win = new BrowserWindow({
+ x: Math.round(area.x) - outset,
+ y: Math.round(area.y) - outset,
+ width: Math.round(area.width) + outset * 2,
+ height: Math.round(area.height) + outset * 2,
+ frame: false,
+ transparent: true,
+ resizable: false,
+ movable: false,
+ focusable: false,
+ skipTaskbar: true,
+ hasShadow: false,
+ enableLargerThanScreen: true,
+ show: false,
+ backgroundColor: "#00000000",
+ ...(process.platform === "darwin" ? { type: "panel" as const } : {}),
+ webPreferences: { nodeIntegration: false, contextIsolation: true },
+ });
+ win.setIgnoreMouseEvents(true);
+ win.setAlwaysOnTop(true, "screen-saver");
+ win.setVisibleOnAllWorkspaces(true, {
+ visibleOnFullScreen: true,
+ skipTransformProcessType: true,
+ });
+ win.setContentProtection(true);
+ areaRecordingBorderWindow = win;
+ win.on("closed", () => {
+ if (areaRecordingBorderWindow === win) areaRecordingBorderWindow = null;
+ });
+
+ const html = `<!DOCTYPE html><html><head><style>
+html,body{margin:0;height:100%;background:transparent;overflow:hidden}
+div{position:fixed;inset:0;border:2px dashed rgba(255,255,255,.95);box-shadow:0 0 0 1px rgba(0,0,0,.45),inset 0 0 0 1px rgba(0,0,0,.45)}
+</style></head><body><div></div></body></html>`;
+ void win
+ .loadURL(`data:text/html;charset=utf-8,${encodeURIComponent(html)}`)
+ .then(() => {
+ if (!win.isDestroyed()) win.showInactive();
+ })
+ .catch(() => {
+ if (!win.isDestroyed()) win.close();
+ });
+}
+
+export function hideAreaRecordingBorder(): void {
+ const win = areaRecordingBorderWindow;
+ areaRecordingBorderWindow = null;
+ if (win && !win.isDestroyed()) win.close();
+}
diff --git a/src/App.tsx b/src/App.tsx
index 43a83e77..da0899f5 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -20,6 +20,7 @@ const UpdateToastWindow = lazy(() =>
})),
);
const EditorWindow = lazy(() => import("./components/video-editor/EditorWindow"));
+const CapturePicker = lazy(() => import("./components/capture-picker/CapturePicker"));
export default function App() {
const [windowType] = useState(
@@ -35,7 +36,8 @@ export default function App() {
windowType === "hud-overlay" ||
windowType === "source-selector" ||
windowType === "countdown" ||
- windowType === "update-toast"
+ windowType === "update-toast" ||
+ windowType === "capture-picker"
) {
document.body.style.background = "transparent";
document.documentElement.style.background = "transparent";
@@ -78,6 +80,9 @@ export default function App() {
case "editor":
content = <EditorWindow />;
break;
+ case "capture-picker":
+ content = <CapturePicker />;
+ break;
default:
content = (
<div className="flex h-full w-full items-center justify-center bg-editor-bg text-foreground">
diff --git a/src/components/capture-picker/CapturePicker.tsx b/src/components/capture-picker/CapturePicker.tsx
new file mode 100644
index 00000000..ec7f6195
--- /dev/null
+++ b/src/components/capture-picker/CapturePicker.tsx
@@ -0,0 +1,443 @@
+import { useCallback, useEffect, useRef, useState } from "react";
+import type { CSSProperties, PointerEvent as ReactPointerEvent } from "react";
+import { useScopedT } from "@/contexts/I18nContext";
+import {
+ AREA_HANDLES,
+ type AreaHandle,
+ type AreaRect,
+ frontmostAt,
+ MIN_AREA_SIZE,
+ moveAreaRect,
+ normalizeAreaRect,
+ rectContains,
+ resizeAreaRect,
+} from "./areaGeometry";
+
+type PickerWindow = { window: CapturePickerWindow; rect: AreaRect };
+
+/** Something a click picks: the window under the cursor, or the whole screen. */
+type Target =
+ | { kind: "window"; window: CapturePickerWindow; rect: AreaRect }
+ | { kind: "screen"; rect: AreaRect };
+
+type Selection = Target | { kind: "area"; rect: AreaRect };
+
+type Drag =
+ | { kind: "press"; startX: number; startY: number }
+ | { kind: "draw"; originX: number; originY: number }
+ | { kind: "move"; startX: number; startY: number; rect: AreaRect }
+ | { kind: "resize"; handle: AreaHandle; startX: number; startY: number; rect: AreaRect };
+
+const TOOLBAR_HEIGHT = 44;
+const TOOLBAR_GAP = 12;
+/** A press that travels this far draws an area instead of clicking. */
+const DRAG_THRESHOLD = 4;
+const DIM = "rgba(0,0,0,0.38)";
+const HIGHLIGHT = "rgba(10,132,255,0.95)";
+
+const HANDLE_POSITIONS: Record<AreaHandle, { left: string; top: string; cursor: string }> = {
+ nw: { left: "0%", top: "0%", cursor: "nwse-resize" },
+ n: { left: "50%", top: "0%", cursor: "ns-resize" },
+ ne: { left: "100%", top: "0%", cursor: "nesw-resize" },
+ e: { left: "100%", top: "50%", cursor: "ew-resize" },
+ se: { left: "100%", top: "100%", cursor: "nwse-resize" },
+ s: { left: "50%", top: "100%", cursor: "ns-resize" },
+ sw: { left: "0%", top: "100%", cursor: "nesw-resize" },
+ w: { left: "0%", top: "50%", cursor: "ew-resize" },
+};
+
+function viewport() {
+ return { width: window.innerWidth, height: window.innerHeight };
+}
+
+function screenRect(): AreaRect {
+ return { x: 0, y: 0, ...viewport() };
+}
+
+/** Converts a global rectangle to this overlay's coordinates, clipped to it. */
+function toLocal(rect: CaptureArea): AreaRect {
+ return normalizeAreaRect(
+ {
+ x: rect.x - window.screenX,
+ y: rect.y - window.screenY,
+ width: rect.width,
+ height: rect.height,
+ },
+ viewport(),
+ );
+}
+
+function sizeLabel(rect: AreaRect) {
+ return `${Math.round(rect.width)} × ${Math.round(rect.height)}`;
+}
+
+/**
+ * Full-display overlay for picking what to record, one per display. Hovering
+ * highlights the window under the cursor; a click picks it, or the whole screen
+ * over the desktop; a drag draws an area. Moving or resizing a pick turns it into
+ * an area. Enter or double-click records, Escape cancels.
+ */
+export function CapturePicker() {
+ const t = useScopedT("launch");
+ const [displayId] = useState(() =>
+ Number(new URLSearchParams(window.location.search).get("displayId")),
+ );
+ const [selection, setSelection] = useState<Selection | null>(null);
+ const [hover, setHover] = useState<Target | null>(null);
+ const [dragging, setDragging] = useState(false);
+ const dragRef = useRef<Drag | null>(null);
+ const selectionRef = useRef<Selection | null>(null);
+ selectionRef.current = selection;
+ const windowsRef = useRef<PickerWindow[]>([]);
+
+ const targetAt = useCallback((x: number, y: number): Target => {
+ const hit = frontmostAt(windowsRef.current, x, y);
+ return hit
+ ? { kind: "window", window: hit.window, rect: hit.rect }
+ : { kind: "screen", rect: screenRect() };
+ }, []);
+
+ useEffect(() => {
+ let cancelled = false;
+ // Reveal the window only after a frame with the picker's real state.
+ const reveal = () =>
+ requestAnimationFrame(() =>
+ requestAnimationFrame(() => window.electronAPI.capturePickerReady()),
+ );
+ window.electronAPI
+ .getCapturePickerContext(displayId)
+ .then((context) => {
+ if (cancelled) return;
+ windowsRef.current = context.windows
+ .map((entry) => ({ window: entry, rect: toLocal(entry) }))
+ .filter((entry) => entry.rect.width > 0 && entry.rect.height > 0);
+ if (context.lastArea && !selectionRef.current) {
+ setSelection({ kind: "area", rect: toLocal(context.lastArea) });
+ } else if (context.cursor) {
+ const x = context.cursor.x - window.screenX;
+ const y = context.cursor.y - window.screenY;
+ if (rectContains(screenRect(), x, y)) setHover(targetAt(x, y));
+ }
+ })
+ .finally(reveal);
+ return () => {
+ cancelled = true;
+ };
+ }, [displayId, targetAt]);
+
+ const finish = useCallback(
+ (record: boolean | null) => {
+ const current = selectionRef.current;
+ if (record === null || !current) {
+ void window.electronAPI.completeCapturePick(null);
+ return;
+ }
+ if (current.kind === "window") {
+ void window.electronAPI.completeCapturePick({
+ kind: "window",
+ windowId: current.window.id,
+ displayId,
+ record,
+ });
+ return;
+ }
+ if (current.kind === "screen") {
+ void window.electronAPI.completeCapturePick({ kind: "screen", displayId, record });
+ return;
+ }
+ const { rect } = current;
+ if (rect.width < MIN_AREA_SIZE || rect.height < MIN_AREA_SIZE) return;
+ void window.electronAPI.completeCapturePick({
+ kind: "area",
+ x: window.screenX + rect.x,
+ y: window.screenY + rect.y,
+ width: rect.width,
+ height: rect.height,
+ displayId,
+ record,
+ });
+ },
+ [displayId],
+ );
+
+ useEffect(() => {
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.key === "Escape") {
+ event.preventDefault();
+ finish(null);
+ } else if (event.key === "Enter") {
+ event.preventDefault();
+ finish(true);
+ }
+ };
+ window.addEventListener("keydown", onKeyDown);
+ return () => window.removeEventListener("keydown", onKeyDown);
+ }, [finish]);
+
+ const handlePointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
+ if (event.button !== 0) return;
+ const target = event.target as HTMLElement;
+ if (target.closest("[data-picker-toolbar]")) return;
+ event.currentTarget.setPointerCapture(event.pointerId);
+ const handle = target.closest<HTMLElement>("[data-picker-handle]")?.dataset.pickerHandle as
+ | AreaHandle
+ | undefined;
+ const current = selectionRef.current;
+ if (handle && current) {
+ dragRef.current = {
+ kind: "resize",
+ handle,
+ startX: event.clientX,
+ startY: event.clientY,
+ rect: current.rect,
+ };
+ } else if (current && rectContains(current.rect, event.clientX, event.clientY)) {
+ dragRef.current = {
+ kind: "move",
+ startX: event.clientX,
+ startY: event.clientY,
+ rect: current.rect,
+ };
+ } else {
+ dragRef.current = { kind: "press", startX: event.clientX, startY: event.clientY };
+ }
+ };
+
+ const handlePointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {
+ const drag = dragRef.current;
+ const bounds = viewport();
+ if (!drag) {
+ const current = selectionRef.current;
+ setHover(
+ current && rectContains(current.rect, event.clientX, event.clientY)
+ ? null
+ : targetAt(event.clientX, event.clientY),
+ );
+ return;
+ }
+
+ if (drag.kind === "press") {
+ const distance = Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY);
+ if (distance < DRAG_THRESHOLD) return;
+ dragRef.current = { kind: "draw", originX: drag.startX, originY: drag.startY };
+ setHover(null);
+ }
+
+ const active = dragRef.current;
+ if (!active || active.kind === "press") return;
+ if (active.kind === "draw") {
+ setDragging(true);
+ setSelection({
+ kind: "area",
+ rect: normalizeAreaRect(
+ {
+ x: active.originX,
+ y: active.originY,
+ width: event.clientX - active.originX,
+ height: event.clientY - active.originY,
+ },
+ bounds,
+ ),
+ });
+ return;
+ }
+
+ const dx = event.clientX - active.startX;
+ const dy = event.clientY - active.startY;
+ // A click inside a picked window keeps it; only real movement turns it into an area.
+ if (!dragging && Math.hypot(dx, dy) < DRAG_THRESHOLD / 2) return;
+ setDragging(true);
+ setSelection({
+ kind: "area",
+ rect:
+ active.kind === "move"
+ ? moveAreaRect(active.rect, dx, dy, bounds)
+ : resizeAreaRect(active.rect, active.handle, dx, dy, bounds),
+ });
+ };
+
+ const handlePointerUp = (event: ReactPointerEvent<HTMLDivElement>) => {
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) {
+ event.currentTarget.releasePointerCapture(event.pointerId);
+ }
+ const drag = dragRef.current;
+ dragRef.current = null;
+ setDragging(false);
+ if (drag?.kind === "press") {
+ // A click picks the window under the cursor, or the screen over the desktop.
+ setSelection(targetAt(drag.startX, drag.startY));
+ setHover(null);
+ return;
+ }
+ const current = selectionRef.current;
+ if (
+ drag?.kind === "draw" &&
+ current &&
+ (current.rect.width < DRAG_THRESHOLD || current.rect.height < DRAG_THRESHOLD)
+ ) {
+ setSelection(null);
+ }
+ };
+
+ const describe = (pick: Selection) =>
+ pick.kind === "window"
+ ? [pick.window.appName, pick.window.title].filter(Boolean).join(" — ")
+ : pick.kind === "screen"
+ ? t("capturePicker.entireScreen", "Entire screen")
+ : "";
+
+ const tooSmall =
+ selection?.kind === "area" &&
+ (selection.rect.width < MIN_AREA_SIZE || selection.rect.height < MIN_AREA_SIZE);
+ const rect = selection?.rect ?? null;
+ const toolbarTop = rect
+ ? rect.y + rect.height + TOOLBAR_GAP + TOOLBAR_HEIGHT <= window.innerHeight
+ ? rect.y + rect.height + TOOLBAR_GAP
+ : rect.y - TOOLBAR_GAP - TOOLBAR_HEIGHT >= 0
+ ? rect.y - TOOLBAR_GAP - TOOLBAR_HEIGHT
+ : rect.y + rect.height - TOOLBAR_HEIGHT - TOOLBAR_GAP
+ : 0;
+ const placeLabel = (target: AreaRect): CSSProperties =>
+ target.y >= 30 ? { top: -26, left: 0 } : { top: 6, left: 6 };
+
+ return (
+ <div
+ className="fixed inset-0 select-none overflow-hidden"
+ style={{
+ cursor: "crosshair",
+ background: selection || hover ? "transparent" : DIM,
+ }}
+ onPointerDown={handlePointerDown}
+ onPointerMove={handlePointerMove}
+ onPointerUp={handlePointerUp}
+ onPointerCancel={handlePointerUp}
+ onPointerLeave={() => {
+ if (!dragRef.current) setHover(null);
+ }}
+ onDoubleClick={(event) => {
+ const current = selectionRef.current;
+ if (current && rectContains(current.rect, event.clientX, event.clientY))
+ finish(true);
+ }}
+ onContextMenu={(event) => {
+ event.preventDefault();
+ finish(null);
+ }}
+ >
+ {hover && !dragging && (
+ <div
+ className="pointer-events-none absolute"
+ style={{
+ left: hover.rect.x,
+ top: hover.rect.y,
+ width: hover.rect.width,
+ height: hover.rect.height,
+ background: selection ? "transparent" : "rgba(10,132,255,0.16)",
+ boxShadow: selection
+ ? `inset 0 0 0 2px ${HIGHLIGHT}`
+ : `inset 0 0 0 2px ${HIGHLIGHT}, 0 0 0 100vmax ${DIM}`,
+ }}
+ >
+ <div
+ className="absolute max-w-[min(520px,90%)] truncate whitespace-nowrap rounded-md px-2 py-0.5 text-[11px] font-medium text-white"
+ style={{ ...placeLabel(hover.rect), background: HIGHLIGHT }}
+ >
+ {describe(hover)} · {sizeLabel(hover.rect)}
+ </div>
+ </div>
+ )}
+
+ {selection === null ? (
+ <div className="pointer-events-none absolute inset-x-0 bottom-24 flex justify-center">
+ <div className="rounded-full bg-[rgba(18,18,22,0.88)] px-4 py-2 text-[13px] font-medium text-white/90 shadow-lg ring-1 ring-white/10 backdrop-blur-md">
+ {t(
+ "capturePicker.hint",
+ "Click a window or the desktop, or drag an area · Esc to cancel",
+ )}
+ </div>
+ </div>
+ ) : (
+ <>
+ <div
+ className="absolute"
+ style={{
+ left: selection.rect.x,
+ top: selection.rect.y,
+ width: selection.rect.width,
+ height: selection.rect.height,
+ cursor: dragging ? "grabbing" : "move",
+ boxShadow: `0 0 0 100vmax ${DIM}`,
+ outline: "1px solid rgba(255,255,255,0.95)",
+ outlineOffset: selection.kind === "screen" ? -1 : 0,
+ }}
+ >
+ {AREA_HANDLES.map((handle) => (
+ <div
+ key={handle}
+ data-picker-handle={handle}
+ className="absolute h-[11px] w-[11px] rounded-full border border-black/30 bg-white shadow"
+ style={{
+ left: HANDLE_POSITIONS[handle].left,
+ top: HANDLE_POSITIONS[handle].top,
+ transform: "translate(-50%, -50%)",
+ cursor: HANDLE_POSITIONS[handle].cursor,
+ }}
+ />
+ ))}
+ <div
+ className="pointer-events-none absolute max-w-[min(520px,90%)] truncate whitespace-nowrap rounded-md bg-[rgba(18,18,22,0.88)] px-2 py-0.5 text-[11px] font-medium tabular-nums text-white/90"
+ style={placeLabel(selection.rect)}
+ >
+ {selection.kind === "area"
+ ? sizeLabel(selection.rect)
+ : `${describe(selection)} · ${sizeLabel(selection.rect)}`}
+ </div>
+ </div>
+ {!dragging && (
+ <div
+ data-picker-toolbar
+ className="absolute flex items-center gap-1 rounded-full bg-[rgba(18,18,22,0.92)] p-1 text-[13px] font-medium text-white shadow-xl ring-1 ring-white/10 backdrop-blur-md"
+ style={{
+ top: toolbarTop,
+ left: Math.min(
+ Math.max(selection.rect.x + selection.rect.width / 2, 160),
+ window.innerWidth - 160,
+ ),
+ height: TOOLBAR_HEIGHT,
+ transform: "translateX(-50%)",
+ cursor: "default",
+ }}
+ >
+ <button
+ type="button"
+ className="h-full rounded-full px-4 text-white/80 hover:bg-white/10 hover:text-white"
+ onClick={() => finish(null)}
+ >
+ {t("capturePicker.cancel", "Cancel")}
+ </button>
+ <button
+ type="button"
+ disabled={tooSmall}
+ className="h-full rounded-full px-4 text-white/80 hover:bg-white/10 hover:text-white disabled:opacity-40"
+ onClick={() => finish(false)}
+ >
+ {t("capturePicker.select", "Select")}
+ </button>
+ <button
+ type="button"
+ disabled={tooSmall}
+ className="flex h-full items-center gap-2 rounded-full bg-[#e5484d] px-4 text-white hover:bg-[#ec5d62] disabled:opacity-40"
+ onClick={() => finish(true)}
+ >
+ <span className="h-2.5 w-2.5 rounded-full bg-white" />
+ {t("capturePicker.record", "Record")}
+ </button>
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ );
+}
+
+export default CapturePicker;
diff --git a/src/components/capture-picker/areaGeometry.test.ts b/src/components/capture-picker/areaGeometry.test.ts
new file mode 100644
index 00000000..e3925834
--- /dev/null
+++ b/src/components/capture-picker/areaGeometry.test.ts
@@ -0,0 +1,68 @@
+import { describe, expect, it } from "vitest";
+import { frontmostAt, moveAreaRect, normalizeAreaRect, resizeAreaRect } from "./areaGeometry";
+
+const bounds = { width: 1000, height: 800 };
+
+describe("area geometry", () => {
+ it("normalizes drags that go up or left", () => {
+ expect(normalizeAreaRect({ x: 300, y: 200, width: -100, height: -50 }, bounds)).toEqual({
+ x: 200,
+ y: 150,
+ width: 100,
+ height: 50,
+ });
+ });
+
+ it("clamps rectangles to the overlay", () => {
+ expect(normalizeAreaRect({ x: 900, y: 700, width: 300, height: 300 }, bounds)).toEqual({
+ x: 900,
+ y: 700,
+ width: 100,
+ height: 100,
+ });
+ expect(
+ moveAreaRect({ x: 100, y: 100, width: 200, height: 200 }, 2000, -500, bounds),
+ ).toEqual({
+ x: 800,
+ y: 0,
+ width: 200,
+ height: 200,
+ });
+ });
+
+ it("resizes from an edge or corner and flips past the opposite edge", () => {
+ const rect = { x: 100, y: 100, width: 200, height: 100 };
+ expect(resizeAreaRect(rect, "se", 50, 20, bounds)).toEqual({
+ x: 100,
+ y: 100,
+ width: 250,
+ height: 120,
+ });
+ expect(resizeAreaRect(rect, "w", 300, 0, bounds)).toEqual({
+ x: 300,
+ y: 100,
+ width: 100,
+ height: 100,
+ });
+ expect(resizeAreaRect(rect, "n", 0, -150, bounds)).toEqual({
+ x: 100,
+ y: 0,
+ width: 200,
+ height: 200,
+ });
+ });
+});
+
+describe("frontmostAt", () => {
+ const back = { id: "back", rect: { x: 0, y: 0, width: 800, height: 600 } };
+ const front = { id: "front", rect: { x: 100, y: 100, width: 200, height: 200 } };
+
+ it("finds the frontmost window under a point", () => {
+ expect(frontmostAt([front, back], 150, 150)?.id).toBe("front");
+ expect(frontmostAt([front, back], 500, 500)?.id).toBe("back");
+ });
+
+ it("finds nothing over the desktop", () => {
+ expect(frontmostAt([front, back], 900, 700)).toBeNull();
+ });
+});
diff --git a/src/components/capture-picker/areaGeometry.ts b/src/components/capture-picker/areaGeometry.ts
new file mode 100644
index 00000000..c0086fac
--- /dev/null
+++ b/src/components/capture-picker/areaGeometry.ts
@@ -0,0 +1,73 @@
+export type AreaRect = { x: number; y: number; width: number; height: number };
+export type AreaHandle = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
+
+export const AREA_HANDLES: AreaHandle[] = ["nw", "n", "ne", "e", "se", "s", "sw", "w"];
+/** Matches MIN_CAPTURE_AREA_SIZE in electron/ipc/sourceArea.ts. */
+export const MIN_AREA_SIZE = 32;
+
+type Bounds = { width: number; height: number };
+
+function clamp(value: number, min: number, max: number) {
+ return Math.min(max, Math.max(min, value));
+}
+
+/**
+ * Puts the origin at the top-left corner when a drag went up or left, and keeps
+ * the rectangle inside the overlay.
+ */
+export function normalizeAreaRect(rect: AreaRect, bounds: Bounds): AreaRect {
+ const left = clamp(Math.min(rect.x, rect.x + rect.width), 0, bounds.width);
+ const right = clamp(Math.max(rect.x, rect.x + rect.width), 0, bounds.width);
+ const top = clamp(Math.min(rect.y, rect.y + rect.height), 0, bounds.height);
+ const bottom = clamp(Math.max(rect.y, rect.y + rect.height), 0, bounds.height);
+ return {
+ x: Math.round(left),
+ y: Math.round(top),
+ width: Math.round(right - left),
+ height: Math.round(bottom - top),
+ };
+}
+
+/** Moves the rectangle by a drag offset without letting it leave the overlay. */
+export function moveAreaRect(rect: AreaRect, dx: number, dy: number, bounds: Bounds): AreaRect {
+ return {
+ ...rect,
+ x: clamp(Math.round(rect.x + dx), 0, Math.max(0, bounds.width - rect.width)),
+ y: clamp(Math.round(rect.y + dy), 0, Math.max(0, bounds.height - rect.height)),
+ };
+}
+
+/** Drags one edge or corner; dragging past the opposite edge flips the rectangle. */
+export function resizeAreaRect(
+ rect: AreaRect,
+ handle: AreaHandle,
+ dx: number,
+ dy: number,
+ bounds: Bounds,
+): AreaRect {
+ let left = rect.x;
+ let top = rect.y;
+ let right = rect.x + rect.width;
+ let bottom = rect.y + rect.height;
+ if (handle.includes("w")) left += dx;
+ if (handle.includes("e")) right += dx;
+ if (handle.includes("n")) top += dy;
+ if (handle.includes("s")) bottom += dy;
+ return normalizeAreaRect(
+ { x: left, y: top, width: right - left, height: bottom - top },
+ bounds,
+ );
+}
+
+export function rectContains(rect: AreaRect, x: number, y: number): boolean {
+ return x >= rect.x && x < rect.x + rect.width && y >= rect.y && y < rect.y + rect.height;
+}
+
+/** The frontmost entry under the point, from a list ordered front to back. */
+export function frontmostAt<T extends { rect: AreaRect }>(
+ entries: T[],
+ x: number,
+ y: number,
+): T | null {
+ return entries.find((entry) => rectContains(entry.rect, x, y)) ?? null;
+}
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index 634fec26..e83e6cfb 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -186,6 +186,16 @@ function LaunchWindowContent() {
ease: [0.22, 1, 0.36, 1] as const,
};
+ const handlePickOnScreen = async () => {
+ const result = await window.electronAPI.pickCaptureTarget();
+ if (!result.success) return;
+ if (result.record) {
+ toggleRecording();
+ } else if (result.source) {
+ void window.electronAPI.showSourceHighlight?.(result.source);
+ }
+ };
+
const openHome = () => {
localStorage.setItem("recordly.open-dashboard", String(Date.now()));
void window.electronAPI.showProjectDashboard();
@@ -224,6 +234,7 @@ function LaunchWindowContent() {
<SourcePopover
selectedSource={selectedSource}
onSourceSelect={handleSourceSelect}
+ onPickOnScreen={platform === "darwin" ? handlePickOnScreen : undefined}
onOpen={beginInteractiveHudAction}
trigger={
<Button
diff --git a/src/components/launch/SourceSelector.tsx b/src/components/launch/SourceSelector.tsx
index c5906697..fcc865bb 100644
--- a/src/components/launch/SourceSelector.tsx
+++ b/src/components/launch/SourceSelector.tsx
@@ -1,5 +1,5 @@
import { ToggleButton } from "@heroui/react";
-import { AppWindowIcon, CaretUpIcon, MonitorIcon } from "@/components/ui/icons";
+import { AppWindowIcon, CaretUpIcon, Crop, MonitorIcon } from "@/components/ui/icons";
import * as React from "react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Button } from "@/components/ui/button";
@@ -28,6 +28,8 @@ interface SourceSelectorProps {
loading?: boolean;
/** Callback when a source is selected */
onSourceSelect?: (source: DesktopSource) => void;
+ /** Opens the on-screen picker for an area or window; omitted where unsupported */
+ onPickOnScreen?: () => void;
/** Callback to fetch sources */
onFetchSources?: () => Promise<void>;
/** Whether the popover is open */
@@ -47,9 +49,15 @@ export const SourceSelectorContent = ({
selectedSource = "Screen",
loading = false,
onSourceSelect = () => undefined,
+ onPickOnScreen,
}: Pick<
SourceSelectorProps,
- "screenSources" | "windowSources" | "selectedSource" | "loading" | "onSourceSelect"
+ | "screenSources"
+ | "windowSources"
+ | "selectedSource"
+ | "loading"
+ | "onSourceSelect"
+ | "onPickOnScreen"
>) => {
const t = useScopedT("launch");
const renderSourceItem = (source: DesktopSource, index: number) => {
@@ -101,58 +109,91 @@ export const SourceSelectorContent = ({
};
const hasAnySources = screenSources.length > 0 || windowSources.length > 0;
+ const pickOnScreenItem = onPickOnScreen ? (
+ <div className="p-2 pb-0">
+ <ToggleButton
+ variant="ghost"
+ isSelected={selectedSource.startsWith("Area ")}
+ className={cn(
+ "source-selector-item group min-h-[46px] w-full px-3 py-2.5 text-left flex items-center justify-start gap-3",
+ selectedSource.startsWith("Area ") && "source-selector-item-selected",
+ )}
+ onClick={onPickOnScreen}
+ >
+ <div className="source-selector-thumb-fallback w-12 h-8 rounded-[8px] flex items-center justify-center flex-shrink-0">
+ <Crop className="w-5 h-5 source-selector-muted" />
+ </div>
+ <div className="flex-1 min-w-0 flex flex-col items-start text-left">
+ <div className="text-sm font-medium source-selector-text w-full">
+ {t("recording.pickOnScreen", "Select area or window")}
+ </div>
+ <div className="text-xs source-selector-subtle truncate w-full text-left">
+ {selectedSource.startsWith("Area ")
+ ? selectedSource
+ : t("recording.pickOnScreenHint", "Drag an area, or click a window")}
+ </div>
+ </div>
+ </ToggleButton>
+ </div>
+ ) : null;
if (loading && !hasAnySources) {
return (
- <div className="flex items-center justify-center py-8">
- <div className="animate-spin rounded-full h-5 w-5 border-b-2 source-selector-accent-border" />
- </div>
+ <>
+ {pickOnScreenItem}
+ <div className="flex items-center justify-center py-8">
+ <div className="animate-spin rounded-full h-5 w-5 border-b-2 source-selector-accent-border" />
+ </div>
+ </>
);
}
return (
- <div className="max-h-[320px] overflow-y-auto overflow-x-hidden p-2 source-selector-scroll">
- {hasAnySources ? (
- <>
- {screenSources.length > 0 ? (
- <div className="space-y-1">
- <div className="px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.08em] source-selector-label flex items-center gap-2">
- {t("recording.screens")}
- <span
- className={cn(
- "normal-case tracking-normal text-[10px] source-selector-muted transition-opacity duration-150",
- loading ? "opacity-100" : "opacity-0",
+ <>
+ {pickOnScreenItem}
+ <div className="max-h-[320px] overflow-y-auto overflow-x-hidden p-2 source-selector-scroll">
+ {hasAnySources ? (
+ <>
+ {screenSources.length > 0 ? (
+ <div className="space-y-1">
+ <div className="px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.08em] source-selector-label flex items-center gap-2">
+ {t("recording.screens")}
+ <span
+ className={cn(
+ "normal-case tracking-normal text-[10px] source-selector-muted transition-opacity duration-150",
+ loading ? "opacity-100" : "opacity-0",
+ )}
+ >
+ {t("common.loading", "Refreshing...")}
+ </span>
+ </div>
+ <div className="space-y-0.5">
+ {screenSources.map((source, index) =>
+ renderSourceItem(source, index),
)}
- >
- {t("common.loading", "Refreshing...")}
- </span>
- </div>
- <div className="space-y-0.5">
- {screenSources.map((source, index) =>
- renderSourceItem(source, index),
- )}
+ </div>
</div>
- </div>
- ) : null}
- {windowSources.length > 0 ? (
- <div className="space-y-1">
- <div className="px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.08em] source-selector-label">
- {t("recording.windows")}
- </div>
- <div className="space-y-0.5">
- {windowSources.map((source, index) =>
- renderSourceItem(source, index),
- )}
+ ) : null}
+ {windowSources.length > 0 ? (
+ <div className="space-y-1">
+ <div className="px-3 py-2 text-[10px] font-semibold uppercase tracking-[0.08em] source-selector-label">
+ {t("recording.windows")}
+ </div>
+ <div className="space-y-0.5">
+ {windowSources.map((source, index) =>
+ renderSourceItem(source, index),
+ )}
+ </div>
</div>
- </div>
- ) : null}
- </>
- ) : (
- <div className="text-center py-8 text-sm source-selector-muted">
- {t("recording.noSourcesFound")}
- </div>
- )}
- </div>
+ ) : null}
+ </>
+ ) : (
+ <div className="text-center py-8 text-sm source-selector-muted">
+ {t("recording.noSourcesFound")}
+ </div>
+ )}
+ </div>
+ </>
);
};
@@ -166,6 +207,7 @@ export const SourceSelector = React.memo(function SourceSelector({
selectedSource: propsSelectedSource,
loading: propsLoading,
onSourceSelect: propsOnSourceSelect,
+ onPickOnScreen,
onFetchSources: propsOnFetchSources,
open: propsOpen,
onOpenChange: propsOnOpenChange,
@@ -340,6 +382,7 @@ export const SourceSelector = React.memo(function SourceSelector({
selectedSource={selectedSource}
loading={loading}
onSourceSelect={onSourceSelect}
+ onPickOnScreen={onPickOnScreen}
/>
</PopoverContent>
</Popover>
diff --git a/src/components/launch/popovers/SourcePopover.tsx b/src/components/launch/popovers/SourcePopover.tsx
index 5459fae1..f4b56a0f 100644
--- a/src/components/launch/popovers/SourcePopover.tsx
+++ b/src/components/launch/popovers/SourcePopover.tsx
@@ -14,11 +14,14 @@ export function SourcePopover({
trigger,
selectedSource,
onSourceSelect,
+ onPickOnScreen,
onOpen,
}: {
trigger: ReactNode;
selectedSource: string;
onSourceSelect: (source: DesktopSource) => Promise<void> | void;
+ /** Opens the on-screen picker for an area or window; omitted where unsupported */
+ onPickOnScreen?: () => Promise<void> | void;
onOpen?: () => void;
}) {
const { isOpen, requestOpen, requestClose } = useLaunchPopoverCoordinator();
@@ -60,6 +63,14 @@ export function SourcePopover({
console.error("Failed to select source:", error);
}
}}
+ onPickOnScreen={
+ onPickOnScreen
+ ? () => {
+ requestClose(POPOVER_ID);
+ void onPickOnScreen();
+ }
+ : undefined
+ }
onFetchSources={fetchSources}
open={open}
onOpenChange={(nextOpen) => {
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index dc6b7032..70663d09 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -1156,7 +1156,8 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
const useNativeMacScreenCapture =
platform === "darwin" &&
(selectedSource.id?.startsWith("screen:") ||
- selectedSource.id?.startsWith("window:")) &&
+ selectedSource.id?.startsWith("window:") ||
+ selectedSource.id?.startsWith("area:")) &&
typeof window.electronAPI.startNativeScreenRecording === "function";
let useNativeWindowsCapture = false;
diff --git a/src/main.tsx b/src/main.tsx
index d79a1d3d..9dc270b0 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -10,6 +10,12 @@ installFeedbackDiagnostics();
document.documentElement.dataset.platform = /mac/i.test(navigator.platform) ? "macos" : "other";
+// The capture picker covers whole displays, so it must never paint the app background.
+if (new URLSearchParams(window.location.search).get("windowType") === "capture-picker") {
+ document.documentElement.style.background = "transparent";
+ document.body.style.background = "transparent";
+}
+
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<ThemeProvider>
diff --git a/tests/ui/capture-picker.spec.ts b/tests/ui/capture-picker.spec.ts
new file mode 100644
index 00000000..8e32093f
--- /dev/null
+++ b/tests/ui/capture-picker.spec.ts
@@ -0,0 +1,103 @@
+import { expect, type Page, test } from "@playwright/test";
+import { installDesktopBridge } from "./bridge";
+
+// Front to back: Notes overlaps the left part of Safari.
+const windows = [
+ {
+ id: "window:101:0",
+ appName: "Notes",
+ title: "Launch checklist",
+ display_id: "1",
+ x: 160,
+ y: 140,
+ width: 620,
+ height: 460,
+ },
+ {
+ id: "window:102:0",
+ appName: "Safari",
+ title: "Release notes",
+ display_id: "1",
+ x: 520,
+ y: 220,
+ width: 760,
+ height: 560,
+ },
+];
+
+async function openPicker(page: Page) {
+ await installDesktopBridge(page);
+ await page.addInitScript((pickerWindows) => {
+ const api = (window as unknown as { electronAPI: Record<string, unknown> }).electronAPI;
+ Object.assign(api, {
+ getCapturePickerContext: async () => ({
+ displayBounds: { x: 0, y: 0, width: 1440, height: 1000 },
+ lastArea: null,
+ windows: pickerWindows,
+ cursor: null,
+ }),
+ completeCapturePick: async (pick: unknown) => {
+ document.documentElement.dataset.pick = JSON.stringify(pick);
+ },
+ capturePickerReady: () => {
+ document.documentElement.dataset.pickerReady = "true";
+ },
+ });
+ }, windows);
+ await page.goto("/?windowType=capture-picker&displayId=1");
+ await expect(page.locator("html")).toHaveAttribute("data-picker-ready", "true");
+}
+
+async function pick(page: Page) {
+ const value = await page.locator("html").getAttribute("data-pick");
+ return value ? JSON.parse(value) : undefined;
+}
+
+test("hovering highlights the frontmost window and a click picks it", async ({ page }) => {
+ await openPicker(page);
+ await page.mouse.move(600, 300);
+ await expect(page.getByText("Notes — Launch checklist · 620 × 460")).toBeVisible();
+
+ await page.mouse.click(600, 300);
+ await page.getByRole("button", { name: "Record" }).click();
+ expect(await pick(page)).toEqual({
+ kind: "window",
+ windowId: "window:101:0",
+ displayId: 1,
+ record: true,
+ });
+});
+
+test("a click on the desktop picks the whole screen", async ({ page }) => {
+ await openPicker(page);
+ await page.mouse.move(1380, 60);
+ await expect(page.getByText("Entire screen · 1440 × 1000")).toBeVisible();
+
+ await page.mouse.click(1380, 60);
+ await page.getByRole("button", { name: "Select" }).click();
+ expect(await pick(page)).toEqual({ kind: "screen", displayId: 1, record: false });
+});
+
+test("a drag draws an area", async ({ page }) => {
+ await openPicker(page);
+ await page.mouse.move(300, 200);
+ await page.mouse.down();
+ await page.mouse.move(700, 450, { steps: 8 });
+ await page.mouse.up();
+ await expect(page.getByText("400 × 250")).toBeVisible();
+
+ await page.keyboard.press("Enter");
+ expect(await pick(page)).toMatchObject({
+ kind: "area",
+ width: 400,
+ height: 250,
+ displayId: 1,
+ record: true,
+ });
+});
+
+test("Escape cancels", async ({ page }) => {
+ await openPicker(page);
+ await page.keyboard.press("Escape");
+ expect(await pick(page)).toBeNull();
+});