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

fix: accentColor should reflect system settings without restart

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-07-04 10:57:23 +02:00 committed by GitHub
parent ceefcd1d32
commit e39cf315dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 16 deletions

View file

@ -305,7 +305,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

@ -572,28 +572,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);
}