Skip to content

Commit

Permalink
[silmarillion] Disable the UIA renderer before detaching
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 23, 2023
1 parent 614ec58 commit b1a867d
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// _renderer will always exist since it's introduced in the ctor
_renderer->AddRenderEngine(pEngine);
}
void ControlCore::DetachUiaEngine(::Microsoft::Console::Render::IRenderEngine* const pEngine)
{
_renderer->RemoveRenderEngine(pEngine);
}

bool ControlCore::IsInReadOnlyMode() const
{
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
bool& selectionNeedsToBeCopied);

void AttachUiaEngine(::Microsoft::Console::Render::IRenderEngine* const pEngine);
void DetachUiaEngine(::Microsoft::Console::Render::IRenderEngine* const pEngine);

bool IsInReadOnlyMode() const;
void ToggleReadOnlyMode();
Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/TerminalControl/ControlCore.idl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ namespace Microsoft.Terminal.Control
void UpdateSettings(IControlSettings settings, IControlAppearance appearance);
void ApplyAppearance(Boolean focused);

void Detach();

IControlSettings Settings { get; };
IControlAppearance FocusedAppearance { get; };
IControlAppearance UnfocusedAppearance { get; };
Expand Down
20 changes: 19 additions & 1 deletion src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,24 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _guid;
}

void ControlInteractivity::Detach()
{
if (_uiaEngine)
{
LOG_IF_FAILED(_uiaEngine->Disable());
}

_core->Detach();
}

void ControlInteractivity::Reparent(const Microsoft::Terminal::Control::IKeyBindings& keyBindings)
{
_core->Reparent(keyBindings);

/*if (_uiaEngine)
{
_uiaEngine->Reparent();
}*/
}

// Method Description:
Expand Down Expand Up @@ -677,7 +692,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
try
{
const auto autoPeer = winrt::make_self<implementation::InteractivityAutomationPeer>(this);

if (_uiaEngine)
{
_core->DetachUiaEngine(_uiaEngine.get());
}
_uiaEngine = std::make_unique<::Microsoft::Console::Render::UiaEngine>(autoPeer.get());
_core->AttachUiaEngine(_uiaEngine.get());
return *autoPeer;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Control::ControlCore Core();

void Close();
void Detach();

Control::InteractivityAutomationPeer OnCreateAutomationPeer();
::Microsoft::Console::Render::IRenderData* GetRenderData() const;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.idl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Microsoft.Terminal.Control

Guid Id { get; };
void Reparent(Microsoft.Terminal.Control.IKeyBindings keyBindings);
void Detach();
void Close();

InteractivityAutomationPeer OnCreateAutomationPeer();
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void TermControl::Detach()
{
_revokers = {};
_core.Detach();
_interactivity.Detach();
_detached = true;
}

Expand Down
14 changes: 14 additions & 0 deletions src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,20 @@ void Renderer::AddRenderEngine(_In_ IRenderEngine* const pEngine)
THROW_HR_MSG(E_UNEXPECTED, "engines array is full");
}

void Renderer::RemoveRenderEngine(_In_ IRenderEngine* const pEngine)
{
THROW_HR_IF_NULL(E_INVALIDARG, pEngine);

for (auto& p : _engines)
{
if (p == pEngine)
{
p = nullptr;
return;
}
}
}

// Method Description:
// - Registers a callback for when the background color is changed
// Arguments:
Expand Down
1 change: 1 addition & 0 deletions src/renderer/base/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace Microsoft::Console::Render
void WaitUntilCanRender();

void AddRenderEngine(_In_ IRenderEngine* const pEngine);
void RemoveRenderEngine(_In_ IRenderEngine* const pEngine);

void SetBackgroundColorChangedCallback(std::function<void()> pfn);
void SetFrameColorChangedCallback(std::function<void()> pfn);
Expand Down

0 comments on commit b1a867d

Please sign in to comment.