Repository: electron/electron
Pull request: fix: window `accentColor` should adhere to native window behavior

#### Description of Change

Closes https://github.com/electron/electron/issues/47723.

Fixes an issue where the accent border was drawn on all windows regardless of the window's active focused status. As of this PR by default the accent border will be drawn on active frameless windows unless the user specified `accentColor: true` or a color in which case it will be drawn on all windows.

cc @bpasero 

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

#### Release Notes

Notes: Fixes an issue where the accent border was drawn on all windows regardless of the window's active focused status.

Changed files:
filename: shell/browser/native_window_views.cc
patch: @@ -420,8 +420,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.
@@ -1732,6 +1730,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);

filename: shell/browser/native_window_views.h
patch: @@ -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,

filename: shell/browser/native_window_views_win.cc
patch: @@ -499,15 +499,15 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
       return false;
     }
     case WM_DWMCOLORIZATIONCOLORCHANGED: {
-      UpdateWindowAccentColor();
+      UpdateWindowAccentColor(IsActive());
       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();
+          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<bool>(accent_color_);
   } else if (std::holds_alternative<std::monostate>(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.