fix: accent color should reflect system settings without restart (#47629)

fix: accentColor should reflect system settings without restart
This commit is contained in:
Shelley Vohr
2025-07-03 18:13:39 +02:00
committed by GitHub
parent bc585b6a3f
commit 5ef6897bc7
2 changed files with 30 additions and 16 deletions

View File

@@ -319,7 +319,7 @@ class NativeWindowViews : public NativeWindow,
// Whether the window is currently being moved. // Whether the window is currently being moved.
bool is_moving_ = false; bool is_moving_ = false;
std::variant<bool, SkColor> accent_color_ = true; std::variant<std::monostate, bool, SkColor> accent_color_;
std::optional<gfx::Rect> pending_bounds_change_; std::optional<gfx::Rect> pending_bounds_change_;

View File

@@ -574,28 +574,42 @@ void NativeWindowViews::UpdateWindowAccentColor() {
if (base::win::GetVersion() < base::win::Version::WIN11) if (base::win::GetVersion() < base::win::Version::WIN11)
return; return;
if (!IsAccentColorOnTitleBarsEnabled())
return;
COLORREF border_color; COLORREF border_color;
bool should_apply_accent = false;
if (std::holds_alternative<bool>(accent_color_)) { if (std::holds_alternative<bool>(accent_color_)) {
// Don't set accent color if the user has disabled it. bool force_accent = std::get<bool>(accent_color_);
if (!std::get<bool>(accent_color_)) if (!force_accent) {
return; should_apply_accent = false;
} else {
std::optional<DWORD> accent_color = GetAccentColor(); std::optional<DWORD> accent_color = GetAccentColor();
if (!accent_color.has_value()) if (accent_color.has_value()) {
return; border_color = RGB(GetRValue(accent_color.value()),
GetGValue(accent_color.value()),
border_color = GetBValue(accent_color.value()));
RGB(GetRValue(accent_color.value()), GetGValue(accent_color.value()), should_apply_accent = true;
GetBValue(accent_color.value())); }
} else { }
} else if (std::holds_alternative<SkColor>(accent_color_)) {
SkColor color = std::get<SkColor>(accent_color_); SkColor color = std::get<SkColor>(accent_color_);
border_color = border_color =
RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color)); RGB(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color));
should_apply_accent = true;
} else if (std::holds_alternative<std::monostate>(accent_color_)) {
if (IsAccentColorOnTitleBarsEnabled()) {
std::optional<DWORD> accent_color = GetAccentColor();
if (accent_color.has_value()) {
border_color = RGB(GetRValue(accent_color.value()),
GetGValue(accent_color.value()),
GetBValue(accent_color.value()));
should_apply_accent = true;
}
}
} }
// Reset to default system colors when accent color should not be applied.
if (!should_apply_accent)
border_color = DWMWA_COLOR_DEFAULT;
SetWindowBorderAndCaptionColor(GetAcceleratedWidget(), border_color); SetWindowBorderAndCaptionColor(GetAcceleratedWidget(), border_color);
} }