Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(capture): include menus and popups in Windows window recordings
EtienneLescotb8b9049b2e2d
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.tsindex c892b0be7..bbbb74bc6 100644--- a/electron/ipc/handlers.ts+++ b/electron/ipc/handlers.ts@@ -117,6 +117,7 @@ import {NATIVE_WINDOWS_SALVAGEABLE_OUTPUT_BYTES,readMicrophoneDefaulted,readMicrophoneUnavailable,+ readSecondaryWindowsApplied,readWebcamFormat,readWebcamUnavailable,terminateNativeWindowsCapture,@@ -2926,6 +2927,9 @@ export function registerIpcHandlers(cursorOffsetMs: nativeWindowsCursorOffsetMs,webcamFormat,encoderSelection,+ // Logged only: menus missing from a window take on Windows before 11+ // 24H2 are a platform limit, not something to put in front of the user.+ secondaryWindowsApplied: readSecondaryWindowsApplied(nativeWindowsCaptureOutput),});const source = selectedSource || { name: "Screen" };diff --git a/electron/native/wgc-capture/src/main.cpp b/electron/native/wgc-capture/src/main.cppindex 996540de7..b094e31f5 100644--- a/electron/native/wgc-capture/src/main.cpp+++ b/electron/native/wgc-capture/src/main.cpp@@ -730,7 +730,14 @@ int wmain(int argc, wchar_t* argv[]) {// A window is captured by whichever display it currently sits on, which// is the adapter that matters for the same reason a monitor's does.capturedMonitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST);- if (!session.initialize(window, config.fps, config.captureCursor)) {+ // A window source would otherwise lose every context menu and dropdown,+ // which are windows of their own (getopenscreen/openscreen#894). Windows 11+ // 24H2+ can draw them into this capture; OPENSCREEN_WGC_DISABLE_SECONDARY_+ // WINDOWS=1 restores the window-only capture. Never for a monitor source,+ // which already contains everything on that screen.+ const bool includeSecondaryWindows =+ readEnvInt("OPENSCREEN_WGC_DISABLE_SECONDARY_WINDOWS", 0) != 1;+ if (!session.initialize(window, config.fps, config.captureCursor, includeSecondaryWindows)) {std::cerr << "ERROR: Failed to initialize WGC window session" << std::endl;return 1;}diff --git a/electron/native/wgc-capture/src/wgc_session.cpp b/electron/native/wgc-capture/src/wgc_session.cppindex b75d0819e..726d7effd 100644--- a/electron/native/wgc-capture/src/wgc_session.cpp+++ b/electron/native/wgc-capture/src/wgc_session.cpp@@ -214,6 +214,27 @@ bool WgcSession::applySessionOptions(bool captureCursor) {// IsBorderRequired is Windows 11-only. Ignore it on older builds.}+ // Best effort, never a reason to fail the recording: a menu missing from the+ // video is today's behavior, a recording that does not start is not.+ if (includeSecondaryWindows_ && !secondaryWindowsReported_) {+ bool applied = false;+#if defined(NTDDI_WIN11_GE)+ // IGraphicsCaptureSession6 (Windows 11 24H2, SDK 26100). try_as returns+ // null on an older runtime, so it degrades to the window alone.+ try {+ if (auto session6 = session_.try_as<wgcap::IGraphicsCaptureSession6>()) {+ session6.IncludeSecondaryWindows(true);+ applied = session6.IncludeSecondaryWindows();+ }+ } catch (...) {+ // Left at applied=false; the event below says so.+ }+#endif+ secondaryWindowsReported_ = true;+ std::cout << "{\"event\":\"secondary-windows\",\"applied\":" << (applied ? "true" : "false")+ << "}" << std::endl;+ }+return true;}@@ -240,8 +261,9 @@ bool WgcSession::initialize(HMONITOR monitor, int fps, bool captureCursor) {return true;}-bool WgcSession::initialize(HWND window, int fps, bool captureCursor) {+bool WgcSession::initialize(HWND window, int fps, bool captureCursor, bool includeSecondaryWindows) {fps_ = fps > 0 ? fps : 60;+ includeSecondaryWindows_ = includeSecondaryWindows;if (!createD3DDevice()) {return false;}diff --git a/electron/native/wgc-capture/src/wgc_session.h b/electron/native/wgc-capture/src/wgc_session.hindex 35eb25a54..4dbb33e43 100644--- a/electron/native/wgc-capture/src/wgc_session.h+++ b/electron/native/wgc-capture/src/wgc_session.h@@ -53,7 +53,11 @@ public:WgcSession& operator=(const WgcSession&) = delete;bool initialize(HMONITOR monitor, int fps, bool captureCursor);- bool initialize(HWND window, int fps, bool captureCursor);+ // includeSecondaryWindows asks DWM to draw the popups and tool windows that+ // overlap the captured window (context menus, dropdowns) into the same+ // texture. Windows 11 24H2+ only; older runtimes silently keep capturing the+ // window alone, and a `secondary-windows` event reports which one happened.+ bool initialize(HWND window, int fps, bool captureCursor, bool includeSecondaryWindows = false);bool start();// Returns the most recently arrived frame's texture and timestamp, or// false if none is available since the last call. The returned pointer@@ -113,5 +117,7 @@ private:int height_ = 0;int fps_ = 60;bool captureCursor_ = false;+ bool includeSecondaryWindows_ = false;+ bool secondaryWindowsReported_ = false;bool started_ = false;};diff --git a/electron/recording/nativeWindowsCaptureStop.test.ts b/electron/recording/nativeWindowsCaptureStop.test.tsindex 68ebf01c9..e277eceec 100644--- a/electron/recording/nativeWindowsCaptureStop.test.ts+++ b/electron/recording/nativeWindowsCaptureStop.test.ts@@ -7,6 +7,7 @@ import {NATIVE_WINDOWS_SALVAGEABLE_OUTPUT_BYTES,readMicrophoneDefaulted,readMicrophoneUnavailable,+ readSecondaryWindowsApplied,readStoppedPath,readWebcamFormat,readWebcamUnavailable,@@ -125,6 +126,27 @@ describe("readMicrophoneDefaulted", () => {});});+describe("readSecondaryWindowsApplied", () => {+ it("is true when the helper drew menus and popups into the capture", () => {+ const output =+ '{"event":"cursor-capture","schemaVersion":2,"requested":false,"applied":false}\n' ++ '{"event":"secondary-windows","applied":true}\n' ++ "Recording started\n";+ expect(readSecondaryWindowsApplied(output)).toBe(true);+ });++ it("is false on a runtime older than Windows 11 24H2", () => {+ expect(readSecondaryWindowsApplied('{"event":"secondary-windows","applied":false}\n')).toBe(+ false,+ );+ });++ it("is null when the helper said nothing, as for a monitor source", () => {+ const output = '{"event":"cursor-capture","applied":true}\nRecording started\n';+ expect(readSecondaryWindowsApplied(output)).toBe(null);+ });+});+describe("readMicrophoneUnavailable", () => {// The line ScreenCaptureRecorder.swift emits on macOS 13 and 14, which have no// `captureMicrophone`, before recording the take without it (#700).diff --git a/electron/recording/nativeWindowsCaptureStop.ts b/electron/recording/nativeWindowsCaptureStop.tsindex 9f2e2db33..478d30e61 100644--- a/electron/recording/nativeWindowsCaptureStop.ts+++ b/electron/recording/nativeWindowsCaptureStop.ts@@ -122,6 +122,20 @@ export function readMicrophoneDefaulted(output: string) {return output.includes('"code":"microphone-defaulted"');}+/**+ * Did the helper draw menus and popups into a window recording?+ *+ * `true` on Windows 11 24H2+, `false` where the runtime cannot (the recording is+ * the window alone, as before), `null` when the helper never said: a monitor+ * source, the kill switch, or an older helper (getopenscreen/openscreen#894).+ */+export function readSecondaryWindowsApplied(output: string) {+ if (output.includes('"event":"secondary-windows","applied":true')) {+ return true;+ }+ return output.includes('"event":"secondary-windows","applied":false') ? false : null;+}+/*** Did the macOS helper record without the microphone it was asked for?*