Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: support window accent color in frameless windows
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere authored Jun 24, 2025
commit aa895795aee0e06f6346851140643e45bb820ec8
2 changes: 2 additions & 0 deletions 2 shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ 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.
Expand Down
1 change: 1 addition & 0 deletions 1 shell/browser/native_window_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class NativeWindowViews : public NativeWindow,
void ResetWindowControls();
void SetRoundedCorners(bool rounded);
void SetForwardMouseMessages(bool forward);
void UpdateWindowAccentColor();
static LRESULT CALLBACK SubclassProc(HWND hwnd,
UINT msg,
WPARAM w_param,
Expand Down
75 changes: 75 additions & 0 deletions 75 shell/browser/native_window_views_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,53 @@ namespace electron {

namespace {

void SetWindowBorderAndCaptionColor(HWND hwnd, COLORREF color) {
if (base::win::GetVersion() < base::win::Version::WIN11)
return;

HRESULT result =
DwmSetWindowAttribute(hwnd, DWMWA_CAPTION_COLOR, &color, sizeof(color));

if (FAILED(result))
LOG(WARNING) << "Failed to set caption color";

result =
DwmSetWindowAttribute(hwnd, DWMWA_BORDER_COLOR, &color, sizeof(color));

if (FAILED(result))
LOG(WARNING) << "Failed to set border color";
}

DWORD GetAccentColor() {
DWORD accent_color = 0;
DWORD color_size = sizeof(accent_color);

HKEY key;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", 0,
KEY_READ, &key) == ERROR_SUCCESS) {
RegQueryValueEx(key, L"AccentColor", NULL, NULL, (LPBYTE)&accent_color,
&color_size);
RegCloseKey(key);
}

return accent_color;
}

bool IsAccentColorOnTitleBarsEnabled() {
DWORD enabled = 0;
DWORD size = sizeof(enabled);

HKEY key;
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\DWM", 0,
KEY_READ, &key) == ERROR_SUCCESS) {
RegQueryValueEx(key, L"ColorPrevalence", NULL, NULL, (LPBYTE)&enabled,
&size);
RegCloseKey(key);
}

return enabled != 0;
}

// Convert Win32 WM_QUERYENDSESSIONS to strings.
const std::vector<std::string> EndSessionToStringVec(LPARAM end_session_id) {
std::vector<std::string> params;
Expand Down Expand Up @@ -450,6 +497,19 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
}
return false;
}
case WM_DWMCOLORIZATIONCOLORCHANGED: {
UpdateWindowAccentColor();
return false;
}
case WM_SETTINGCHANGE: {
if (l_param) {
const wchar_t* setting_name = reinterpret_cast<const wchar_t*>(l_param);
std::wstring setting_str(setting_name);
if (setting_str == L"ImmersiveColorSet")
UpdateWindowAccentColor();
}
return false;
}
default: {
return false;
}
Expand Down Expand Up @@ -509,6 +569,21 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
}
}

void NativeWindowViews::UpdateWindowAccentColor() {
if (base::win::GetVersion() < base::win::Version::WIN11)
return;

// Chromium correctly updates accent color for framed windows.
if (has_frame() || !IsAccentColorOnTitleBarsEnabled())
return;

DWORD accent_color = GetAccentColor();
COLORREF border_color = RGB(GetRValue(accent_color), GetGValue(accent_color),
GetBValue(accent_color));

SetWindowBorderAndCaptionColor(GetAcceleratedWidget(), border_color);
}

void NativeWindowViews::ResetWindowControls() {
// If a given window was minimized and has since been
// unminimized (restored/maximized), ensure the WCO buttons
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.