Repository navigation
Conversation
Add ExcludeFromCapture to WindowOptions and PanelOptions, desktop.SetWindowExcludedFromCapture and desktop.CanExcludeWindowsFromCapture. macOS sets the window's sharing type to none; Windows 10 version 2004 and later set the display affinity WDA_EXCLUDEFROMCAPTURE, without falling back to WDA_MONITOR's black rectangle on earlier builds. Linux, phones and the web report it unavailable. Scope.Capture of an excluded window reports an error. Fixes #2826
Add nsgo.WindowExcludedFromCapture so the main window, like any other, stays out of captures from its first frame on macOS and Windows. Add a macOS test that reads the screen with screencapture under an excluded window and a window excluded before it first shows, and log when the sharing type macOS reports differs from the one set. Make the Windows pixel test open its windows through the engine, with the excluded one owned by the window read under it so it stays above.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Desktop apps can now keep a window or panel out of screenshots, screen recordings and screen sharing, as a recorder's HUD, a countdown, an annotation overlay or a password prompt needs.
ExcludeFromCaptureondesktop.WindowOptionsanddesktop.PanelOptionsapplies it before the surface first shows, so no frame of it is captured.nsgo.WindowExcludedFromCapture()does the same for the main window, alongsidensgo.SkipTaskbar()andnsgo.WindowNoShadow(), so a recorder whose main window is its HUD is never captured either.desktop.SetWindowExcludedFromCaptureturns it on or off later, anddesktop.CanExcludeWindowsFromCapturesays in a window's scope whether it takes effect.sharingTypetoNSWindowSharingNone, and back toNSWindowSharingReadOnly. AppKit documents this only as keeping other processes from reading the window's contents, so the docs say plainly that whether a given recorder leaves it out depends on the capture API it uses.SetWindowDisplayAffinitywithWDA_EXCLUDEFROMCAPTURE, andWDA_NONEto turn it off. Before Windows 10 version 2004 (build 19041) the capability reads false. It does not fall back toWDA_MONITOR, which would show a black rectangle instead of hiding the window.Scope.Captureof an excluded window returns an error instead of an image. What the system's capture makes of an excluded window differs by API and OS version, andPrintWindowwould bypass the exclusion on Windows.nsgotestrecords the option on opened surfaces (SurfaceConfig.ExcludeFromCapture) and records the runtime request (WindowSetExcludedFromCapture).On macOS 26.7, during a run over SSH with no display, a window that already had its window-server window stayed at
NSWindowSharingNoneafter it was set back to read-only. A deferred window switched both ways. Because of this, the macOS backend tracks the sharing type the window reports, not the one it requested, and logs when the two differ, so an app is told rather than left with a window that silently stays excluded. The public docs,desktop.SetWindowExcludedFromCaptureand the architecture doc say so.Tests that read the screen:
TestWindowExcludedFromScreenCaptureshows an opaque magenta window and reads the screen under it withscreencapture, another process as a real recorder is. It checks that the colour is present before, absent while excluded and present again aftersetExcludedFromCapture(false), or, if the window server keeps the sharing type at none, that the surface still reports it excluded and the colour stays absent. A second, deferred window is excluded before it first shows and must never appear, then appear once the exclusion is off. It skips without a display or Screen Recording permission.TestWindowExcludedFromCaptureopens a magenta window and a smaller green window owned by it, so the green one stays above, withExcludeFromCapture. The screen must show magenta where the green window is until its exclusion is turned off, then green. The magenta window is then toggled the same way.Fixes #2826
Targets
core,base,ui,tsx, thensgotool)Screenshots
None
Verification
5e7e7e4ef58c730df9b031753a0c58fe37c9473ab84aa6d55419ce37f3b640f8887fd0bcbf47aa6dgo tool nsgo check -target macos,windows,linux -jobs 6→ 0go tool nsgo test ./core ./desktop ./nsgotest ./internal/driver ./internal/backend .→ 0go tool nsgo test -run 'TestWindowExcludedFromCapture|TestWindowExcludedFromScreenCapture|TestTransparentWindow$' ./internal/platform/macos→ 0go run ./tools/changelog check→ 0nsgo checkran on56ec8cdbe. The only later change is a skip message in a test, which the test runs above built.TestWindowExcludedFromScreenCaptureskipped there becausescreencapturecannot read a screen without a display, so the pixel checks on macOS, including whether a window shown on a display really gets its read-only sharing type back, still need a run on a Mac with a display and Screen Recording permission for the terminal. The WindowsTestWindowExcludedFromCapturewas compiled and vetted, not run; it needs a Windows 10 version 2004 or later session with a desktop.nsgo.WindowExcludedFromCapturereachesSurfaceConfigthrough the samecore.WindowOptionspath that the core tests cover, but no native test opens a main window with it. Linux runtime tests and arm64 macOS were not run.Checklist
fix(linux): keep the caret after a paste; a squash merge uses it as the commit subject.changelog.d/fragment, not inCHANGELOG.md.