-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable changing the color of the active pane border #3752
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,11 @@ class TerminalApp::GlobalAppSettings final | |
|
||
void ApplyToSettings(winrt::Microsoft::Terminal::Settings::TerminalSettings& settings) const noexcept; | ||
|
||
bool HasPaneFocusBorderColor() const noexcept; | ||
bool IsPaneFocusColorAccentColor() const noexcept; | ||
COLORREF GetPaneFocusColor() const; | ||
void SetPaneFocusColor(std::optional<std::wstring> newValue); | ||
|
||
private: | ||
GUID _defaultProfile; | ||
winrt::com_ptr<winrt::TerminalApp::implementation::AppKeyBindings> _keybindings; | ||
|
@@ -96,8 +101,8 @@ class TerminalApp::GlobalAppSettings final | |
std::wstring _wordDelimiters; | ||
bool _copyOnSelect; | ||
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme; | ||
|
||
winrt::TerminalApp::LaunchMode _launchMode; | ||
std::optional<std::wstring> _activePaneBorderColor{ std::nullopt }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the rest of these private variables are initialized here. Are they initialized in the constructor instead? |
||
|
||
static winrt::Windows::UI::Xaml::ElementTheme _ParseTheme(const std::wstring& themeString) noexcept; | ||
static std::wstring_view _SerializeTheme(const winrt::Windows::UI::Xaml::ElementTheme theme) noexcept; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#include "Pane.h" | ||
#include "Profile.h" | ||
#include "CascadiaSettings.h" | ||
#include "../../WinRTUtils/inc/Utils.h" | ||
|
||
#include "winrt/Microsoft.Terminal.TerminalConnection.h" | ||
|
||
|
@@ -545,6 +546,13 @@ void Pane::UpdateSettings(const TerminalSettings& settings, const GUID& profile) | |
{ | ||
_control.UpdateSettings(settings); | ||
} | ||
|
||
_root.Dispatcher().RunAsync(CoreDispatcherPriority::Low, [this]() { | ||
// Call _SetupResources to potentially reload the active pane brush, | ||
// and UpdateVisuals to apply the brush | ||
_SetupResources(); | ||
UpdateVisuals(); | ||
}); | ||
Comment on lines
+550
to
+555
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a good use for the |
||
} | ||
} | ||
|
||
|
@@ -1111,36 +1119,61 @@ void Pane::_ControlGotFocusHandler(winrt::Windows::Foundation::IInspectable cons | |
void Pane::_SetupResources() | ||
{ | ||
const auto res = Application::Current().Resources(); | ||
const auto accentColorKey = winrt::box_value(L"SystemAccentColor"); | ||
if (res.HasKey(accentColorKey)) | ||
|
||
// First setup the pane border TabViewBackground color | ||
const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground"); | ||
if (res.HasKey(tabViewBackgroundKey)) | ||
{ | ||
const auto colorFromResources = res.Lookup(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) | ||
auto actualColor = winrt::unbox_value_or<Color>(colorFromResources, Colors::Black()); | ||
s_focusedBorderBrush = SolidColorBrush(actualColor); | ||
winrt::Windows::Foundation::IInspectable obj = res.Lookup(tabViewBackgroundKey); | ||
s_unfocusedBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>(); | ||
} | ||
else | ||
{ | ||
// DON'T use Transparent here - if it's "Transparent", then it won't | ||
// be able to hittest for clicks, and then clicking on the border | ||
// will eat focus. | ||
s_focusedBorderBrush = SolidColorBrush{ Colors::Black() }; | ||
s_unfocusedBorderBrush = SolidColorBrush{ Colors::Black() }; | ||
} | ||
|
||
const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground"); | ||
if (res.HasKey(accentColorKey)) | ||
// Now try and set the pane border color. | ||
// - If it's null, we'll use the TabViewBackground color. | ||
// - if it's "accent", we'll use the accent color | ||
// - if it's "#rrbbgg", we'll use the given color | ||
const auto& settings = CascadiaSettings::GetCurrentAppSettings(); | ||
const auto& globals = settings.GlobalSettings(); | ||
if (!globals.HasPaneFocusBorderColor()) | ||
{ | ||
winrt::Windows::Foundation::IInspectable obj = res.Lookup(tabViewBackgroundKey); | ||
s_unfocusedBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>(); | ||
s_focusedBorderBrush = s_unfocusedBorderBrush; | ||
} | ||
else | ||
{ | ||
// DON'T use Transparent here - if it's "Transparent", then it won't | ||
// be able to hittest for clicks, and then clicking on the border | ||
// will eat focus. | ||
s_unfocusedBorderBrush = SolidColorBrush{ Colors::Black() }; | ||
if (globals.IsPaneFocusColorAccentColor()) | ||
{ | ||
// Use the accent color for the pane border | ||
|
||
const auto accentColorKey = winrt::box_value(L"SystemAccentColor"); | ||
if (res.HasKey(accentColorKey)) | ||
{ | ||
const auto colorFromResources = res.Lookup(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) | ||
auto actualColor = winrt::unbox_value_or<Color>(colorFromResources, Colors::Black()); | ||
s_focusedBorderBrush = SolidColorBrush(actualColor); | ||
} | ||
else | ||
{ | ||
// DON'T use Transparent here - see earlier comment for why | ||
s_focusedBorderBrush = s_unfocusedBorderBrush; | ||
} | ||
} | ||
else | ||
{ | ||
// Create a brush for the color the user specified | ||
const COLORREF focusColor = globals.GetPaneFocusColor(); | ||
s_focusedBorderBrush = Media::SolidColorBrush{}; | ||
s_focusedBorderBrush.Color(ColorRefToColor(focusColor)); | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment why you did this or use UNREFERENCED_PARAMETER macro to make it clear.