This commit is contained in:
Mike Griese 2021-10-26 08:59:04 -05:00
parent 282c03c374
commit 6babb4e73a
8 changed files with 21 additions and 121 deletions

View file

@ -95,58 +95,15 @@ namespace winrt::TerminalApp::implementation
_restorePreviewFuncs.clear(); _restorePreviewFuncs.clear();
_ApplyToActiveControls([&](const auto& control) { _ApplyToActiveControls([&](const auto& control) {
// Stash a copy of the original scheme.
auto originalScheme{ control.ColorScheme() }; auto originalScheme{ control.ColorScheme() };
// Apply the new scheme.
control.ColorScheme(scheme.ToCoreScheme()); control.ColorScheme(scheme.ToCoreScheme());
// // Get the settings of the focused control and stash them
// const auto& controlSettings = control.Settings().as<TerminalSettings>();
// // Make sure to recurse up to the root - if you're doing
// // this while you're currently previewing a SetColorScheme
// // action, then the parent of the control's settings is _the
// // last preview TerminalSettings we inserted! We don't want
// // to save that one!
// auto originalSettings = controlSettings.GetParent();
// while (originalSettings.GetParent() != nullptr)
// {
// originalSettings = originalSettings.GetParent();
// }
// // Create a new child for those settings
// TerminalSettingsCreateResult fake{ originalSettings };
// const auto& childStruct = TerminalSettings::CreateWithParent(fake);
// // Modify the child to have the applied color scheme
// childStruct.DefaultSettings().ApplyColorScheme(scheme);
// // Insert that new child as the parent of the control's settings
// controlSettings.SetParent(childStruct.DefaultSettings());
// control.UpdateControlSettings(controlSettings);
// // Take a copy of the inputs, since they are pointers anyways.
_restorePreviewFuncs.emplace_back([=]() { _restorePreviewFuncs.emplace_back([=]() {
// On dismiss, restore the original scheme.
control.ColorScheme(originalScheme); control.ColorScheme(originalScheme);
//// Get the runtime settings of the focused control
//const auto& controlSettings{ control.Settings().as<TerminalSettings>() };
//// Get the control's root settings, the ones that we actually
//// assigned to it.
//auto parentSettings{ controlSettings.GetParent() };
//while (parentSettings.GetParent() != nullptr)
//{
// parentSettings = parentSettings.GetParent();
//}
//// If the root settings are the same as the ones we stashed,
//// then reset the parent of the runtime settings to the stashed
//// settings. This condition might be false if the settings
//// hot-reloaded while the palette was open. In that case, we
//// don't want to reset the settings to what they were _before_
//// the hot-reload.
//if (originalSettings == parentSettings)
//{
// // Set the original settings as the parent of the control's settings
// control.Settings().as<TerminalSettings>().SetParent(originalSettings);
//}
// control.UpdateControlSettings(control.Settings());
}); });
}); });
} }

View file

@ -452,58 +452,7 @@ namespace winrt::TerminalApp::implementation
if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(realArgs.SchemeName())) if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(realArgs.SchemeName()))
{ {
const auto res = _ApplyToActiveControls([&](auto& control) { const auto res = _ApplyToActiveControls([&](auto& control) {
// Core::Scheme coreScheme{};
// coreScheme.Foreground = scheme.Foreground();
// coreScheme.Background = scheme.Background();
// coreScheme.CursorColor = scheme.CursorColor();
// coreScheme.SelectionBackground = scheme.SelectionBackground();
// coreScheme.Black = scheme.Table()[0];
// coreScheme.Red = scheme.Table()[1];
// coreScheme.Green = scheme.Table()[2];
// coreScheme.Yellow = scheme.Table()[3];
// coreScheme.Blue = scheme.Table()[4];
// coreScheme.Purple = scheme.Table()[5];
// coreScheme.Cyan = scheme.Table()[6];
// coreScheme.White = scheme.Table()[7];
// coreScheme.BrightBlack = scheme.Table()[8];
// coreScheme.BrightRed = scheme.Table()[9];
// coreScheme.BrightGreen = scheme.Table()[10];
// coreScheme.BrightYellow = scheme.Table()[11];
// coreScheme.BrightBlue = scheme.Table()[12];
// coreScheme.BrightPurple = scheme.Table()[13];
// coreScheme.BrightCyan = scheme.Table()[14];
// coreScheme.BrightWhite = scheme.Table()[15];
control.ColorScheme(scheme.ToCoreScheme()); control.ColorScheme(scheme.ToCoreScheme());
//// Start by getting the current settings of the control
//auto controlSettings = control.Settings().as<TerminalSettings>();
//auto parentSettings = controlSettings;
//// Those are the _runtime_ settings however. What we
//// need to do is:
////
//// 1. Blow away any colors set in the runtime settings.
//// 2. Apply the color scheme to the parent settings.
////
//// 1 is important to make sure that the effects of
//// something like `colortool` are cleared when setting
//// the scheme.
//if (controlSettings.GetParent() != nullptr)
//{
// parentSettings = controlSettings.GetParent();
//}
//// ApplyColorScheme(nullptr) will clear the old color scheme.
//controlSettings.ApplyColorScheme(nullptr);
//parentSettings.ApplyColorScheme(scheme);
//control.UpdateControlSettings();
// TODO!
// We'll need a dedicated method for this. The Control's
// settings are hosted in the Core, which could be OOP.
// We'll need to manually tell the control to update its
// core's scheme.
}); });
args.Handled(res); args.Handled(res);
} }

View file

@ -1095,7 +1095,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
til::color ControlCore::BackgroundColor() const til::color ControlCore::BackgroundColor() const
{ {
return _terminal->GetDefaultBackground(); // The Terminal internally stores it's BG with 0 opacity, so as to allow
// DX to paint the BG color transparently. We however don't want to leak
// that implementation detail.
return _terminal->GetDefaultBackground().with_alpha(0xff);
} }
// Method Description: // Method Description:
@ -1606,15 +1609,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return s; return s;
} }
void ControlCore::ColorScheme(Core::Scheme scheme) void ControlCore::ColorScheme(const Core::Scheme& scheme)
{ {
_settings->FocusedAppearance()->DefaultForeground(scheme.Foreground); _settings->FocusedAppearance()->DefaultForeground(scheme.Foreground);
// Set the default background as transparent to prevent the _settings->FocusedAppearance()->DefaultBackground(scheme.Background);
// DX layer from overwriting the background image or acrylic effect
til::color newBackgroundColor{ scheme.Background };
// _settings->FocusedAppearance()->DefaultBackground(newBackgroundColor.with_alpha(0));
// _settings->FocusedAppearance()->DefaultBackground(newBackgroundColor);
_settings->FocusedAppearance()->DefaultBackground(newBackgroundColor.with_alpha(255));
_settings->FocusedAppearance()->CursorColor(scheme.CursorColor); _settings->FocusedAppearance()->CursorColor(scheme.CursorColor);
_settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground); _settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground);

View file

@ -66,7 +66,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Control::IControlAppearance FocusedAppearance() const { return *_settings->FocusedAppearance(); }; Control::IControlAppearance FocusedAppearance() const { return *_settings->FocusedAppearance(); };
Control::IControlAppearance UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); }; Control::IControlAppearance UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); };
winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept; winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept;
void ColorScheme(winrt::Microsoft::Terminal::Core::Scheme scheme); void ColorScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme);
void SizeChanged(const double width, const double height); void SizeChanged(const double width, const double height);
void ScaleChanged(const double scale); void ScaleChanged(const double scale);

View file

@ -431,6 +431,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::_InitializeBackgroundBrush() void TermControl::_InitializeBackgroundBrush()
{ {
auto settings{ _core.Settings() }; auto settings{ _core.Settings() };
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff);
if (settings.UseAcrylic()) if (settings.UseAcrylic())
{ {
// See if we've already got an acrylic background brush // See if we've already got an acrylic background brush
@ -446,8 +447,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// see GH#1082: Initialize background color so we don't get a // see GH#1082: Initialize background color so we don't get a
// fade/flash when _BackgroundColorChanged is called // fade/flash when _BackgroundColorChanged is called
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff);
acrylic.FallbackColor(bgColor); acrylic.FallbackColor(bgColor);
acrylic.TintColor(bgColor); acrylic.TintColor(bgColor);
@ -462,8 +461,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
} }
else else
{ {
auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff);
Media::SolidColorBrush solidColor{}; Media::SolidColorBrush solidColor{};
solidColor.Opacity(_core.Opacity()); solidColor.Opacity(_core.Opacity());
solidColor.Color(bgColor); solidColor.Color(bgColor);
@ -487,11 +484,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::fire_and_forget TermControl::_changeBackgroundColor(const til::color bg) winrt::fire_and_forget TermControl::_changeBackgroundColor(const til::color bg)
{ {
auto bg3{ bg };
auto weakThis{ get_weak() }; auto weakThis{ get_weak() };
co_await winrt::resume_foreground(Dispatcher()); co_await winrt::resume_foreground(Dispatcher());
auto bg2{ bg };
bg;
if (auto control{ weakThis.get() }) if (auto control{ weakThis.get() })
{ {
if (auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>()) if (auto acrylic = RootGrid().Background().try_as<Media::AcrylicBrush>())
@ -2606,7 +2600,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core.ColorScheme(); return _core.ColorScheme();
} }
void TermControl::ColorScheme(Core::Scheme scheme) const noexcept void TermControl::ColorScheme(const Core::Scheme& scheme) const noexcept
{ {
_core.ColorScheme(scheme); _core.ColorScheme(scheme);
} }

View file

@ -113,7 +113,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
hstring ReadEntireBuffer() const; hstring ReadEntireBuffer() const;
winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept; winrt::Microsoft::Terminal::Core::Scheme ColorScheme() const noexcept;
void ColorScheme(winrt::Microsoft::Terminal::Core::Scheme scheme) const noexcept; void ColorScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme) const noexcept;
// -------------------------------- WinRT Events --------------------------------- // -------------------------------- WinRT Events ---------------------------------
// clang-format off // clang-format off

View file

@ -1299,10 +1299,13 @@ Scheme Terminal::GetColorScheme() const noexcept
Scheme s; Scheme s;
s.Foreground = til::color{ _defaultFg }; s.Foreground = til::color{ _defaultFg };
s.Background = til::color{ _defaultBg }; // Don't leak the implementation detail that our _defaultBg is stored
// internally without alpha.
s.Background = til::color{ _defaultBg.with_alpha(0xff) };
// SelectionBackground is stored in the ControlAppearance // SelectionBackground is stored in the ControlAppearance
// s.SelectionBackground;
s.CursorColor = til::color{ _buffer->GetCursor().GetColor() }; s.CursorColor = til::color{ _buffer->GetCursor().GetColor() };
s.Black = til::color{ _colorTable[0] }; s.Black = til::color{ _colorTable[0] };
s.Red = til::color{ _colorTable[1] }; s.Red = til::color{ _colorTable[1] };
s.Green = til::color{ _colorTable[2] }; s.Green = til::color{ _colorTable[2] };
@ -1322,7 +1325,7 @@ Scheme Terminal::GetColorScheme() const noexcept
return s; return s;
} }
void Terminal::ApplyScheme(Scheme colorScheme) void Terminal::ApplyScheme(const Scheme& colorScheme)
{ {
_defaultFg = colorScheme.Foreground; _defaultFg = colorScheme.Foreground;
// Set the default background as transparent to prevent the // Set the default background as transparent to prevent the
@ -1353,5 +1356,4 @@ void Terminal::ApplyScheme(Scheme colorScheme)
{ {
_MakeAdjustedColorArray(); _MakeAdjustedColorArray();
} }
} }

View file

@ -223,7 +223,7 @@ public:
til::color GetDefaultBackground() const noexcept; til::color GetDefaultBackground() const noexcept;
winrt::Microsoft::Terminal::Core::Scheme GetColorScheme() const noexcept; winrt::Microsoft::Terminal::Core::Scheme GetColorScheme() const noexcept;
void ApplyScheme(winrt::Microsoft::Terminal::Core::Scheme scheme); void ApplyScheme(const winrt::Microsoft::Terminal::Core::Scheme& scheme);
Microsoft::Console::Render::BlinkingState& GetBlinkingState() const noexcept; Microsoft::Console::Render::BlinkingState& GetBlinkingState() const noexcept;