Skip to content

Commit 7cd9f7d

Browse files
committed
PRE-MERGE #17346 Automatically enable AdjustIndistinguishableColors if High Contrast mode enabled
2 parents a093ca3 + bddd619 commit 7cd9f7d

File tree

12 files changed

+48
-8
lines changed

12 files changed

+48
-8
lines changed

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
955955
}
956956
}
957957

958+
void ControlCore::SetHighContrastInfo(const bool enabled)
959+
{
960+
_terminal->SetHighContrastInfo(enabled);
961+
}
962+
958963
Control::IControlSettings ControlCore::Settings()
959964
{
960965
return *_settings;

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ static Microsoft::Console::TSF::Handle& GetTSFHandle()
9090

9191
namespace winrt::Microsoft::Terminal::Control::implementation
9292
{
93+
Windows::UI::ViewManagement::AccessibilitySettings TermControl::_accessibilitySettings{};
94+
9395
static void _translatePathInPlace(std::wstring& fullPath, PathTranslationStyle translationStyle)
9496
{
9597
static constexpr wil::zwstring_view s_pathPrefixes[] = {
@@ -276,6 +278,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
276278

277279
_core = _interactivity.Core();
278280

281+
// If high contrast mode was changed, update the appearance appropriately.
282+
_core.SetHighContrastInfo(_accessibilitySettings.HighContrast());
283+
_revokers.HighContrastChanged = _accessibilitySettings.HighContrastChanged(winrt::auto_revoke, [weakThis{ get_weak() }](const Windows::UI::ViewManagement::AccessibilitySettings& a11ySettings, auto&&) {
284+
if (auto termControl = weakThis.get())
285+
{
286+
termControl->_core.SetHighContrastInfo(a11ySettings.HighContrast());
287+
termControl->_core.ApplyAppearance(termControl->_focused);
288+
}
289+
});
290+
279291
// This event is specifically triggered by the renderer thread, a BG thread. Use a weak ref here.
280292
_revokers.RendererEnteredErrorState = _core.RendererEnteredErrorState(winrt::auto_revoke, { get_weak(), &TermControl::_RendererEnteredErrorState });
281293

src/cascadia/TerminalControl/TermControl.h

Lines changed: 3 additions & 3 deletions
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);
@@ -480,6 +479,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
480479
// These are set up in _InitializeTerminal
481480
Control::ControlCore::RendererWarning_revoker RendererWarning;
482481
Control::ControlCore::SwapChainChanged_revoker SwapChainChanged;
482+
Windows::UI::ViewManagement::AccessibilitySettings::HighContrastChanged_revoker HighContrastChanged;
483483

484484
Control::ControlInteractivity::OpenHyperlink_revoker interactivityOpenHyperlink;
485485
Control::ControlInteractivity::ScrollPositionChanged_revoker interactivityScrollPositionChanged;

src/cascadia/TerminalCore/ICoreAppearance.idl

Lines changed: 2 additions & 1 deletion
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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ void Terminal::UpdateAppearance(const ICoreAppearance& appearance)
143143
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBold, appearance.IntenseIsBold());
144144
renderSettings.SetRenderMode(RenderSettings::Mode::IntenseIsBright, appearance.IntenseIsBright());
145145

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

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

src/cascadia/TerminalCore/Terminal.hpp

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,10 @@
942942
<value>Always</value>
943943
<comment>An option to choose from for the "adjust indistinguishable colors" setting. When selected, we will adjust the text colors for visibility.</comment>
944944
</data>
945+
<data name="Profile_AdjustIndistinguishableColorsAutomatic.Content" xml:space="preserve">
946+
<value>Automatic</value>
947+
<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>
948+
</data>
945949
<data name="Profile_CursorShapeBar.Content" xml:space="preserve">
946950
<value>Bar ( ┃ )</value>
947951
<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/MTSMSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Author(s):
136136
X(ConvergedAlignment, BackgroundImageAlignment, "backgroundImageAlignment", ConvergedAlignment::Horizontal_Center | ConvergedAlignment::Vertical_Center) \
137137
X(hstring, BackgroundImagePath, "backgroundImage") \
138138
X(Model::IntenseStyle, IntenseTextStyle, "intenseTextStyle", Model::IntenseStyle::Bright) \
139-
X(Core::AdjustTextMode, AdjustIndistinguishableColors, "adjustIndistinguishableColors", Core::AdjustTextMode::Never) \
139+
X(Core::AdjustTextMode, AdjustIndistinguishableColors, "adjustIndistinguishableColors", Core::AdjustTextMode::Automatic) \
140140
X(bool, UseAcrylic, "useAcrylic", false)
141141

142142
// Intentionally omitted Appearance settings:

0 commit comments

Comments
 (0)