mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-15 16:40:12 -06:00
Make the Pane inactive border respect the theme.window.applicationTheme (#14486)
We couldn't do this before, because `App::Current().Resources().Lookup()` would always return the OS theme version of a resource. That thread has lengthy details on why. FORTUNATELY FOR US, this isn't the first time we've dealt with this. We've come up with a workaround in the past, and we can just use it again here. Closes #3917 This will also make #3061 easy 😉
This commit is contained in:
parent
4d27a05318
commit
84bb98bc81
@ -153,7 +153,7 @@
|
||||
Color="#2e2e2e" />
|
||||
|
||||
<StaticResource x:Key="UnfocusedBorderBrush"
|
||||
ResourceKey="ApplicationPageBackgroundThemeBrush" />
|
||||
ResourceKey="TabViewBackground" />
|
||||
|
||||
<SolidColorBrush x:Key="SettingsUiTabBrush"
|
||||
Color="#0c0c0c" />
|
||||
@ -169,7 +169,7 @@
|
||||
Color="#e8e8e8" />
|
||||
|
||||
<StaticResource x:Key="UnfocusedBorderBrush"
|
||||
ResourceKey="ApplicationPageBackgroundThemeBrush" />
|
||||
ResourceKey="TabViewBackground" />
|
||||
|
||||
<SolidColorBrush x:Key="SettingsUiTabBrush"
|
||||
Color="#ffffff" />
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
#include "Pane.h"
|
||||
#include "AppLogic.h"
|
||||
|
||||
#include "Utils.h"
|
||||
|
||||
#include <Mmsystem.h>
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
@ -46,14 +48,6 @@ Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFo
|
||||
_warningBellToken = _control.WarningBell({ this, &Pane::_ControlWarningBellHandler });
|
||||
_closeTerminalRequestedToken = _control.CloseTerminalRequested({ this, &Pane::_CloseTerminalRequestedHandler });
|
||||
|
||||
// On the first Pane's creation, lookup resources we'll use to theme the
|
||||
// Pane, including the brushed to use for the focused/unfocused border
|
||||
// color.
|
||||
if (s_focusedBorderBrush == nullptr || s_unfocusedBorderBrush == nullptr)
|
||||
{
|
||||
_SetupResources();
|
||||
}
|
||||
|
||||
// Register an event with the control to have it inform us when it gains focus.
|
||||
_gotFocusRevoker = _control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler });
|
||||
_lostFocusRevoker = _control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler });
|
||||
@ -3104,16 +3098,16 @@ float Pane::_ClampSplitPosition(const bool widthOrHeight, const float requestedV
|
||||
// * The Brush we'll use for inactive Panes - TabViewBackground (to match the
|
||||
// color of the titlebar)
|
||||
// Arguments:
|
||||
// - <none>
|
||||
// - requestedTheme: this should be the currently active Theme for the app
|
||||
// Return Value:
|
||||
// - <none>
|
||||
void Pane::_SetupResources()
|
||||
void Pane::SetupResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme)
|
||||
{
|
||||
const auto res = Application::Current().Resources();
|
||||
const auto accentColorKey = winrt::box_value(L"SystemAccentColor");
|
||||
if (res.HasKey(accentColorKey))
|
||||
{
|
||||
const auto colorFromResources = res.Lookup(accentColorKey);
|
||||
const auto colorFromResources = ThemeLookup(res, requestedTheme, accentColorKey);
|
||||
// If SystemAccentColor is _not_ a Color for some reason, use
|
||||
// Transparent as the color, so we don't do this process again on
|
||||
// the next pane (by leaving s_focusedBorderBrush nullptr)
|
||||
@ -3131,7 +3125,10 @@ void Pane::_SetupResources()
|
||||
const auto unfocusedBorderBrushKey = winrt::box_value(L"UnfocusedBorderBrush");
|
||||
if (res.HasKey(unfocusedBorderBrushKey))
|
||||
{
|
||||
auto obj = res.Lookup(unfocusedBorderBrushKey);
|
||||
// MAKE SURE TO USE ThemeLookup, so that we get the correct resource for
|
||||
// the requestedTheme, not just the value from the resources (which
|
||||
// might not respect the settings' requested theme)
|
||||
auto obj = ThemeLookup(res, requestedTheme, unfocusedBorderBrushKey);
|
||||
s_unfocusedBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
|
||||
}
|
||||
else
|
||||
|
||||
@ -136,6 +136,8 @@ public:
|
||||
|
||||
bool ContainsReadOnly() const;
|
||||
|
||||
static void SetupResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme);
|
||||
|
||||
// Method Description:
|
||||
// - A helper method for ad-hoc recursion on a pane tree. Walks the pane
|
||||
// tree, calling a function on each pane in a depth-first pattern.
|
||||
@ -339,8 +341,6 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
static void _SetupResources();
|
||||
|
||||
struct PanePoint
|
||||
{
|
||||
float x;
|
||||
|
||||
@ -4175,6 +4175,22 @@ namespace winrt::TerminalApp::implementation
|
||||
const auto theme = _settings.GlobalSettings().CurrentTheme();
|
||||
auto requestedTheme{ theme.RequestedTheme() };
|
||||
|
||||
{
|
||||
// Update the brushes that Pane's use...
|
||||
Pane::SetupResources(requestedTheme);
|
||||
// ... then trigger a visual update for all the pane borders to
|
||||
// apply the new ones.
|
||||
for (const auto& tab : _tabs)
|
||||
{
|
||||
if (auto terminalTab{ _GetTerminalTabImpl(tab) })
|
||||
{
|
||||
terminalTab->GetRootPane()->WalkTree([&](auto&& pane) {
|
||||
pane->UpdateVisuals();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto res = Application::Current().Resources();
|
||||
|
||||
// Use our helper to lookup the theme-aware version of the resource.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user