UI: Add option to hide OBS windows on Windows

This uses the SetWindowDisplayAffinity API to hide windows from capture
applications (including OBS). This is not perfect - internal windows
such as context menus, combo box dropdowns, etc will still be displayed.
Even with these limitations, it should help people with single monitors
capture content with less interference from the OBS window.

This implementation is for Windows only but the code is generic enough
that adding other platforms should be straightforward.
This commit is contained in:
Richard Stanway
2020-06-27 02:31:08 +02:00
committed by Jim
parent e9cbe52d96
commit 076cd5d5d4
12 changed files with 162 additions and 0 deletions

View File

@@ -9947,3 +9947,29 @@ void OBSBasic::UpdatePreviewSafeAreas()
drawSafeAreas = config_get_bool(App()->GlobalConfig(), "BasicWindow",
"ShowSafeAreas");
}
void OBSBasic::SetDisplayAffinity(QWindow *window)
{
if (!SetDisplayAffinitySupported())
return;
bool hideFromCapture = config_get_bool(App()->GlobalConfig(),
"BasicWindow",
"HideOBSWindowsFromCapture");
// Don't hide projectors, those are designed to be visible / captured
if (window->property("isOBSProjectorWindow") == true)
return;
#ifdef _WIN32
HWND hwnd = (HWND)window->winId();
if (hideFromCapture)
SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE);
else
SetWindowDisplayAffinity(hwnd, WDA_NONE);
#else
// TODO: Implement for other platforms if possible. Don't forget to
// implement SetDisplayAffinitySupported too!
#endif
}