diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 207540bf4a50..981fdabebb2a 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -37,6 +37,7 @@ #include "shell/common/options_switches.h" #include "ui/aura/window_tree_host.h" #include "ui/base/hit_test.h" +#include "ui/compositor/compositor.h" #include "ui/display/screen.h" #include "ui/gfx/image/image.h" #include "ui/gfx/native_widget_types.h" @@ -1224,6 +1225,7 @@ void NativeWindowViews::SetBackgroundColor(SkColor background_color) { DeleteObject((HBRUSH)previous_brush); InvalidateRect(GetAcceleratedWidget(), nullptr, 1); #endif + GetWidget()->GetCompositor()->SetBackgroundColor(background_color); } void NativeWindowViews::SetHasShadow(bool has_shadow) { 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 3618bb840cb6..641aaf5b753c 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 @@ -23,6 +23,20 @@ ElectronDesktopWindowTreeHostWin::ElectronDesktopWindowTreeHostWin( ElectronDesktopWindowTreeHostWin::~ElectronDesktopWindowTreeHostWin() = default; +bool ElectronDesktopWindowTreeHostWin::ShouldUpdateWindowTransparency() const { + // If transparency is updated for an opaque window before widget init is + // completed, the window flickers white before the background color is applied + // and we don't want that. We do, however, want translucent windows to be + // properly transparent, so ensure it gets updated in that case. + if (!widget_init_done_ && !native_window_view_->IsTranslucent()) + return false; + return views::DesktopWindowTreeHostWin::ShouldUpdateWindowTransparency(); +} + +void ElectronDesktopWindowTreeHostWin::OnWidgetInitDone() { + widget_init_done_ = true; +} + bool ElectronDesktopWindowTreeHostWin::PreHandleMSG(UINT message, WPARAM w_param, LPARAM l_param, 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 acfbfda8be34..4776d6659306 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 @@ -31,6 +31,8 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin, protected: // views::DesktopWindowTreeHostWin: + void OnWidgetInitDone() override; + bool ShouldUpdateWindowTransparency() const override; bool PreHandleMSG(UINT message, WPARAM w_param, LPARAM l_param, @@ -51,6 +53,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin, private: raw_ptr native_window_view_; // weak ref std::optional force_should_paint_as_active_; + bool widget_init_done_ = false; }; } // namespace electron