Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix: rebase cursor samples on capture bounds, use window bounds for picked windows

Matt Van Horn14c0b4793e33
diff --git a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
index a8d916a59..c59f5ff8d 100644
--- a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
+++ b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
@@ -234,6 +234,8 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
private readyTimer: NodeJS.Timeout | null = null;
private previousLeftButtonDown = false;
private consecutiveOutsideSamples = 0;
+ private screenPoints: Array<{ x: number; y: number }> = [];
+ private boundsOverride: Rectangle | null = null;
// Hide only after this many consecutive out-of-bounds samples (~100ms at 33ms interval).
// Fast swipes that briefly exit the display are clipped by clip-path instead of disappearing.
private static readonly OUTSIDE_HIDE_THRESHOLD = 3;
@@ -242,6 +244,8 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
async start(): Promise<void> {
this.samples = [];
+ this.screenPoints = [];
+ this.boundsOverride = null;
this.assets.clear();
this.lineBuffer = "";
this.startTimeMs = this.options.startTimeMs ?? Date.now();
@@ -330,6 +334,20 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
};
}
+ updateCaptureBounds(bounds: Rectangle): void {
+ this.boundsOverride = bounds;
+ const width = Math.max(1, bounds.width);
+ const height = Math.max(1, bounds.height);
+ for (let index = 0; index < this.samples.length; index++) {
+ const point = this.screenPoints[index];
+ if (!point) {
+ continue;
+ }
+ this.samples[index].cx = clamp((point.x - bounds.x) / width, 0, 1);
+ this.samples[index].cy = clamp((point.y - bounds.y) / height, 0, 1);
+ }
+ }
+
private startPositionOnlyFallback() {
this.captureSample(Date.now(), null, null, false, false, false);
this.fallbackInterval = setInterval(() => {
@@ -408,7 +426,10 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
leftButtonReleased: boolean,
) {
const cursor = screen.getCursorScreenPoint();
- const bounds = this.options.getDisplayBounds() ?? screen.getDisplayNearestPoint(cursor).bounds;
+ const bounds =
+ this.boundsOverride ??
+ this.options.getDisplayBounds() ??
+ screen.getDisplayNearestPoint(cursor).bounds;
const width = Math.max(1, bounds.width);
const height = Math.max(1, bounds.height);
const normalizedX = (cursor.x - bounds.x) / width;
@@ -442,9 +463,11 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
...(assetId ? { assetId } : {}),
...(cursorType ? { cursorType } : {}),
});
+ this.screenPoints.push({ x: cursor.x, y: cursor.y });
if (this.samples.length > this.options.maxSamples) {
this.samples.shift();
+ this.screenPoints.shift();
}
}
diff --git a/electron/native-bridge/cursor/recording/session.ts b/electron/native-bridge/cursor/recording/session.ts
index 9cebe9f4c..db4469f4b 100644
--- a/electron/native-bridge/cursor/recording/session.ts
+++ b/electron/native-bridge/cursor/recording/session.ts
@@ -1,6 +1,8 @@
+import type { Rectangle } from "electron";
import type { CursorRecordingData } from "../../../../src/native/contracts";
export interface CursorRecordingSession {
start(): Promise<void>;
stop(): Promise<CursorRecordingData>;
+ updateCaptureBounds?(bounds: Rectangle): void;
}
diff --git a/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift b/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift
index efcd1512c..4d47d274d 100644
--- a/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift
+++ b/electron/native/screencapturekit/Sources/OpenScreenScreenCaptureKitHelper/ScreenCaptureRecorder.swift
@@ -119,9 +119,7 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {
let filter: SCContentFilter
let width: Int
let height: Int
- // Global frame (points, top-left origin) of the captured region. The cursor is
- // normalised against this, so it is the filter's content rect — the same
- // rectangle the output buffer is sized from — wherever that exists.
+ // Global frame (points, top-left origin) the cursor is normalised against.
let captureFrame: CGRect
}
@@ -1182,23 +1180,33 @@ final class ScreenCaptureRecorder: NSObject, SCStreamOutput, SCStreamDelegate {
return status == .complete
}
- /// On-screen rectangle of the pixels this filter will rasterise, in points.
- ///
- /// `captureSize` already takes its dimensions from `contentRect`: that product is
- /// the buffer ScreenCaptureKit fills. The cursor is a global Electron point
- /// normalised against a frame reported separately, so the frame has to be that
- /// same rectangle, origin included. `SCWindow.frame` and the frame stored with a
- /// system-picker choice describe the window, which on macOS 26 sits below the
- /// pixels the stream writes; the pointer then draws above the click (#1130).
- /// No constant is added here to compensate. `contentRect` is screen points and
- /// exists from macOS 14. On 13 the source frame is the only measurement available.
+ /// One-window filters use `kCGWindowBounds`: a picker window's `contentRect` sits
+ /// below the pixels the cursor is on (#1130). Displays keep `contentRect`.
private func captureContentFrame(for filter: SCContentFilter, fallback: CGRect) -> CGRect {
- guard #available(macOS 14.0, *) else {
- return fallback
+ if #available(macOS 15.2, *),
+ filter.includedWindows.count == 1,
+ let windowID = filter.includedWindows.first?.windowID,
+ let bounds = Self.cgWindowBounds(windowID) {
+ return bounds
}
+ guard #available(macOS 14.0, *) else { return fallback }
return filter.contentRect
}
+ private static func cgWindowBounds(_ windowID: UInt32) -> CGRect? {
+ guard let entries = CGWindowListCopyWindowInfo(.optionIncludingWindow, CGWindowID(windowID))
+ as? [[String: Any]],
+ let raw = entries.first(where: {
+ ($0[kCGWindowNumber as String] as? NSNumber)?.uint32Value == windowID
+ })?[kCGWindowBounds as String] as? NSDictionary
+ else { return nil }
+ var rect = CGRect.null
+ guard CGRectMakeWithDictionaryRepresentation(raw, &rect), rect.width > 0, rect.height > 0 else {
+ return nil
+ }
+ return rect
+ }
+
/// Output-buffer size for a filter, capped by the resolution the app asked for.
///
/// The filter is asked first, because `contentRect × pointPixelScale` is by definition the