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.
This commit is contained in:
Shelley Vohr 2025-05-09 16:38:27 +02:00 committed by GitHub
commit 75cf8ea96d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View file

@ -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();

View file

@ -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;