From 75cf8ea96d6a81525c9e1b097e2bcba488a1f83b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 9 May 2025 16:38:27 +0200 Subject: [PATCH] fix: restore previous Windows screenshotting (#47020) 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. --- .../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;