From 62ad38f8185c1634968415973c02b2179b8bd394 Mon Sep 17 00:00:00 2001 From: Micha Hanselmann Date: Thu, 7 Oct 2021 15:14:36 +0200 Subject: [PATCH] fix: black window on screen capture when content protection is enabled --- shell/browser/native_window_views.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 31e147204d128..233ccc3ef07ba 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1125,8 +1125,17 @@ void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) { void NativeWindowViews::SetContentProtection(bool enable) { #if defined(OS_WIN) + HWND hwnd = GetAcceleratedWidget(); + if (!layered_) { + // Workaround to prevent black window on screen capture after hiding and + // showing the BrowserWindow. + LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); + ex_style |= WS_EX_LAYERED; + ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); + layered_ = true; + } DWORD affinity = enable ? WDA_EXCLUDEFROMCAPTURE : WDA_NONE; - ::SetWindowDisplayAffinity(GetAcceleratedWidget(), affinity); + ::SetWindowDisplayAffinity(hwnd, affinity); #endif }