From 31e799859fc9fcb8ccf041224e67a6b18afe224e Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Oct 2021 11:27:26 -0500 Subject: [PATCH] this builds at least --- .../TerminalApp/ActionPreviewHandlers.cpp | 44 +++---- .../TerminalApp/AppActionHandlers.cpp | 48 ++++---- src/cascadia/TerminalApp/Pane.cpp | 4 +- src/cascadia/TerminalApp/TerminalPage.cpp | 4 +- src/cascadia/TerminalControl/ControlCore.cpp | 107 +++++++++--------- src/cascadia/TerminalControl/ControlCore.h | 18 ++- src/cascadia/TerminalControl/ControlCore.idl | 8 +- .../TerminalControl/ControlInteractivity.cpp | 3 +- .../TerminalControl/ControlInteractivity.h | 1 + .../TerminalControl/ControlInteractivity.idl | 1 + .../TerminalControl/ControlSettings.h | 3 +- src/cascadia/TerminalControl/TermControl.cpp | 90 ++++++++------- src/cascadia/TerminalControl/TermControl.h | 19 ++-- src/cascadia/TerminalControl/TermControl.idl | 8 +- .../TerminalSettingsEditor/Profiles.cpp | 14 +-- src/cascadia/inc/ControlProperties.h | 3 +- 16 files changed, 208 insertions(+), 167 deletions(-) diff --git a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp index 3fc4ff2ae..96c9bd814 100644 --- a/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp +++ b/src/cascadia/TerminalApp/ActionPreviewHandlers.cpp @@ -115,34 +115,34 @@ namespace winrt::TerminalApp::implementation // Insert that new child as the parent of the control's settings controlSettings.SetParent(childStruct.DefaultSettings()); - control.UpdateSettings(); + 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() }; + //// 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.UpdateSettings(); + control.UpdateControlSettings(control.Settings()); }); }); } diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp index ae79289fa..3af4b73e9 100644 --- a/src/cascadia/TerminalApp/AppActionHandlers.cpp +++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp @@ -451,29 +451,35 @@ namespace winrt::TerminalApp::implementation { if (const auto scheme = _settings.GlobalSettings().ColorSchemes().TryLookup(realArgs.SchemeName())) { - const auto res = _ApplyToActiveControls([&](auto& control) { - // 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(); - } + const auto res = _ApplyToActiveControls([&](auto& /*control*/) { + //// 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); + //// ApplyColorScheme(nullptr) will clear the old color scheme. + //controlSettings.ApplyColorScheme(nullptr); + //parentSettings.ApplyColorScheme(scheme); - control.UpdateSettings(); + //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/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 958548f3a..993202315 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -1476,8 +1476,8 @@ void Pane::UpdateSettings(const TerminalSettingsCreateResult& settings, const Pr // sure the unfocused settings inherit from that. unfocusedSettings.SetParent(controlSettings); } - _control.UnfocusedAppearance(unfocusedSettings); - _control.UpdateSettings(); + // _control.UnfocusedAppearance(unfocusedSettings); + _control.UpdateControlSettings(controlSettings, unfocusedSettings); } // Method Description: diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index b779b5069..b2ef82ab1 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -2162,9 +2162,9 @@ namespace winrt::TerminalApp::implementation // Give term control a child of the settings so that any overrides go in the child // This way, when we do a settings reload we just update the parent and the overrides remain const auto child = TerminalSettings::CreateWithParent(settings); - TermControl term{ child.DefaultSettings(), connection }; + TermControl term{ child.DefaultSettings(), child.UnfocusedSettings(), connection }; - term.UnfocusedAppearance(child.UnfocusedSettings()); // It is okay for the unfocused settings to be null + // term.UnfocusedAppearance(child.UnfocusedSettings()); // It is okay for the unfocused settings to be null return term; } diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp index 0e3897e51..b22fd5727 100644 --- a/src/cascadia/TerminalControl/ControlCore.cpp +++ b/src/cascadia/TerminalControl/ControlCore.cpp @@ -54,15 +54,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation return initialized; } - ControlCore::ControlCore(IControlSettings settings, + ControlCore::ControlCore(Control::IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection) : _connection{ connection }, - _settings{ settings }, _desiredFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, { 0, DEFAULT_FONT_SIZE }, CP_UTF8 }, _actualFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false } { _EnsureStaticInitialization(); + _settings = winrt::make_self(settings, unfocusedAppearance); + _terminal = std::make_unique<::Microsoft::Terminal::Core::Terminal>(); // Subscribe to the connection's disconnected event and call our connection closed handlers. @@ -78,7 +80,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation }); // GH#8969: pre-seed working directory to prevent potential races - _terminal->SetWorkingDirectory(_settings.StartingDirectory()); + _terminal->SetWorkingDirectory(_settings->StartingDirectory()); auto pfnCopyToClipboard = std::bind(&ControlCore::_terminalCopyToClipboard, this, std::placeholders::_1); _terminal->SetCopyToClipboardCallback(pfnCopyToClipboard); @@ -185,7 +187,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation } }); - UpdateSettings(settings); + // TODO! uh, this feels wrong aren't we just setting this above?? + UpdateSettings(settings, unfocusedAppearance); } ControlCore::~ControlCore() @@ -242,7 +245,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation LOG_IF_FAILED(_renderEngine->SetWindowSize({ viewInPixels.Width(), viewInPixels.Height() })); // Update DxEngine's SelectionBackground - _renderEngine->SetSelectionBackground(til::color{ _settings.SelectionBackground() }); + _renderEngine->SetSelectionBackground(til::color{ _settings->SelectionBackground() }); const auto vp = _renderEngine->GetViewportInCharacters(viewInPixels); const auto width = vp.Width(); @@ -250,10 +253,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation _connection.Resize(height, width); // Override the default width and height to match the size of the swapChainPanel - _settings.InitialCols(width); - _settings.InitialRows(height); + _settings->InitialCols(width); + _settings->InitialRows(height); - _terminal->CreateFromSettings(_settings, *_renderer); + _terminal->CreateFromSettings(*_settings, *_renderer); // IMPORTANT! Set this callback up sooner than later. If we do it // after Enable, then it'll be possible to paint the frame once @@ -265,17 +268,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation // We do this after we initially set the swapchain so as to avoid unnecessary callbacks (and locking problems) _renderEngine->SetCallback(std::bind(&ControlCore::_renderEngineSwapChainChanged, this)); - _renderEngine->SetRetroTerminalEffect(_settings.RetroTerminalEffect()); - _renderEngine->SetPixelShaderPath(_settings.PixelShaderPath()); - _renderEngine->SetForceFullRepaintRendering(_settings.ForceFullRepaintRendering()); - _renderEngine->SetSoftwareRendering(_settings.SoftwareRendering()); - _renderEngine->SetIntenseIsBold(_settings.IntenseIsBold()); + _renderEngine->SetRetroTerminalEffect(_settings->RetroTerminalEffect()); + _renderEngine->SetPixelShaderPath(_settings->PixelShaderPath()); + _renderEngine->SetForceFullRepaintRendering(_settings->ForceFullRepaintRendering()); + _renderEngine->SetSoftwareRendering(_settings->SoftwareRendering()); + _renderEngine->SetIntenseIsBold(_settings->IntenseIsBold()); _updateAntiAliasingMode(_renderEngine.get()); // GH#5098: Inform the engine of the opacity of the default text background. // GH#11315: Always do this, even if they don't have acrylic on. - _renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast(_settings.Opacity())); + _renderEngine->SetDefaultTextBackgroundOpacity(::base::saturated_cast(_settings->Opacity())); THROW_IF_FAILED(_renderEngine->Enable()); @@ -450,7 +453,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // is what the Terminal did prior to 1.12. if (!IsVintageOpacityAvailable()) { - _settings.UseAcrylic(newOpacity < 1.0); + _runtimeUseAcrylic = newOpacity < 1.0; } auto eventArgs = winrt::make_self(newOpacity); @@ -465,7 +468,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // specify a custom pixel shader, manually enable the legacy retro // effect first. This will ensure that a toggle off->on will still work, // even if they currently have retro effect off. - if (_settings.PixelShaderPath().empty() && !_renderEngine->GetRetroTerminalEffect()) + if (_settings->PixelShaderPath().empty() && !_renderEngine->GetRetroTerminalEffect()) { // SetRetroTerminalEffect to true will enable the effect. In this // case, the shader effect will already be disabled (because neither @@ -575,11 +578,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Method Description: // - Updates the settings of the current terminal. // - INVARIANT: This method can only be called if the caller DOES NOT HAVE writing lock on the terminal. - void ControlCore::UpdateSettings(const IControlSettings& settings) + void ControlCore::UpdateSettings(const IControlSettings& settings, const IControlAppearance& newAppearance) { - auto lock = _terminal->LockForWriting(); + _settings = winrt::make_self(settings, newAppearance); - _settings = settings; + auto lock = _terminal->LockForWriting(); _runtimeOpacity = std::nullopt; _runtimeUseAcrylic = std::nullopt; @@ -587,15 +590,15 @@ namespace winrt::Microsoft::Terminal::Control::implementation // GH#11285 - If the user is on Windows 10, and they wanted opacity, but // didn't explicitly request acrylic, then opt them in to acrylic. // On Windows 11+, this isn't needed, because we can have vintage opacity. - if (!IsVintageOpacityAvailable() && _settings.Opacity() < 1.0 && !_settings.UseAcrylic()) + if (!IsVintageOpacityAvailable() && _settings->Opacity() < 1.0 && !_settings->UseAcrylic()) { _runtimeUseAcrylic = true; } // Initialize our font information. - const auto fontFace = _settings.FontFace(); - const short fontHeight = ::base::saturated_cast(_settings.FontSize()); - const auto fontWeight = _settings.FontWeight(); + const auto fontFace = _settings->FontFace(); + const short fontHeight = ::base::saturated_cast(_settings->FontSize()); + const auto fontWeight = _settings->FontWeight(); // The font width doesn't terribly matter, we'll only be using the // height to look it up // The other params here also largely don't matter. @@ -606,7 +609,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation _desiredFont = { _actualFont }; // Update the terminal core with its new Core settings - _terminal->UpdateSettings(_settings); + _terminal->UpdateSettings(*_settings); if (!_initializedTerminal) { @@ -615,8 +618,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation return; } - _renderEngine->SetForceFullRepaintRendering(_settings.ForceFullRepaintRendering()); - _renderEngine->SetSoftwareRendering(_settings.SoftwareRendering()); + _renderEngine->SetForceFullRepaintRendering(_settings->ForceFullRepaintRendering()); + _renderEngine->SetSoftwareRendering(_settings->SoftwareRendering()); _updateAntiAliasingMode(_renderEngine.get()); @@ -633,29 +636,29 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Method Description: // - Updates the appearance of the current terminal. // - INVARIANT: This method can only be called if the caller DOES NOT HAVE writing lock on the terminal. - void ControlCore::UpdateAppearance(const IControlAppearance& newAppearance) - { - auto lock = _terminal->LockForWriting(); + // void ControlCore::UpdateAppearance(const IControlAppearance& newAppearance) + // { + // auto lock = _terminal->LockForWriting(); - // Update the terminal core with its new Core settings - _terminal->UpdateAppearance(newAppearance); + // // Update the terminal core with its new Core settings + // _terminal->UpdateAppearance(newAppearance); - // Update DxEngine settings under the lock - if (_renderEngine) - { - // Update DxEngine settings under the lock - _renderEngine->SetSelectionBackground(til::color{ newAppearance.SelectionBackground() }); - _renderEngine->SetRetroTerminalEffect(newAppearance.RetroTerminalEffect()); - _renderEngine->SetPixelShaderPath(newAppearance.PixelShaderPath()); - _renderEngine->SetIntenseIsBold(_settings.IntenseIsBold()); - _renderer->TriggerRedrawAll(); - } - } + // // Update DxEngine settings under the lock + // if (_renderEngine) + // { + // // Update DxEngine settings under the lock + // _renderEngine->SetSelectionBackground(til::color{ newAppearance.SelectionBackground() }); + // _renderEngine->SetRetroTerminalEffect(newAppearance.RetroTerminalEffect()); + // _renderEngine->SetPixelShaderPath(newAppearance.PixelShaderPath()); + // _renderEngine->SetIntenseIsBold(_settings->IntenseIsBold()); + // _renderer->TriggerRedrawAll(); + // } + // } void ControlCore::_updateAntiAliasingMode(::Microsoft::Console::Render::DxEngine* const dxEngine) { // Update DxEngine's AntialiasingMode - switch (_settings.AntialiasingMode()) + switch (_settings->AntialiasingMode()) { case TextAntialiasingMode::Cleartype: dxEngine->SetAntialiasingMode(D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE); @@ -690,7 +693,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation if (_renderEngine) { std::unordered_map featureMap; - if (const auto fontFeatures = _settings.FontFeatures()) + if (const auto fontFeatures = _settings->FontFeatures()) { featureMap.reserve(fontFeatures.Size()); @@ -700,7 +703,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } } std::unordered_map axesMap; - if (const auto fontAxes = _settings.FontAxes()) + if (const auto fontAxes = _settings->FontAxes()) { axesMap.reserve(fontAxes.Size()); @@ -742,8 +745,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation { // Make sure we have a non-zero font size const auto newSize = std::max(gsl::narrow_cast(fontSize), 1); - const auto fontFace = _settings.FontFace(); - const auto fontWeight = _settings.FontWeight(); + const auto fontFace = _settings->FontFace(); + const auto fontWeight = _settings->FontWeight(); _actualFont = { fontFace, 0, fontWeight.Weight, { 0, newSize }, CP_UTF8, false }; _desiredFont = { _actualFont }; @@ -767,7 +770,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - none void ControlCore::ResetFontSize() { - _setFontSize(_settings.FontSize()); + _setFontSize(_settings->FontSize()); } // Method Description: @@ -979,7 +982,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation TextBuffer::GenHTML(bufferData, _actualFont.GetUnscaledSize().Y, _actualFont.GetFaceName(), - til::color{ _settings.DefaultBackground() }) : + til::color{ _settings->DefaultBackground() }) : ""; // convert to RTF format @@ -987,10 +990,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation TextBuffer::GenRTF(bufferData, _actualFont.GetUnscaledSize().Y, _actualFont.GetFaceName(), - til::color{ _settings.DefaultBackground() }) : + til::color{ _settings->DefaultBackground() }) : ""; - if (!_settings.CopyOnSelect()) + if (!_settings->CopyOnSelect()) { _terminal->ClearSelection(); _renderer->TriggerSelection(); @@ -1231,7 +1234,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation bool ControlCore::CopyOnSelect() const { - return _settings.CopyOnSelect(); + return _settings->CopyOnSelect(); } Windows::Foundation::Collections::IVector ControlCore::SelectedText(bool trimTrailingWhitespace) const diff --git a/src/cascadia/TerminalControl/ControlCore.h b/src/cascadia/TerminalControl/ControlCore.h index a46067cd0..7ffe663df 100644 --- a/src/cascadia/TerminalControl/ControlCore.h +++ b/src/cascadia/TerminalControl/ControlCore.h @@ -44,7 +44,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation struct ControlCore : ControlCoreT { public: - ControlCore(IControlSettings settings, + ControlCore(Control::IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection); ~ControlCore(); @@ -53,8 +54,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation const double compositionScale); void EnablePainting(); - void UpdateSettings(const IControlSettings& settings); - void UpdateAppearance(const IControlAppearance& newAppearance); + void UpdateSettings(const Control::IControlSettings& settings, const IControlAppearance& newAppearance); + // void UpdateAppearance(const Control::IControlAppearance& newAppearance); + Control::IControlSettings Settings() const { return *_settings; }; + Control::IControlAppearance FocusedAppearance() const { return *_settings->FocusedAppearance(); }; + Control::IControlAppearance UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); }; + void SizeChanged(const double width, const double height); void ScaleChanged(const double scale); uint64_t SwapChainHandle() const; @@ -160,8 +165,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation static bool IsVintageOpacityAvailable() noexcept; - RUNTIME_SETTING(double, Opacity, _settings.Opacity()); - RUNTIME_SETTING(bool, UseAcrylic, _settings.UseAcrylic()); + RUNTIME_SETTING(double, Opacity, _settings->Opacity()); + RUNTIME_SETTING(bool, UseAcrylic, _settings->UseAcrylic()); // -------------------------------- WinRT Events --------------------------------- // clang-format off @@ -203,7 +208,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation std::unique_ptr<::Microsoft::Console::Render::DxEngine> _renderEngine{ nullptr }; std::unique_ptr<::Microsoft::Console::Render::Renderer> _renderer{ nullptr }; - IControlSettings _settings{ nullptr }; + // IControlSettings _settings{ nullptr }; + winrt::com_ptr _settings{ nullptr }; FontInfoDesired _desiredFont; FontInfo _actualFont; diff --git a/src/cascadia/TerminalControl/ControlCore.idl b/src/cascadia/TerminalControl/ControlCore.idl index 23f85abc9..0817b5335 100644 --- a/src/cascadia/TerminalControl/ControlCore.idl +++ b/src/cascadia/TerminalControl/ControlCore.idl @@ -33,14 +33,18 @@ namespace Microsoft.Terminal.Control [default_interface] runtimeclass ControlCore : ICoreState { ControlCore(IControlSettings settings, + IControlAppearance unfocusedAppearance, Microsoft.Terminal.TerminalConnection.ITerminalConnection connection); Boolean Initialize(Double actualWidth, Double actualHeight, Double compositionScale); - void UpdateSettings(IControlSettings settings); - void UpdateAppearance(IControlAppearance appearance); + void UpdateSettings(IControlSettings settings, IControlAppearance appearance); + // void UpdateAppearance(IControlAppearance appearance); + IControlSettings Settings { get; }; + IControlAppearance FocusedAppearance { get; }; + IControlAppearance UnfocusedAppearance { get; }; UInt64 SwapChainHandle { get; }; diff --git a/src/cascadia/TerminalControl/ControlInteractivity.cpp b/src/cascadia/TerminalControl/ControlInteractivity.cpp index 6991d1b40..737f839e6 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.cpp +++ b/src/cascadia/TerminalControl/ControlInteractivity.cpp @@ -39,13 +39,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation } ControlInteractivity::ControlInteractivity(IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection) : _touchAnchor{ std::nullopt }, _lastMouseClickTimestamp{}, _lastMouseClickPos{}, _selectionNeedsToBeCopied{ false } { - _core = winrt::make_self(settings, connection); + _core = winrt::make_self(settings, unfocusedAppearance, connection); } // Method Description: diff --git a/src/cascadia/TerminalControl/ControlInteractivity.h b/src/cascadia/TerminalControl/ControlInteractivity.h index 71312afc3..cb63c65e0 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.h +++ b/src/cascadia/TerminalControl/ControlInteractivity.h @@ -35,6 +35,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { public: ControlInteractivity(IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection); void GotFocus(); diff --git a/src/cascadia/TerminalControl/ControlInteractivity.idl b/src/cascadia/TerminalControl/ControlInteractivity.idl index 6261b773d..3921c7c5f 100644 --- a/src/cascadia/TerminalControl/ControlInteractivity.idl +++ b/src/cascadia/TerminalControl/ControlInteractivity.idl @@ -14,6 +14,7 @@ namespace Microsoft.Terminal.Control [default_interface] runtimeclass ControlInteractivity { ControlInteractivity(IControlSettings settings, + IControlAppearance unfocusedAppearance, Microsoft.Terminal.TerminalConnection.ITerminalConnection connection); ControlCore Core { get; }; diff --git a/src/cascadia/TerminalControl/ControlSettings.h b/src/cascadia/TerminalControl/ControlSettings.h index b7759f007..defba6213 100644 --- a/src/cascadia/TerminalControl/ControlSettings.h +++ b/src/cascadia/TerminalControl/ControlSettings.h @@ -27,7 +27,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation winrt::com_ptr _focusedAppearance{ nullptr }; public: - ControlSettings(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance) + ControlSettings(const Control::IControlSettings& settings, + const Control::IControlAppearance& unfocusedAppearance) { _focusedAppearance = winrt::make_self(settings); _unfocusedAppearance = unfocusedAppearance ? diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp index 47ff268ca..229947099 100644 --- a/src/cascadia/TerminalControl/TermControl.cpp +++ b/src/cascadia/TerminalControl/TermControl.cpp @@ -49,6 +49,7 @@ DEFINE_ENUM_FLAG_OPERATORS(winrt::Microsoft::Terminal::Control::MouseButtonState namespace winrt::Microsoft::Terminal::Control::implementation { TermControl::TermControl(IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, TerminalConnection::ITerminalConnection connection) : _settings{ winrt::make_self(settings, nullptr) }, _isInternalScrollBarUpdate{ false }, @@ -62,7 +63,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation { InitializeComponent(); - _interactivity = winrt::make(settings, connection); + _interactivity = winrt::make(settings, unfocusedAppearance, connection); _core = _interactivity.Core(); // These events might all be triggered by the connection, but that @@ -145,7 +146,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation _autoScrollTimer.Interval(AutoScrollUpdateInterval); _autoScrollTimer.Tick({ this, &TermControl::_UpdateAutoScroll }); - _ApplyUISettings(_settings); + _ApplyUISettings(); } // Method Description: @@ -230,28 +231,36 @@ namespace winrt::Microsoft::Terminal::Control::implementation this->Focus(FocusState::Programmatic); } + + winrt::fire_and_forget TermControl::UpdateControlSettings(IControlSettings settings) + { + return UpdateControlSettings(settings, _core.UnfocusedAppearance()); + } // Method Description: // - Given Settings having been updated, applies the settings to the current terminal. // Return Value: // - - winrt::fire_and_forget TermControl::UpdateSettings() + winrt::fire_and_forget TermControl::UpdateControlSettings(IControlSettings settings, IControlAppearance unfocusedAppearance) { auto weakThis{ get_weak() }; + co_await winrt::resume_background(); + _core.UpdateSettings(settings, unfocusedAppearance); + // Dispatch a call to the UI thread to apply the new settings to the // terminal. co_await winrt::resume_foreground(Dispatcher()); - _UpdateSettingsFromUIThread(_settings); + _UpdateSettingsFromUIThread(); - _UpdateAppearanceFromUIThread(_focused ? _settings->FocusedAppearance() : _settings->UnfocusedAppearance()); + _UpdateAppearanceFromUIThread(_focused ? _core.FocusedAppearance() : _core.UnfocusedAppearance()); } // Method Description: // - Dispatches a call to the UI thread and updates the appearance // Arguments: // - newAppearance: the new appearance to set - winrt::fire_and_forget TermControl::UpdateAppearance(winrt::com_ptr newAppearance) + winrt::fire_and_forget TermControl::UpdateAppearance(IControlAppearance newAppearance) { // Dispatch a call to the UI thread co_await winrt::resume_foreground(Dispatcher()); @@ -267,17 +276,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - INVARIANT: This method must be called from the UI thread. // Arguments: // - newSettings: the new settings to set - void TermControl::_UpdateSettingsFromUIThread(winrt::com_ptr newSettings) + void TermControl::_UpdateSettingsFromUIThread() { if (_IsClosing()) { return; } - _core.UpdateSettings(newSettings.try_as()); // TODO! + // _core.UpdateSettings(settings); // TODO! // Update our control settings - _ApplyUISettings(newSettings); + _ApplyUISettings(); } // Method Description: @@ -285,16 +294,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - INVARIANT: This method must be called from the UI thread. // Arguments: // - newAppearance: the new appearance to set - void TermControl::_UpdateAppearanceFromUIThread(winrt::com_ptr newAppearance) + void TermControl::_UpdateAppearanceFromUIThread(Control::IControlAppearance newAppearance) { if (_IsClosing()) { return; } - if (!newAppearance->BackgroundImage().empty()) + if (!newAppearance.BackgroundImage().empty()) { - Windows::Foundation::Uri imageUri{ newAppearance->BackgroundImage() }; + Windows::Foundation::Uri imageUri{ newAppearance.BackgroundImage() }; // Check if the image brush is already pointing to the image // in the modified settings; if it isn't (or isn't there), @@ -314,10 +323,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation } // Apply stretch, opacity and alignment settings - BackgroundImage().Stretch(newAppearance->BackgroundImageStretchMode()); - BackgroundImage().Opacity(newAppearance->BackgroundImageOpacity()); - BackgroundImage().HorizontalAlignment(newAppearance->BackgroundImageHorizontalAlignment()); - BackgroundImage().VerticalAlignment(newAppearance->BackgroundImageVerticalAlignment()); + BackgroundImage().Stretch(newAppearance.BackgroundImageStretchMode()); + BackgroundImage().Opacity(newAppearance.BackgroundImageOpacity()); + BackgroundImage().HorizontalAlignment(newAppearance.BackgroundImageHorizontalAlignment()); + BackgroundImage().VerticalAlignment(newAppearance.BackgroundImageVerticalAlignment()); } else { @@ -325,15 +334,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation } // Update our control settings - const auto bg = newAppearance->DefaultBackground(); + const auto bg = newAppearance.DefaultBackground(); _changeBackgroundColor(bg); // Set TSF Foreground Media::SolidColorBrush foregroundBrush{}; - foregroundBrush.Color(static_cast(newAppearance->DefaultForeground())); + foregroundBrush.Color(static_cast(newAppearance.DefaultForeground())); TSFInputControl().Foreground(foregroundBrush); - _core.UpdateAppearance(newAppearance.try_as()); + // TODO! + // _core.UpdateAppearance(newAppearance.try_as()); } // Method Description: @@ -368,21 +378,23 @@ namespace winrt::Microsoft::Terminal::Control::implementation // - // Return Value: // - - void TermControl::_ApplyUISettings(const winrt::com_ptr& newSettings) + void TermControl::_ApplyUISettings() { _InitializeBackgroundBrush(); - const auto bg = newSettings->FocusedAppearance()->DefaultBackground(); + // settings might be out-of-proc in the future + auto settings{ _core.Settings() }; + const auto bg = _core.FocusedAppearance().DefaultBackground(); _changeBackgroundColor(bg); // Apply padding as swapChainPanel's margin - const auto newMargin = ParseThicknessFromPadding(newSettings->Padding()); + const auto newMargin = ParseThicknessFromPadding(settings.Padding()); SwapChainPanel().Margin(newMargin); TSFInputControl().Margin(newMargin); // Apply settings for scrollbar - if (newSettings->ScrollState() == ScrollbarState::Hidden) + if (settings.ScrollState() == ScrollbarState::Hidden) { // In the scenario where the user has turned off the OS setting to automatically hide scrollbars, the // Terminal scrollbar would still be visible; so, we need to set the control's visibility accordingly to @@ -410,7 +422,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Method Description: // - Set up each layer's brush used to display the control's background. // - Respects the settings for acrylic, background image and opacity from - // _settings-> + // _settings. // * If acrylic is not enabled, setup a solid color background, otherwise // use bgcolor as acrylic's tint // - Avoids image flickering and acrylic brush redraw if settings are changed @@ -718,7 +730,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation } // Now that the renderer is set up, update the appearance for initialization - _UpdateAppearanceFromUIThread(_settings->FocusedAppearance()); + _UpdateAppearanceFromUIThread(_core.FocusedAppearance()); _initializedTerminal = true; @@ -1507,7 +1519,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation // appearances anyway so there's no need to switch back upon gaining focus if (_settings->UnfocusedAppearance()) { - UpdateAppearance(_settings->FocusedAppearance()); + UpdateAppearance(_core.FocusedAppearance()); } } @@ -1549,10 +1561,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation // Check if there is an unfocused config we should set the appearance to // upon losing focus - if (_settings->UnfocusedAppearance()) - { - UpdateAppearance(_settings->UnfocusedAppearance()); - } + // if (_settings->UnfocusedAppearance()) + // { + UpdateAppearance(_core.UnfocusedAppearance()); + // } } // Method Description: @@ -2363,21 +2375,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation return _settings.try_as(); } - void TermControl::Settings(IControlSettings newSettings) - { - DebugBreak(); - _settings = winrt::make_self(newSettings, nullptr); - } + // void TermControl::Settings(IControlSettings newSettings) + // { + // DebugBreak(); + // _settings = winrt::make_self(newSettings, nullptr); + // } IControlAppearance TermControl::UnfocusedAppearance() const { return *_settings->UnfocusedAppearance(); } - void TermControl::UnfocusedAppearance(IControlAppearance newAppearance) - { - _settings = winrt::make_self(_settings.try_as(), newAppearance); - } + // void TermControl::UnfocusedAppearance(IControlAppearance newAppearance) + // { + // _settings = winrt::make_self(_settings.try_as(), newAppearance); + // } Windows::Foundation::IReference TermControl::TabColor() noexcept { diff --git a/src/cascadia/TerminalControl/TermControl.h b/src/cascadia/TerminalControl/TermControl.h index 2eb96cf75..91c5aaadf 100644 --- a/src/cascadia/TerminalControl/TermControl.h +++ b/src/cascadia/TerminalControl/TermControl.h @@ -26,9 +26,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation { struct TermControl : TermControlT { - TermControl(IControlSettings settings, TerminalConnection::ITerminalConnection connection); + TermControl(IControlSettings settings, + Control::IControlAppearance unfocusedAppearance, + TerminalConnection::ITerminalConnection connection); - winrt::fire_and_forget UpdateSettings(); + winrt::fire_and_forget UpdateControlSettings(Control::IControlSettings settings); + winrt::fire_and_forget UpdateControlSettings(Control::IControlSettings settings, Control::IControlAppearance unfocusedAppearance); hstring GetProfileName() const; @@ -89,9 +92,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation const Windows::UI::Xaml::Thickness GetPadding(); IControlSettings Settings() const; - void Settings(IControlSettings newSettings); + // void Settings(IControlSettings newSettings); IControlAppearance UnfocusedAppearance() const; - void UnfocusedAppearance(IControlAppearance newSettings); + // void UnfocusedAppearance(IControlAppearance newSettings); static Windows::Foundation::Size GetProposedDimensions(IControlSettings const& settings, const uint32_t dpi); static Windows::Foundation::Size GetProposedDimensions(const winrt::Windows::Foundation::Size& initialSizeInChars, @@ -199,10 +202,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation return _closing; } - void _UpdateSettingsFromUIThread(winrt::com_ptr newSettings); - void _UpdateAppearanceFromUIThread(winrt::com_ptr newAppearance); - void _ApplyUISettings(const winrt::com_ptr& newSettings); - winrt::fire_and_forget UpdateAppearance(winrt::com_ptr newAppearance); + void _UpdateSettingsFromUIThread(); + void _UpdateAppearanceFromUIThread(Control::IControlAppearance newAppearance); + void _ApplyUISettings(); + winrt::fire_and_forget UpdateAppearance(Control::IControlAppearance newAppearance); void _InitializeBackgroundBrush(); void _BackgroundColorChangedHandler(const IInspectable& sender, const IInspectable& args); diff --git a/src/cascadia/TerminalControl/TermControl.idl b/src/cascadia/TerminalControl/TermControl.idl index 26db0862c..8b9fb2dab 100644 --- a/src/cascadia/TerminalControl/TermControl.idl +++ b/src/cascadia/TerminalControl/TermControl.idl @@ -17,14 +17,16 @@ namespace Microsoft.Terminal.Control ICoreState { TermControl(IControlSettings settings, + IControlAppearance unfocusedAppearance, Microsoft.Terminal.TerminalConnection.ITerminalConnection connection); static Windows.Foundation.Size GetProposedDimensions(IControlSettings settings, UInt32 dpi); - void UpdateSettings(); + void UpdateControlSettings(IControlSettings settings); + void UpdateControlSettings(IControlSettings settings, IControlAppearance unfocusedAppearance); - Microsoft.Terminal.Control.IControlSettings Settings; - Microsoft.Terminal.Control.IControlAppearance UnfocusedAppearance; + Microsoft.Terminal.Control.IControlSettings Settings { get; }; + Microsoft.Terminal.Control.IControlAppearance UnfocusedAppearance { get; }; event FontSizeChangedEventArgs FontSizeChanged; event Windows.Foundation.TypedEventHandler TitleChanged; diff --git a/src/cascadia/TerminalSettingsEditor/Profiles.cpp b/src/cascadia/TerminalSettingsEditor/Profiles.cpp index 6c507ecf4..d7432cbf8 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles.cpp +++ b/src/cascadia/TerminalSettingsEditor/Profiles.cpp @@ -349,7 +349,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } Profiles::Profiles() : - _previewControl{ Control::TermControl(Model::TerminalSettings{}, make()) } + _previewControl{ Control::TermControl(Model::TerminalSettings{}, nullptr, make()) } { InitializeComponent(); @@ -404,26 +404,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentScrollState" }); } - _previewControl.Settings(_State.Profile().TermSettings()); - _previewControl.UpdateSettings(); + // _previewControl.Settings(_State.Profile().TermSettings()); + _previewControl.UpdateControlSettings(_State.Profile().TermSettings()); }); // The Appearances object handles updating the values in the settings UI, but // we still need to listen to the changes here just to update the preview control _AppearanceViewModelChangedRevoker = _State.Profile().DefaultAppearance().PropertyChanged(winrt::auto_revoke, [=](auto&&, const PropertyChangedEventArgs& /*args*/) { - _previewControl.Settings(_State.Profile().TermSettings()); - _previewControl.UpdateSettings(); + // _previewControl.Settings(_State.Profile().TermSettings()); + _previewControl.UpdateControlSettings(_State.Profile().TermSettings()); }); // Navigate to the pivot in the provided navigation state ProfilesPivot().SelectedIndex(static_cast(_State.LastActivePivot())); - _previewControl.Settings(_State.Profile().TermSettings()); + // _previewControl.Settings(_State.Profile().TermSettings()); // There is a possibility that the control has not fully initialized yet, // so wait for it to initialize before updating the settings (so we know // that the renderer is set up) _previewControl.Initialized([&](auto&& /*s*/, auto&& /*e*/) { - _previewControl.UpdateSettings(); + _previewControl.UpdateControlSettings(_State.Profile().TermSettings()); }); } diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index fe39d92fe..b3ddbc240 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -11,7 +11,8 @@ X(til::color, CursorColor, DEFAULT_CURSOR_COLOR) \ X(winrt::Microsoft::Terminal::Core::CursorStyle, CursorShape, winrt::Microsoft::Terminal::Core::CursorStyle::Vintage) \ X(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT) \ - X(bool, IntenseIsBright, true) + X(bool, IntenseIsBright, true) \ + X(bool, AdjustIndistinguishableColors, true) // --------------------------- Control Appearance --------------------------- // All of these settings are defined in IControlSettings.