Skip to content

Commit b2ac328

Browse files
committed
PRE-MERGE #17346 Automatically enable AdjustIndistinguishableColors if High Contrast mode enabled
2 parents 44f19bd + f4a355d commit b2ac328

File tree

11 files changed

+42
-7
lines changed

11 files changed

+42
-7
lines changed

src/cascadia/TerminalControl/ControlCore.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
941941
}
942942
}
943943

944+
void ControlCore::SetHighContrastInfo(const bool enabled)
945+
{
946+
_terminal->SetHighContrastInfo(enabled);
947+
}
948+
944949
Control::IControlSettings ControlCore::Settings()
945950
{
946951
return *_settings;

src/cascadia/TerminalControl/ControlCore.h

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
9494

9595
void UpdateSettings(const Control::IControlSettings& settings, const IControlAppearance& newAppearance);
9696
void ApplyAppearance(const bool focused);
97+
void SetHighContrastInfo(const bool enabled);
9798
Control::IControlSettings Settings();
9899
Control::IControlAppearance FocusedAppearance() const;
99100
Control::IControlAppearance UnfocusedAppearance() const;

src/cascadia/TerminalControl/ControlCore.idl

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ namespace Microsoft.Terminal.Control
102102
IControlAppearance FocusedAppearance { get; };
103103
IControlAppearance UnfocusedAppearance { get; };
104104
Boolean HasUnfocusedAppearance();
105+
void SetHighContrastInfo(Boolean enabled);
105106

106107
UInt64 SwapChainHandle { get; };
107108

src/cascadia/TerminalControl/TermControl.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ static Microsoft::Console::TSF::Handle& GetTSFHandle()
150150

151151
namespace winrt::Microsoft::Terminal::Control::implementation
152152
{
153+
Windows::UI::ViewManagement::AccessibilitySettings TermControl::_accessibilitySettings{};
154+
153155
static void _translatePathInPlace(std::wstring& fullPath, PathTranslationStyle translationStyle)
154156
{
155157
static constexpr wil::zwstring_view s_pathPrefixes[] = {
@@ -330,6 +332,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
330332

331333
_core = _interactivity.Core();
332334

335+
// If high contrast mode was changed, update the appearance appropriately.
336+
_accessibilitySettings.HighContrastChanged([this](const Windows::UI::ViewManagement::AccessibilitySettings& a11ySettings, auto&&) {
337+
_core.SetHighContrastInfo(a11ySettings.HighContrast());
338+
_core.ApplyAppearance(_focused);
339+
});
340+
333341
// This event is specifically triggered by the renderer thread, a BG thread. Use a weak ref here.
334342
_revokers.RendererEnteredErrorState = _core.RendererEnteredErrorState(winrt::auto_revoke, { get_weak(), &TermControl::_RendererEnteredErrorState });
335343

src/cascadia/TerminalControl/TermControl.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
238238
friend struct TermControlT<TermControl>; // friend our parent so it can bind private event handlers
239239
friend struct TsfDataProvider;
240240

241+
static Windows::UI::ViewManagement::AccessibilitySettings _accessibilitySettings;
242+
241243
// NOTE: _uiaEngine must be ordered before _core.
242244
//
243245
// ControlCore::AttachUiaEngine receives a IRenderEngine as a raw pointer, which we own.
@@ -362,7 +364,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
362364
};
363365
bool _InitializeTerminal(const InitializeReason reason);
364366
safe_void_coroutine _restoreInBackground();
365-
void _SetFontSize(int fontSize);
366367
void _TappedHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& e);
367368
void _KeyDownHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
368369
void _KeyUpHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::KeyRoutedEventArgs& e);
@@ -394,8 +395,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
394395
void _SwapChainSizeChanged(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::SizeChangedEventArgs& e);
395396
void _SwapChainScaleChanged(const Windows::UI::Xaml::Controls::SwapChainPanel& sender, const Windows::Foundation::IInspectable& args);
396397

397-
void _TerminalTabColorChanged(const std::optional<til::color> color);
398-
399398
void _ScrollPositionChanged(const IInspectable& sender, const Control::ScrollPositionChangedArgs& args);
400399

401400
bool _CapturePointer(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& e);

src/cascadia/TerminalCore/ICoreAppearance.idl

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ namespace Microsoft.Terminal.Core
2323
{
2424
Never,
2525
Indexed,
26-
Always
26+
Always,
27+
Automatic
2728
};
2829

2930
// TerminalCore declares its own Color struct to avoid depending

src/cascadia/TerminalCore/Terminal.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,15 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
141141
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBold, appearance.IntenseIsBold());
142142
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBright, appearance.IntenseIsBright());
143143

144-
switch (appearance.AdjustIndistinguishableColors())
144+
// If AIC is set to Automatic,
145+
// update the value based on if high contrast mode is enabled.
146+
AdjustTextMode deducedAIC = appearance.AdjustIndistinguishableColors();
147+
if (deducedAIC == AdjustTextMode::Automatic)
148+
{
149+
deducedAIC = _highContrastMode ? AdjustTextMode::Indexed : AdjustTextMode::Never;
150+
}
151+
152+
switch (deducedAIC)
145153
{
146154
case AdjustTextMode::Always:
147155
renderSettings.SetRenderMode(RenderSettings::Mode::IndexedDistinguishableColors, false);
@@ -211,6 +219,11 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
211219
_NotifyScrollEvent();
212220
}
213221

222+
void Terminal::SetHighContrastInfo(bool hc) noexcept
223+
{
224+
_highContrastMode = hc;
225+
}
226+
214227
void Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
215228
{
216229
auto& engine = reinterpret_cast<OutputStateMachineEngine&>(_stateMachine->Engine());

src/cascadia/TerminalCore/Terminal.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Microsoft::Terminal::Core::Terminal final :
9292

9393
void UpdateSettings(winrt::Microsoft::Terminal::Core::ICoreSettings settings);
9494
void UpdateAppearance(const winrt::Microsoft::Terminal::Core::ICoreAppearance& appearance);
95+
void SetHighContrastInfo(bool hc) noexcept;
9596
void SetFontInfo(const FontInfo& fontInfo);
9697
void SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle);
9798
void SetVtChecksumReportSupport(const bool enabled);
@@ -382,6 +383,7 @@ class Microsoft::Terminal::Core::Terminal final :
382383

383384
std::wstring _answerbackMessage;
384385
std::wstring _workingDirectory;
386+
bool _highContrastMode = false;
385387

386388
// This default fake font value is only used to check if the font is a raster font.
387389
// Otherwise, the font is changed to a real value with the renderer via TriggerFontChange.

src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

+4
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,10 @@
938938
<value>Always</value>
939939
<comment>An option to choose from for the "adjust indistinguishable colors" setting. When selected, we will adjust the text colors for visibility.</comment>
940940
</data>
941+
<data name="Profile_AdjustIndistinguishableColorsAutomatic.Content" xml:space="preserve">
942+
<value>Automatic</value>
943+
<comment>An option to choose from for the "adjust indistinguishable colors" setting. When selected, we will adjust the text colors for visibility only when the colors are part of this profile's color scheme's color table if and only if high contrast mode is enabled.</comment>
944+
</data>
941945
<data name="Profile_CursorShapeBar.Content" xml:space="preserve">
942946
<value>Bar ( ┃ )</value>
943947
<comment>{Locked="┃"} An option to choose from for the "cursor shape" setting. When selected, the cursor will look like a vertical bar. The character in the parentheses is used to show what it looks like.</comment>

src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::CursorStyle)
3535
// - Helper for converting a user-specified adjustTextMode value to its corresponding enum
3636
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Core::AdjustTextMode)
3737
{
38-
JSON_MAPPINGS(3) = {
38+
JSON_MAPPINGS(4) = {
3939
pair_type{ "never", ValueType::Never },
4040
pair_type{ "indexed", ValueType::Indexed },
4141
pair_type{ "always", ValueType::Always },
42+
pair_type{ "automatic", ValueType::Automatic },
4243
};
4344

4445
// Override mapping parser to add boolean parsing

src/cascadia/inc/ControlProperties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
X(til::color, SelectionBackground, DEFAULT_FOREGROUND) \
1515
X(bool, IntenseIsBold) \
1616
X(bool, IntenseIsBright, true) \
17-
X(winrt::Microsoft::Terminal::Core::AdjustTextMode, AdjustIndistinguishableColors, winrt::Microsoft::Terminal::Core::AdjustTextMode::Never)
17+
X(winrt::Microsoft::Terminal::Core::AdjustTextMode, AdjustIndistinguishableColors, winrt::Microsoft::Terminal::Core::AdjustTextMode::Automatic)
1818

1919
// --------------------------- Control Appearance ---------------------------
2020
// All of these settings are defined in IControlAppearance.

0 commit comments

Comments
 (0)