diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 10afaf001810..c7f8916177f5 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1282,12 +1282,7 @@ void NativeWindowViews::SetOpacity(const double opacity) { #if BUILDFLAG(IS_WIN) const double boundedOpacity = std::clamp(opacity, 0.0, 1.0); HWND hwnd = GetAcceleratedWidget(); - if (!layered_) { - LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); - ex_style |= WS_EX_LAYERED; - ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); - layered_ = true; - } + SetLayered(); ::SetLayeredWindowAttributes(hwnd, 0, boundedOpacity * 255, LWA_ALPHA); opacity_ = boundedOpacity; #else @@ -1730,6 +1725,16 @@ void NativeWindowViews::UpdateThickFrame() { FlipWindowStyle(GetAcceleratedWidget(), resizable_, WS_THICKFRAME); } } + +void NativeWindowViews::SetLayered() { + HWND hwnd = GetAcceleratedWidget(); + if (!layered_) { + LONG ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); + ex_style |= WS_EX_LAYERED; + ::SetWindowLong(hwnd, GWL_EXSTYLE, ex_style); + layered_ = true; + } +} #endif void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget, diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 2872d77c3293..ae85a927fc7f 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -178,6 +178,7 @@ class NativeWindowViews : public NativeWindow, #if BUILDFLAG(IS_WIN) TaskbarHost& taskbar_host() { return taskbar_host_; } void UpdateThickFrame(); + void SetLayered(); #endif SkColor overlay_button_color() const { return overlay_button_color_; } diff --git a/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc b/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc index daea2f8b3492..40a3d6b66d23 100644 --- a/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc +++ b/shell/browser/ui/win/electron_desktop_window_tree_host_win.cc @@ -176,6 +176,11 @@ void ElectronDesktopWindowTreeHostWin::UpdateAllowScreenshots() { if (allowed == allow_screenshots_) return; + // On some older Windows versions, setting the display affinity + // to WDA_EXCLUDEFROMCAPTURE won't prevent the window from being + // captured - setting WS_EX_LAYERED mitigates this issue. + if (base::win::GetVersion() < base::win::Version::WIN11_22H2) + native_window_view_->SetLayered(); ::SetWindowDisplayAffinity( GetAcceleratedWidget(), allow_screenshots_ ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE);