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(recording): close four gaps found in review of the Linux capture path

Etienne Lescot599617aa36d7
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index 5301bd93b..715dc8515 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -552,7 +552,23 @@ let linuxNativeCaptureSourceLabel: string | null = null;
* cancel, would otherwise leak a live ScreenCast session — the compositor's
* "screen is being shared" indicator with nothing recording behind it.
*/
-let preparedLinuxCapture: { session: LinuxNativeCaptureSession; outputPath: string } | null = null;
+let preparedLinuxCapture: {
+ session: LinuxNativeCaptureSession;
+ outputPath: string;
+ /** What the helper was actually spawned with. See [`captureSettingsOf`]. */
+ request: NativeLinuxRecordingRequest;
+} | null = null;
+/**
+ * Identifies the prepare that is still waiting on the picker.
+ *
+ * The slot above is only filled AFTER an await with no upper bound — a human is
+ * reading a dialog. For that whole window it is null, so without this token a
+ * cancel would find nothing to cancel and a second prepare would find nothing to
+ * supersede: the first session would then assign itself afterwards and stay
+ * alive, holding a ScreenCast grant and the compositor's sharing indicator with
+ * nothing recording behind it.
+ */
+let preparingLinuxCaptureToken: symbol | null = null;
/**
* Claims the prepared session when it matches the recording about to start.
@@ -561,22 +577,52 @@ let preparedLinuxCapture: { session: LinuxNativeCaptureSession; outputPath: stri
* discarded rather than reused: arming it would record against the wrong output
* path, and leaving it would strand a portal session.
*/
-function takePreparedLinuxSession(outputPath: string): LinuxNativeCaptureSession | null {
+function takePreparedLinuxSession(
+ outputPath: string,
+ request: NativeLinuxRecordingRequest,
+): LinuxNativeCaptureSession | null {
const prepared = preparedLinuxCapture;
if (!prepared) {
return null;
}
preparedLinuxCapture = null;
- if (prepared.outputPath === outputPath) {
- return prepared.session;
+ if (prepared.outputPath !== outputPath) {
+ console.warn("[native-linux] discarding a prepared session for a different recording");
+ prepared.session.discard();
+ return null;
}
- console.warn("[native-linux] discarding a prepared session for a different recording");
- prepared.session.discard();
- return null;
+ // EVERY CAPTURE SETTING IS FIXED AT SPAWN. `arm()` only writes `record`, so a
+ // prepared helper is already running with the audio and cursor settings it
+ // was created with — and the HUD does not lock its controls during the
+ // countdown, so the user really can change them in between. Reusing the
+ // session would record one thing while the app believed another, including
+ // the cursor mode that decides whether the editor draws its own pointer.
+ if (captureSettingsOf(prepared.request) !== captureSettingsOf(request)) {
+ console.info("[native-linux] settings changed during the countdown; renegotiating");
+ prepared.session.discard();
+ return null;
+ }
+ return prepared.session;
+}
+
+/** The request fields baked into the helper's spawn arguments, canonicalised. */
+function captureSettingsOf(request: NativeLinuxRecordingRequest): string {
+ return JSON.stringify({
+ fps: request.video?.fps ?? null,
+ bitrate: request.video?.bitrate ?? null,
+ system: request.audio?.system?.enabled ?? false,
+ microphone: request.audio?.microphone?.enabled ?? false,
+ deviceName: request.audio?.microphone?.deviceName ?? null,
+ gain: request.audio?.microphone?.gain ?? null,
+ cursor: normalizeCursorCaptureMode(request?.cursor?.mode) ?? "editable-overlay",
+ });
}
/** Tears down a prepared-but-unarmed session, e.g. an abandoned countdown. */
function discardPreparedLinuxCapture(reason: string) {
+ // Invalidate any negotiation still in flight, so the session it is about to
+ // produce is discarded on arrival instead of stranded.
+ preparingLinuxCaptureToken = null;
if (!preparedLinuxCapture) {
return;
}
@@ -596,13 +642,13 @@ function discardPreparedLinuxCapture(reason: string) {
function linuxSourceLabel(kind?: LinuxCaptureSourceKind): string {
switch (kind) {
case "window":
- return "Window";
+ return mainT("common", "recordingSource.window");
case "monitor":
- return "Screen";
+ return mainT("common", "recordingSource.screen");
case "virtual":
- return "Virtual display";
+ return mainT("common", "recordingSource.virtual");
default:
- return "Screen recording";
+ return mainT("common", "recordingSource.unknown");
}
}
/**
@@ -1871,6 +1917,8 @@ export function registerIpcHandlers(
return { success: false, reason: "already-recording" };
}
discardPreparedLinuxCapture("superseded by a new prepare");
+ const token = Symbol("prepare-native-linux-recording");
+ preparingLinuxCaptureToken = token;
try {
if (!findPipeWireCursorHelperPath()) {
@@ -1909,7 +1957,16 @@ export function registerIpcHandlers(
// The picker is up now. No timeout: a human is reading a dialog.
await session.waitUntilSourceSelected();
- preparedLinuxCapture = { session, outputPath };
+ // Cancelled or superseded while the picker was up. Discard rather
+ // than assign: this grant is for a recording nobody is waiting for
+ // any more, and keeping it would leave the sharing indicator on.
+ if (preparingLinuxCaptureToken !== token) {
+ session.discard();
+ return { success: false, reason: "cancelled" };
+ }
+ preparingLinuxCaptureToken = null;
+
+ preparedLinuxCapture = { session, outputPath, request };
return {
success: true,
recordingId,
@@ -1958,7 +2015,7 @@ export function registerIpcHandlers(
// working: a path that never prepared still gets a full start
// below, just with the picker after its countdown instead of
// before. Nothing has to know which path it is on.
- const prepared = takePreparedLinuxSession(outputPath);
+ const prepared = takePreparedLinuxSession(outputPath, request);
const session =
prepared ??
new LinuxNativeCaptureSession({
diff --git a/electron/native/pipewire-capture/src/capture.rs b/electron/native/pipewire-capture/src/capture.rs
index 8a1174bcd..0b07c34a4 100644
--- a/electron/native/pipewire-capture/src/capture.rs
+++ b/electron/native/pipewire-capture/src/capture.rs
@@ -296,7 +296,12 @@ impl Capture {
/// its original dimensions — see [`Self::committed_width`] — so the caller
/// reports it once rather than silently reframing.
pub fn crop_diverged(&self, frame: &shim::Frame) -> bool {
- frame.crop.width != self.committed_width || frame.crop.height != self.committed_height
+ // Compared at ENCODED parity, not raw. The committed size was rounded
+ // down to even for H.264 chroma, so a window sitting stably at 321x241
+ // commits 320x240 and would otherwise be reported as resized on every
+ // single frame — a warning about a window that never moved.
+ (frame.crop.width & !1) != self.committed_width
+ || (frame.crop.height & !1) != self.committed_height
}
/// Where to start reading this frame, in source pixels.
@@ -681,6 +686,29 @@ mod tests {
let _ = std::fs::remove_file(&output);
}
+ /// A window whose size is odd is rounded down once, at encoder open. Judging
+ /// later frames against the raw rect would then report a resize on every
+ /// frame of a window that never moved.
+ #[test]
+ fn a_stable_odd_sized_window_is_not_reported_as_resized() {
+ let output = std::env::temp_dir().join("openscreen-capture-odd.mp4");
+ // 321x241 rounds to the 320x240 the encoder is opened at.
+ let (mut capture, _) =
+ Capture::start(&output, 320, 240, 30, Some(1_000_000), Some(Backend::Software), Vec::new())
+ .expect("start");
+
+ let frame = cropped_frame(
+ 1920,
+ 1080,
+ shim::CropRect { x: 0, y: 0, width: 321, height: 241 },
+ shim::constants().video_format_bgrx,
+ );
+
+ assert!(!capture.crop_diverged(&frame), "an unchanged odd crop is not a resize");
+ let _ = capture.finish();
+ let _ = std::fs::remove_file(&output);
+ }
+
#[test]
fn an_uncropped_frame_reports_no_divergence() {
let output = std::env::temp_dir().join("openscreen-capture-nocrop.mp4");
diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsx
index 32a1ea411..12d177c14 100644
--- a/src/components/launch/LaunchWindow.test.tsx
+++ b/src/components/launch/LaunchWindow.test.tsx
@@ -474,6 +474,31 @@ describe("LaunchWindow record button", () => {
);
});
+ /**
+ * `portalOwnsSource` is resolved over IPC, so for a moment after mount it
+ * still reads false on Linux. A Record click landing in that window opened a
+ * selector the main process refuses — and the click used to be swallowed,
+ * doing nothing at all. The refusal is authoritative and answers immediately,
+ * so it starts the recording instead.
+ */
+ it("records when the picker refuses because the portal owns the choice", async () => {
+ platformState.value = "linux";
+ // Forces the click down the open-the-selector path, as an unresolved
+ // portal check does.
+ linuxHelperAvailable.value = false;
+ window.electronAPI.openSourceSelector = vi.fn(async () => ({
+ opened: false,
+ reason: "portal-owns-selection",
+ })) as unknown as Window["electronAPI"]["openSourceSelector"];
+
+ renderLaunchWindow();
+ fireEvent.click(await screen.findByTestId("launch-record-button"));
+
+ await waitFor(() => {
+ expect(recorderState.value.toggleRecording).toHaveBeenCalledTimes(1);
+ });
+ });
+
it("does not name a source while recording on Linux", async () => {
platformState.value = "linux";
recorderState.value.recording = true;
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index 33b509eb8..71d9eda27 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -514,8 +514,19 @@ export function LaunchWindow() {
recordAfterSourceSelectionRef.current = true;
void openSourceSelector()
.then((result) => {
- if (!result.opened) {
- recordAfterSourceSelectionRef.current = false;
+ if (result.opened) {
+ return;
+ }
+ recordAfterSourceSelectionRef.current = false;
+ // The main process is the authority on who owns the choice,
+ // and it answers synchronously. `portalOwnsSource` is resolved
+ // over IPC, so for a moment after mount it still reads false —
+ // and a Record click landing in that window used to open a
+ // selector that refused, leaving the click doing nothing at
+ // all. Honouring the refusal starts the recording instead,
+ // whatever the local state has caught up to.
+ if (result.reason === "portal-owns-selection" && !recording) {
+ toggleRecording();
}
})
.catch(() => {
diff --git a/src/i18n/locales/ar/common.json b/src/i18n/locales/ar/common.json
index 16b826989..aead94336 100644
--- a/src/i18n/locales/ar/common.json
+++ b/src/i18n/locales/ar/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "عربي",
"short": "AR"
+ },
+ "recordingSource": {
+ "window": "نافذة",
+ "screen": "شاشة",
+ "virtual": "شاشة افتراضية",
+ "unknown": "تسجيل الشاشة"
}
}
diff --git a/src/i18n/locales/en/common.json b/src/i18n/locales/en/common.json
index 6d77a0121..8dd5e6c86 100644
--- a/src/i18n/locales/en/common.json
+++ b/src/i18n/locales/en/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "English",
"short": "EN"
+ },
+ "recordingSource": {
+ "window": "Window",
+ "screen": "Screen",
+ "virtual": "Virtual display",
+ "unknown": "Screen recording"
}
}
diff --git a/src/i18n/locales/es/common.json b/src/i18n/locales/es/common.json
index 82da2527a..0260dae04 100644
--- a/src/i18n/locales/es/common.json
+++ b/src/i18n/locales/es/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Español",
"short": "ES"
+ },
+ "recordingSource": {
+ "window": "Ventana",
+ "screen": "Pantalla",
+ "virtual": "Pantalla virtual",
+ "unknown": "Grabación de pantalla"
}
}
diff --git a/src/i18n/locales/fr/common.json b/src/i18n/locales/fr/common.json
index 47955acd2..14a6ef89a 100644
--- a/src/i18n/locales/fr/common.json
+++ b/src/i18n/locales/fr/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Français",
"short": "FR"
+ },
+ "recordingSource": {
+ "window": "Fenêtre",
+ "screen": "Écran",
+ "virtual": "Écran virtuel",
+ "unknown": "Enregistrement d'écran"
}
}
diff --git a/src/i18n/locales/it/common.json b/src/i18n/locales/it/common.json
index 728b04e4f..a7e52d874 100644
--- a/src/i18n/locales/it/common.json
+++ b/src/i18n/locales/it/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Italiano",
"short": "IT"
+ },
+ "recordingSource": {
+ "window": "Finestra",
+ "screen": "Schermo",
+ "virtual": "Schermo virtuale",
+ "unknown": "Registrazione schermo"
}
}
diff --git a/src/i18n/locales/ja-JP/common.json b/src/i18n/locales/ja-JP/common.json
index 53b684bb1..f2a063f51 100644
--- a/src/i18n/locales/ja-JP/common.json
+++ b/src/i18n/locales/ja-JP/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "日本語",
"short": "JA"
+ },
+ "recordingSource": {
+ "window": "ウィンドウ",
+ "screen": "画面",
+ "virtual": "仮想ディスプレイ",
+ "unknown": "画面録画"
}
}
diff --git a/src/i18n/locales/ko-KR/common.json b/src/i18n/locales/ko-KR/common.json
index 612f08bef..7c1e5e8c3 100644
--- a/src/i18n/locales/ko-KR/common.json
+++ b/src/i18n/locales/ko-KR/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "한국어",
"short": "KO"
+ },
+ "recordingSource": {
+ "window": "창",
+ "screen": "화면",
+ "virtual": "가상 디스플레이",
+ "unknown": "화면 녹화"
}
}
diff --git a/src/i18n/locales/pt-BR/common.json b/src/i18n/locales/pt-BR/common.json
index ee06d2391..477b7699e 100644
--- a/src/i18n/locales/pt-BR/common.json
+++ b/src/i18n/locales/pt-BR/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Português Brasileiro",
"short": "PT-BR"
+ },
+ "recordingSource": {
+ "window": "Janela",
+ "screen": "Tela",
+ "virtual": "Tela virtual",
+ "unknown": "Gravação de tela"
}
}
diff --git a/src/i18n/locales/ru/common.json b/src/i18n/locales/ru/common.json
index 6e2d97186..4838c0989 100644
--- a/src/i18n/locales/ru/common.json
+++ b/src/i18n/locales/ru/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Русский",
"short": "RU"
+ },
+ "recordingSource": {
+ "window": "Окно",
+ "screen": "Экран",
+ "virtual": "Виртуальный экран",
+ "unknown": "Запись экрана"
}
}
diff --git a/src/i18n/locales/tr/common.json b/src/i18n/locales/tr/common.json
index cdac32a81..0282bf0e5 100644
--- a/src/i18n/locales/tr/common.json
+++ b/src/i18n/locales/tr/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Türkçe",
"short": "TR"
+ },
+ "recordingSource": {
+ "window": "Pencere",
+ "screen": "Ekran",
+ "virtual": "Sanal ekran",
+ "unknown": "Ekran kaydı"
}
}
diff --git a/src/i18n/locales/vi/common.json b/src/i18n/locales/vi/common.json
index f9f9fd067..2ea8e3258 100644
--- a/src/i18n/locales/vi/common.json
+++ b/src/i18n/locales/vi/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "Tiếng Việt",
"short": "VI"
+ },
+ "recordingSource": {
+ "window": "Cửa sổ",
+ "screen": "Màn hình",
+ "virtual": "Màn hình ảo",
+ "unknown": "Ghi màn hình"
}
}
diff --git a/src/i18n/locales/zh-CN/common.json b/src/i18n/locales/zh-CN/common.json
index 1d72f32be..4bf91ce33 100644
--- a/src/i18n/locales/zh-CN/common.json
+++ b/src/i18n/locales/zh-CN/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "简体中文",
"short": "简中"
+ },
+ "recordingSource": {
+ "window": "窗口",
+ "screen": "屏幕",
+ "virtual": "虚拟显示器",
+ "unknown": "屏幕录制"
}
}
diff --git a/src/i18n/locales/zh-TW/common.json b/src/i18n/locales/zh-TW/common.json
index 92401c80a..6d8f827f6 100644
--- a/src/i18n/locales/zh-TW/common.json
+++ b/src/i18n/locales/zh-TW/common.json
@@ -50,5 +50,11 @@
"locale": {
"name": "繁體中文",
"short": "繁中"
+ },
+ "recordingSource": {
+ "window": "視窗",
+ "screen": "螢幕",
+ "virtual": "虛擬顯示器",
+ "unknown": "螢幕錄製"
}
}