fix: white window flicker on window creation (#47022)

This commit is contained in:
Shelley Vohr 2025-05-11 01:24:35 +02:00 committed by GitHub
commit 7ab032f594
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View file

@ -37,6 +37,7 @@
#include "shell/common/options_switches.h" #include "shell/common/options_switches.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/compositor/compositor.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
@ -1224,6 +1225,7 @@ void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
DeleteObject((HBRUSH)previous_brush); DeleteObject((HBRUSH)previous_brush);
InvalidateRect(GetAcceleratedWidget(), nullptr, 1); InvalidateRect(GetAcceleratedWidget(), nullptr, 1);
#endif #endif
GetWidget()->GetCompositor()->SetBackgroundColor(background_color);
} }
void NativeWindowViews::SetHasShadow(bool has_shadow) { void NativeWindowViews::SetHasShadow(bool has_shadow) {

View file

@ -23,6 +23,20 @@ ElectronDesktopWindowTreeHostWin::ElectronDesktopWindowTreeHostWin(
ElectronDesktopWindowTreeHostWin::~ElectronDesktopWindowTreeHostWin() = default; 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, bool ElectronDesktopWindowTreeHostWin::PreHandleMSG(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param,

View file

@ -31,6 +31,8 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
protected: protected:
// views::DesktopWindowTreeHostWin: // views::DesktopWindowTreeHostWin:
void OnWidgetInitDone() override;
bool ShouldUpdateWindowTransparency() const override;
bool PreHandleMSG(UINT message, bool PreHandleMSG(UINT message,
WPARAM w_param, WPARAM w_param,
LPARAM l_param, LPARAM l_param,
@ -51,6 +53,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
private: private:
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 widget_init_done_ = false;
}; };
} // namespace electron } // namespace electron