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.
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_;

View File

@@ -574,28 +574,42 @@ void NativeWindowViews::UpdateWindowAccentColor() {
if (base::win::GetVersion() < base::win::Version::WIN11)
return;
if (!IsAccentColorOnTitleBarsEnabled())
return;
COLORREF border_color;
bool should_apply_accent = false;
if (std::holds_alternative<bool>(accent_color_)) {
// Don't set accent color if the user has disabled it.
if (!std::get<bool>(accent_color_))
return;
std::optional<DWORD> accent_color = GetAccentColor();
if (!accent_color.has_value())
return;
border_color =
RGB(GetRValue(accent_color.value()), GetGValue(accent_color.value()),
GetBValue(accent_color.value()));
} else {
bool force_accent = std::get<bool>(accent_color_);
if (!force_accent) {
should_apply_accent = false;
} else {
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;
}
}
} else if (std::holds_alternative<SkColor>(accent_color_)) {
SkColor color = std::get<SkColor>(accent_color_);
border_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);
}