Repository: microsoft/terminal (language: cpp)

Issue:
Support using different colors in the titlebar for focused/unfocused windows
# Description of the new feature/enhancement

*Context*
When working on large monitors it is possible to have up to 6 windows in tiled mode. It is useful to know which one will pick up the keyboard actions without mouse or alt-tab hunting. For that it would be useful to have a different title bar color for the active window to distinguish it from all the other windows.

*Solution on Windows*
One can pick a color for the active window (`HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM\AccentColor`, say soft blue, can be done through settings)
 and a color for inactive windows (`HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM\AccentColorInactive`, say light gray,  in windows 10 can be done through regedit only)

Applications that work with the two values above: Windows Explorer, Registry Editor, Total Commander, Mozilla Firefox (default theme), Google Chrome (default theme).

Terminal seems to not work with the two values.

That may be at odds with the application identity. (The discontinued Microsoft Edge 44 used the same gray as a strong identity element, Microsoft Office programs also boldly state color identity and ignore `AccentColorInactive`, VSCode states identity as boldly, however it displays the titlebar in a different color when inactive).
Nevertheless, screens only get larger and the use-case described above is likely to become more common.

In terms of how to implement that for Terminal, which displays tabs on the title bar, Firefox has the solution of using the accent color on all inactive tabs and highlighting the active tab using a brighter color. Chrome does the same.



Discussion / hints:
Thanks for the suggestion! I'm going to track this as a part of #3327, which is our megathread for adding even more customization to the Terminal. This request fits in nicely with a lot of the other work being done there.
I think the active titlebar color was in effect when I am using WT without tab (setting: "globals":{"alwaysShowTabs":false, "showTabsInTitlebar": false} ), but it was with before than or equal to version 0.10 .
With 0.11, I cannot completely hide the tabs, so this issue is more important.
> I cannot completely hide the tabs

This behavior hasn't changed in 0.11, you're just running into the settings file changes we made. #5458 for more info.
Thank you @DHowett-MSFT, I moved "globals" setting to root, and I got the original effect.
The titlebar color is in effect when with no tabs and tabs not in titlebar ("showTabsInTitlebar":false).
Instead, the titlebar color is not in effect when tabs in titlebar ("showTabsInTitlebar":true (this is the default)).
I'm a new comer to Windows Terminal and have found it to be a revelation, especially when you combine being able to use beautiful fonts like Cascadia or Nerd Fonts. However, my heart sinks when I see that drab battleship grey for the title bar colour. What gets me is that there must have been an active decision to make it grey as opposed to leave it to the system default of using accent colours defined in systems settings.

Whilst issue #3327 is being considered for development, I would hope in the mean time we could see a simple stop-gap solution being applied where Terminal just uses the Accent colours as defined in system settings.
^yeah. #3327 is very different
> "…Microsoft Office programs also boldly state color identity and ignore AccentColorInactive…"

I have been googling for _many hours_ trying to find a solution for making it possible to identify an **active** / **in-active** Office 365 application.
I am surprised of the lack of such basic functionality (it was possible in Win2k and likely even before that) to make it easy to identify which window actually have focus (hence gets the keyboard events).

This is totally of-topic for this Terminal-issue (sorry), but since we have the attention of some fine Microsoft engineers working on good stuff (linux) PLEASE let me know where to post this wish in the hopes that I can wake up who ever fell asleep in the "UX for beginners" class 
And Terminal's title bar elements don't dim when the window is inactive. Should I create an issue for this (if there isn't one already)?
That is tracked at the root of issue #1625. Thanks! :smile:
this is actually just like #1963
There's a subtle difference between this and #1963 - that one just wants to be able to set a custom titlebar color. This one wants to be able to set custom titlebar color when focused, and a _different_ color when unfocused.
note to self: The old colors in #12635 might be good candidates for the inactive window colors. We may be able to do that following the sameish steps as in https://github.com/microsoft/terminal/issues/12632#issuecomment-1060678947, without adding the rest of the theming settings. 

Fix patch:
diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp
index e9d5324bcb3..9f0c42cf66f 100644
--- a/src/cascadia/TerminalApp/TerminalPage.cpp
+++ b/src/cascadia/TerminalApp/TerminalPage.cpp
@@ -4101,24 +4101,27 @@ namespace winrt::TerminalApp::implementation
 
             TitlebarBrush(acrylicBrush);
         }
-        else if (theme.TabRow() && theme.TabRow().Background())
+        else if (theme.TabRow())
         {
-            const auto tabRowBg = theme.TabRow().Background();
-            const auto terminalBrush = [this]() -> Media::Brush {
-                if (const auto& control{ _GetActiveControl() })
-                {
-                    return control.BackgroundBrush();
-                }
-                else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
-                {
-                    return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
-                }
-                return nullptr;
-            }();
+            if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
+                                                  theme.TabRow().UnfocusedBackground() })
+            {
+                const auto terminalBrush = [this]() -> Media::Brush {
+                    if (const auto& control{ _GetActiveControl() })
+                    {
+                        return control.BackgroundBrush();
+                    }
+                    else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
+                    {
+                        return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
+                    }
+                    return nullptr;
+                }();
 
-            const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
-            bgColor = ThemeColor::ColorFromBrush(themeBrush);
-            TitlebarBrush(themeBrush);
+                const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
+                bgColor = ThemeColor::ColorFromBrush(themeBrush);
+                TitlebarBrush(themeBrush);
+            }
         }
         else
         {
diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h
index b131cf59ad7..5aded2c6ee5 100644
--- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h
+++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h
@@ -124,8 +124,9 @@ Author(s):
     X(winrt::Windows::UI::Xaml::ElementTheme, RequestedTheme, "applicationTheme", winrt::Windows::UI::Xaml::ElementTheme::Default) \
     X(bool, UseMica, "useMica", false)
 
-#define MTSM_THEME_TABROW_SETTINGS(X) \
-    X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
+#define MTSM_THEME_TABROW_SETTINGS(X)                                                             \
+    X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
+    X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr)
 
 #define MTSM_THEME_TAB_SETTINGS(X) \
     X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
diff --git a/src/cascadia/TerminalSettingsModel/Theme.cpp b/src/cascadia/TerminalSettingsModel/Theme.cpp
index 27826d6bb4e..46e7b52f71a 100644
--- a/src/cascadia/TerminalSettingsModel/Theme.cpp
+++ b/src/cascadia/TerminalSettingsModel/Theme.cpp
@@ -104,6 +104,10 @@ winrt::WUX::Media::Brush ThemeColor::Evaluate(const winrt::WUX::ResourceDictiona
     {
     case ThemeColorType::Accent:
     {
+        // NOTE: There is no canonical way to get the unfocused ACCENT titlebar
+        // color in Windows. Edge uses it's own heuristic, and in Windows 11,
+        // much of this logic is rapidly changing. We're not gonna mess with
+        // that, since it seems there's no good way to reverse engineer that.
         til::color accentColor = forTitlebar ?
                                      _getAccentColorForTitlebar() :
                                      til::color{ winrt::unbox_value<winrt::Windows::UI::Color>(res.Lookup(accentColorKey)) };
diff --git a/src/cascadia/TerminalSettingsModel/Theme.idl b/src/cascadia/TerminalSettingsModel/Theme.idl
index 5c295f7df6a..45df3c0c4a4 100644
--- a/src/cascadia/TerminalSettingsModel/Theme.idl
+++ b/src/cascadia/TerminalSettingsModel/Theme.idl
@@ -34,6 +34,7 @@ namespace Microsoft.Terminal.Settings.Model
 
     runtimeclass TabRowTheme {
         ThemeColor Background { get; };
+        ThemeColor UnfocusedBackground { get; };
     }
 
     runtimeclass TabTheme {


Test patch: