From 673ec5d39e53d277e3e7e5388e9456c2b7ce6a3c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:37:01 +0200 Subject: [PATCH] fix: window `accentColor` should adhere to native window behavior (#47802) * fix: window accentColor should adhere to native window behavior Co-authored-by: Shelley Vohr * fix: address review feedback Co-authored-by: Shelley Vohr * chore: remove duplicate UpdateWindowAccentColor call in ctor Co-authored-by: Shelley Vohr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/browser/native_window_views.cc | 8 ++++++-- shell/browser/native_window_views.h | 2 +- shell/browser/native_window_views_win.cc | 8 ++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 734eef269016..10afaf001810 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -422,8 +422,6 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, last_window_state_ = ui::mojom::WindowShowState::kFullscreen; else last_window_state_ = ui::mojom::WindowShowState::kNormal; - - UpdateWindowAccentColor(); #endif // Listen to mouse events. @@ -1746,6 +1744,12 @@ void NativeWindowViews::OnWidgetActivationChanged(views::Widget* changed_widget, NativeWindow::NotifyWindowBlur(); } +#if BUILDFLAG(IS_WIN) + // Update accent color based on activation state when no explicit color is + // set. + UpdateWindowAccentColor(active); +#endif + // Hide menu bar when window is blurred. if (!active && IsMenuBarAutoHide() && IsMenuBarVisible()) SetMenuBarVisibility(false); diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 87dbf4bb732c..2872d77c3293 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -222,7 +222,7 @@ class NativeWindowViews : public NativeWindow, void ResetWindowControls(); void SetRoundedCorners(bool rounded); void SetForwardMouseMessages(bool forward); - void UpdateWindowAccentColor(); + void UpdateWindowAccentColor(bool active); static LRESULT CALLBACK SubclassProc(HWND hwnd, UINT msg, WPARAM w_param, diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 21fbdcfed846..7baa349bd91f 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -499,7 +499,7 @@ bool NativeWindowViews::PreHandleMSG(UINT message, return false; } case WM_DWMCOLORIZATIONCOLORCHANGED: { - UpdateWindowAccentColor(); + UpdateWindowAccentColor(IsActive()); return false; } case WM_SETTINGCHANGE: { @@ -507,7 +507,7 @@ bool NativeWindowViews::PreHandleMSG(UINT message, const wchar_t* setting_name = reinterpret_cast(l_param); std::wstring setting_str(setting_name); if (setting_str == L"ImmersiveColorSet") - UpdateWindowAccentColor(); + UpdateWindowAccentColor(IsActive()); } return false; } @@ -570,7 +570,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { } } -void NativeWindowViews::UpdateWindowAccentColor() { +void NativeWindowViews::UpdateWindowAccentColor(bool active) { if (base::win::GetVersion() < base::win::Version::WIN11) return; @@ -589,7 +589,7 @@ void NativeWindowViews::UpdateWindowAccentColor() { should_apply_accent = std::get(accent_color_); } else if (std::holds_alternative(accent_color_)) { // If no explicit color was set, default to the system accent color. - should_apply_accent = IsAccentColorOnTitleBarsEnabled(); + should_apply_accent = IsAccentColorOnTitleBarsEnabled() && active; } // Use system accent color as fallback if no explicit color was set.