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

Closes https://github.com/electron/electron/issues/47152.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-05-27 14:24:48 +02:00 committed by GitHub
commit f9b86609a9
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) { void ElectronDesktopWindowTreeHostWin::HandleVisibilityChanged(bool visible) {
if (native_window_view_->widget()) if (native_window_view_->widget())
native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible); native_window_view_->widget()->OnNativeWidgetVisibilityChanged(visible);
if (visible)
UpdateAllowScreenshots();
} }
void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) { void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) {
::SetWindowDisplayAffinity(GetAcceleratedWidget(), if (allow_screenshots_ == allow)
allow ? WDA_NONE : WDA_EXCLUDEFROMCAPTURE); 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( void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated(

View file

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