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: recompute cursor visibility when rebasing on capture bounds

EtienneLescot5bb1b3fb5dfb
diff --git a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.test.ts b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.test.ts
index 960cfd906..9f0274a36 100644
--- a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.test.ts
+++ b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.test.ts
@@ -187,6 +187,30 @@ describe("MacNativeCursorRecordingSession capture bounds", () => {
});
});
+ it("brings back samples hidden against the seeded frame once the real bounds arrive", async () => {
+ // Above the seeded window frame, so three samples cross the hide threshold;
+ // the helper's frame then starts higher and contains them.
+ mocks.cursor = { x: 700, y: 60 };
+ const session = new MacNativeCursorRecordingSession({
+ getDisplayBounds: () => WINDOW_BOUNDS,
+ maxSamples: 20,
+ sampleIntervalMs: 33,
+ startTimeMs: 1_000,
+ });
+ const pending = session.start();
+ await Promise.resolve();
+ helper.emitEvent({ type: "ready", timestampMs: 1_000 });
+ await pending;
+ helper.emitEvent({ type: "sample", timestampMs: 1_100 });
+ helper.emitEvent({ type: "sample", timestampMs: 1_133 });
+ helper.emitEvent({ type: "sample", timestampMs: 1_166 });
+
+ session.updateCaptureBounds({ x: 200, y: 50, width: 1000, height: 850 });
+
+ const data = await session.stop();
+ expect(data.samples.slice(0, 3).map((sample) => sample.visible)).toEqual([true, true, true]);
+ });
+
it("falls back to the display under the pointer when no capture bounds exist", async () => {
// No helper on disk: position-only sampling, and nothing has reported a capture rect.
mocks.accessSync.mockImplementation(() => {
diff --git a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
index c59f5ff8d..6ab5d2dd5 100644
--- a/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
+++ b/electron/native-bridge/cursor/recording/macNativeCursorRecordingSession.ts
@@ -338,13 +338,21 @@ export class MacNativeCursorRecordingSession implements CursorRecordingSession {
this.boundsOverride = bounds;
const width = Math.max(1, bounds.width);
const height = Math.max(1, bounds.height);
+ // Replay the outside streak too, so samples hidden against the old bounds come back.
+ this.consecutiveOutsideSamples = 0;
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);
+ const normalizedX = (point.x - bounds.x) / width;
+ const normalizedY = (point.y - bounds.y) / height;
+ const isOutside = normalizedX < 0 || normalizedX > 1 || normalizedY < 0 || normalizedY > 1;
+ this.consecutiveOutsideSamples = isOutside ? this.consecutiveOutsideSamples + 1 : 0;
+ this.samples[index].cx = clamp(normalizedX, 0, 1);
+ this.samples[index].cy = clamp(normalizedY, 0, 1);
+ this.samples[index].visible =
+ this.consecutiveOutsideSamples < MacNativeCursorRecordingSession.OUTSIDE_HIDE_THRESHOLD;
}
}