diff --git a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp index 0b8e9d6bc..79e5461f2 100644 --- a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp +++ b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp @@ -94,7 +94,10 @@ namespace winrt::TerminalApp::implementation // the preview color changes, we only need to be able to restore the last one. _restorePreviewFuncs.clear(); - _ApplyToActiveControls([&](const auto& /*control*/) { + _ApplyToActiveControls([&](const auto& control) { + auto originalScheme{ control.ColorScheme() }; + 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 @@ -118,32 +121,33 @@ namespace winrt::TerminalApp::implementation // control.UpdateControlSettings(controlSettings); // // Take a copy of the inputs, since they are pointers anyways. - // _restorePreviewFuncs.emplace_back([=]() { - // //// Get the runtime settings of the focused control - // //const auto& controlSettings{ control.Settings().as() }; + _restorePreviewFuncs.emplace_back([=]() { + 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(); - // //} + //// 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); - // //} + //// 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()); - // }); + // control.UpdateControlSettings(control.Settings()); + }); }); } } diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index e082a8ad1..95b2a858f 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -452,30 +452,30 @@ namespace winrt::TerminalApp::implementation if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(realArgs.SchemeName())) { const auto res = _ApplyToActiveControls([&](auto& control) { - Core::Scheme coreScheme{}; + // 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]; + // 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(coreScheme); + control.ColorScheme(scheme.ToCoreScheme()); //// Start by getting the current settings of the control //auto controlSettings = control.Settings().as(); //auto parentSettings = controlSettings; diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index e8f26e71d..6d522d613 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -1606,21 +1606,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation return s; } - void ControlCore::ColorScheme(Core::Scheme scheme) const noexcept + void ControlCore::ColorScheme(Core::Scheme scheme) { - _terminal->ApplyScheme(scheme); - _settings->FocusedAppearance()->DefaultForeground(scheme.Foreground); - _settings->FocusedAppearance()->DefaultBackground(scheme.Background); + // 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()->CursorColor(scheme.CursorColor); _settings->FocusedAppearance()->SelectionBackground(scheme.SelectionBackground); - // // _defaultFg = colorScheme.Foreground; - // // // Set the default background as transparent to prevent the - // // // DX layer from overwriting the background image or acrylic effect - // // til::color newBackgroundColor{ colorScheme.Background }; - // // _defaultBg = newBackgroundColor.with_alpha(0); - _settings->FocusedAppearance()->SetColorTableEntry(0, scheme.Black); _settings->FocusedAppearance()->SetColorTableEntry(1, scheme.Red); _settings->FocusedAppearance()->SetColorTableEntry(2, scheme.Green); @@ -1638,8 +1634,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation _settings->FocusedAppearance()->SetColorTableEntry(14, scheme.BrightCyan); _settings->FocusedAppearance()->SetColorTableEntry(15, scheme.BrightWhite); - // _buffer->GetCursor().SetColor(til::color{ colorScheme.CursorColor }); + _terminal->ApplyScheme(scheme); _renderer->TriggerRedrawAll(); + _BackgroundColorChangedHandlers(*this, nullptr); } } diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index 4f50c76aa..36644f790 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) const noexcept; + void ColorScheme(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 3d0e22e07..531de93ad 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -478,7 +478,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation const IInspectable& /*args*/) { til::color newBgColor{ _core.BackgroundColor() }; - _changeBackgroundColor(newBgColor); + _changeBackgroundColor(newBgColor.with_alpha(1)); } winrt::fire_and_forget TermControl::_changeBackgroundColor(const til::color bg) diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp index 76ba3de6f..0d55c405b 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.cpp +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.cpp @@ -147,3 +147,30 @@ void ColorScheme::SetColorTableEntry(uint8_t index, const Core::Color& value) no THROW_HR_IF(E_INVALIDARG, index >= _table.size()); _table[index] = value; } + +winrt::Microsoft::Terminal::Core::Scheme ColorScheme::ToCoreScheme() const noexcept +{ + winrt::Microsoft::Terminal::Core::Scheme coreScheme{}; + + coreScheme.Foreground = Foreground(); + coreScheme.Background = Background(); + coreScheme.CursorColor = CursorColor(); + coreScheme.SelectionBackground = SelectionBackground(); + coreScheme.Black = Table()[0]; + coreScheme.Red = Table()[1]; + coreScheme.Green = Table()[2]; + coreScheme.Yellow = Table()[3]; + coreScheme.Blue = Table()[4]; + coreScheme.Purple = Table()[5]; + coreScheme.Cyan = Table()[6]; + coreScheme.White = Table()[7]; + coreScheme.BrightBlack = Table()[8]; + coreScheme.BrightRed = Table()[9]; + coreScheme.BrightGreen = Table()[10]; + coreScheme.BrightYellow = Table()[11]; + coreScheme.BrightBlue = Table()[12]; + coreScheme.BrightPurple = Table()[13]; + coreScheme.BrightCyan = Table()[14]; + coreScheme.BrightWhite = Table()[15]; + return coreScheme; +} diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.h b/src/cascadia/TerminalSettingsModel/ColorScheme.h index 4d5e580b0..63bfaf45d 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.h +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.h @@ -47,6 +47,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static com_ptr FromJson(const Json::Value& json); Json::Value ToJson() const; + winrt::Microsoft::Terminal::Core::Scheme ToCoreScheme() const noexcept; + com_array Table() const noexcept; void SetColorTableEntry(uint8_t index, const Core::Color& value) noexcept; diff --git a/src/cascadia/TerminalSettingsModel/ColorScheme.idl b/src/cascadia/TerminalSettingsModel/ColorScheme.idl index 418fbb531..8e758cfa6 100644 --- a/src/cascadia/TerminalSettingsModel/ColorScheme.idl +++ b/src/cascadia/TerminalSettingsModel/ColorScheme.idl @@ -19,5 +19,7 @@ namespace Microsoft.Terminal.Settings.Model // we expose the getter as a function. Microsoft.Terminal.Core.Color[] Table(); void SetColorTableEntry(UInt8 index, Microsoft.Terminal.Core.Color value); + + Microsoft.Terminal.Core.Scheme ToCoreScheme(); } }