From 5ed45d06dad3e11dd09b98ddbf37ef32e9dcc652 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Thu, 27 Jan 2022 02:37:32 +0100 Subject: [PATCH] UI: Check current affinity before calling SetWindowDisplayAffinity For some reason, SetWindowDisplayAffinity can make windows visible even when it sets the same value for affinity that GetWindowDisplayAffinity reports. Possibly an API bug as this is probably not a widely used API yet? Fixes a weird window with no size appearing when browsing for files on Windows. --- UI/window-basic-main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index ae32db5bc..d2466d3f5 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -9964,10 +9964,14 @@ void OBSBasic::SetDisplayAffinity(QWindow *window) #ifdef _WIN32 HWND hwnd = (HWND)window->winId(); - if (hideFromCapture) - SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE); - else - SetWindowDisplayAffinity(hwnd, WDA_NONE); + DWORD curAffinity; + if (GetWindowDisplayAffinity(hwnd, &curAffinity)) { + if (hideFromCapture && curAffinity != WDA_EXCLUDEFROMCAPTURE) + SetWindowDisplayAffinity(hwnd, WDA_EXCLUDEFROMCAPTURE); + else if (curAffinity != WDA_NONE) + SetWindowDisplayAffinity(hwnd, WDA_NONE); + } + #else // TODO: Implement for other platforms if possible. Don't forget to // implement SetDisplayAffinitySupported too!