diff --git a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp index 79e5461f2..ecc826be4 100644 --- a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp +++ b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp @@ -95,58 +95,15 @@ namespace winrt::TerminalApp::implementation _restorePreviewFuncs.clear(); _ApplyToActiveControls([&](const auto& control) { + // Stash a copy of the original scheme. auto originalScheme{ control.ColorScheme() }; + + // Apply the new scheme. control.ColorScheme(scheme.ToCoreScheme()); - // // Get the settings of the focused control and stash them - // const auto& controlSettings = control.Settings().as(); - // // 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([=]() { + // On dismiss, restore the original scheme. control.ColorScheme(originalScheme); - //// Get the runtime settings of the focused control - //const auto& controlSettings{ control.Settings().as() }; - - //// 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().SetParent(originalSettings); - //} - - // control.UpdateControlSettings(control.Settings()); }); }); } diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index 95b2a858f..cc36c6e93 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -452,58 +452,7 @@ namespace winrt::TerminalApp::implementation if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(realArgs.SchemeName())) { 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()); - //// Start by getting the current settings of the control - //auto controlSettings = control.Settings().as(); - //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); } diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index cb0d82c38..6c70371af 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1095,7 +1095,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation 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: @@ -1606,15 +1609,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation return s; } - void ControlCore::ColorScheme(Core::Scheme scheme) + void ControlCore::ColorScheme(const Core::Scheme& scheme) { _settings->FocusedAppearance()->DefaultForeground(scheme.Foreground); - // Set the default background as transparent to prevent the - // 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()->DefaultBackground(scheme.Background); _settings->FocusedAppearance()->CursorColor(scheme.CursorColor); _settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground); diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 36644f790..4007cdbbf 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -66,7 +66,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation Control::IControlAppearance FocusedAppearance() const { return *_settings->FocusedAppearance(); }; Control::IControlAppearance UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); }; 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 ScaleChanged(const double scale); diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 417d4ef86..b37528348 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -431,6 +431,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation void TermControl::_InitializeBackgroundBrush() { auto settings{ _core.Settings() }; + auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff); if (settings.UseAcrylic()) { // 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 // fade/flash when _BackgroundColorChanged is called - auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff); - acrylic.FallbackColor(bgColor); acrylic.TintColor(bgColor); @@ -462,8 +461,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation } else { - auto bgColor = til::color{ _core.FocusedAppearance().DefaultBackground() }.with_alpha(0xff); - Media::SolidColorBrush solidColor{}; solidColor.Opacity(_core.Opacity()); solidColor.Color(bgColor); @@ -487,11 +484,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation winrt::fire_and_forget TermControl::_changeBackgroundColor(const til::color bg) { - auto bg3{ bg }; auto weakThis{ get_weak() }; co_await winrt::resume_foreground(Dispatcher()); - auto bg2{ bg }; - bg; if (auto control{ weakThis.get() }) { if (auto acrylic = RootGrid().Background().try_as()) @@ -2606,7 +2600,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation return _core.ColorScheme(); } - void TermControl::ColorScheme(Core::Scheme scheme) const noexcept + void TermControl::ColorScheme(const Core::Scheme& scheme) const noexcept { _core.ColorScheme(scheme); } diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 5cce42cc1..ff42ae266 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -113,7 +113,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation hstring ReadEntireBuffer() const; 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 --------------------------------- // clang-format off diff --git a/src/cascadia/TerminalCore/Terminal.cpp b/src/cascadia/TerminalCore/Terminal.cpp index eb1794be2..3957f8a29 100644 --- a/src/cascadia/TerminalCore/Terminal.cpp +++ b/src/cascadia/TerminalCore/Terminal.cpp @@ -1299,10 +1299,13 @@ Scheme Terminal::GetColorScheme() const noexcept Scheme s; 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 - // s.SelectionBackground; s.CursorColor = til::color{ _buffer->GetCursor().GetColor() }; + s.Black = til::color{ _colorTable[0] }; s.Red = til::color{ _colorTable[1] }; s.Green = til::color{ _colorTable[2] }; @@ -1322,7 +1325,7 @@ Scheme Terminal::GetColorScheme() const noexcept return s; } -void Terminal::ApplyScheme(Scheme colorScheme) +void Terminal::ApplyScheme(const Scheme& colorScheme) { _defaultFg = colorScheme.Foreground; // Set the default background as transparent to prevent the @@ -1353,5 +1356,4 @@ void Terminal::ApplyScheme(Scheme colorScheme) { _MakeAdjustedColorArray(); } - } diff --git a/src/cascadia/TerminalCore/Terminal.hpp b/src/cascadia/TerminalCore/Terminal.hpp index 77b7a15c7..9d50e7252 100644 --- a/src/cascadia/TerminalCore/Terminal.hpp +++ b/src/cascadia/TerminalCore/Terminal.hpp @@ -223,7 +223,7 @@ public: til::color GetDefaultBackground() 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;