fix: titlebar showing in content protected window (#47241)

Closes https://github.com/electron/electron/issues/47152.
This commit is contained in:
Shelley Vohr 2025-05-26 09:46:04 +02:00 committed by GitHub
parent c6f368acc6
commit f89c2a0ef4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -143,11 +143,33 @@ bool ElectronDesktopWindowTreeHostWin::HandleMouseEvent(ui::MouseEvent* event) {
void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
if (native_window_view_->widget())
native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible);
if (visible)
UpdateAllowScreenshots();
}
void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) {
::SetWindowDisplayAffinity(GetAcceleratedWidget(),
allow ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE);
if (allow_screenshots_ == allow)
return;
allow_screenshots_ = allow;
// If the window is not visible, do not set the window display affinity
// because `SetWindowDisplayAffinity` will attempt to compose the window,
if (!IsVisible())
return;
UpdateAllowScreenshots();
}
void ElectronDesktopWindowTreeHostWin::UpdateAllowScreenshots() {
bool allowed = views::DesktopWindowTreeHostWin::AreScreenshotsAllowed();
if (allowed == allow_screenshots_)
return;
::SetWindowDisplayAffinity(
GetAcceleratedWidget(),
allow_screenshots_ ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE);
}
void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated(

View file

@ -52,8 +52,11 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
bool ShouldWindowContentsBeTransparent() const override;
private:
void UpdateAllowScreenshots();
raw_ptr<NativeWindowViews> native_window_view_; // weak ref
std::optional<bool> force_should_paint_as_active_;
bool allow_screenshots_ = true;
bool widget_init_done_ = false;
};