From ace7ef4316ccbcb3d3499cfb9631c6897f411b9d Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 13:10:44 -0400 Subject: [PATCH] fix: restore previous Windows screenshotting (#47033) Fixes https://github.com/electron/electron/issues/45990 We previously made a change in https://github.com/electron/electron/pull/45868 to fix content protection being lost on hide and re-show. However, this cause a breaking change where protected windows were made opaque black instead of being hidden as before. This overrides relevant methods in ElectronDesktopWindowTreeHostWin to restore the previous behavior. without regressing the original issue. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- .../ui/win/electron_desktop_window_tree_host_win.cc | 10 ++++++++++ .../ui/win/electron_desktop_window_tree_host_win.h | 2 ++ 2 files changed, 12 insertions(+) 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 ee6509b9b79c..3618bb840cb6 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 @@ -126,6 +126,16 @@ bool ElectronDesktopWindowTreeHostWin::HandleMouseEvent(ui::MouseEvent* event) { return views::DesktopWindowTreeHostWin::HandleMouseEvent(event); } +void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) { + if (native_window_view_->widget()) + native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible); +} + +void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) { + ::SetWindowDisplayAffinity(GetAcceleratedWidget(), + allow ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE); +} + void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated( ui::NativeTheme* observed_theme) { HWND hWnd = GetAcceleratedWidget(); diff --git a/shell/browser/ui/win/electron_desktop_window_tree_host_win.h b/shell/browser/ui/win/electron_desktop_window_tree_host_win.h index 940328fbd221..acfbfda8be34 100644 --- a/shell/browser/ui/win/electron_desktop_window_tree_host_win.h +++ b/shell/browser/ui/win/electron_desktop_window_tree_host_win.h @@ -41,6 +41,8 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin, int frame_thickness) const override; bool HandleMouseEventForCaption(UINT message) const override; bool HandleMouseEvent(ui::MouseEvent* event) override; + void HandleVisibilityChanged(bool visible) override; + void SetAllowScreenshots(bool allow) override; // ui::NativeThemeObserver: void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;