Skip to content

Commit

Permalink
Revert "There's no reason that this should have entirely broken movin…
Browse files Browse the repository at this point in the history
…g panes. That doesn't make sense."

This reverts commit 31e904a.
  • Loading branch information
zadjii-msft committed Mar 28, 2023
1 parent 31e904a commit a86fd20
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
23 changes: 5 additions & 18 deletions src/cascadia/TerminalControl/ControlCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,32 +1555,19 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_RendererWarningHandlers(*this, winrt::make<RendererWarningArgs>(hr));
}

winrt::fire_and_forget ControlCore::_renderEngineSwapChainChanged(const HANDLE sourceHandle)
void ControlCore::_renderEngineSwapChainChanged(const HANDLE handle)
{
// `sourceHandle` is a weak ref to a HANDLE that's ultimately owned by the
// `handle` is a weak ref to a HANDLE that's ultimately owned by the
// render engine's own unique_handle. We'll add another ref to it here.
// This will make sure that we always have a valid HANDLE to give to
// callers of our own SwapChainHandle method, even if the renderer is
// currently in the process of discarding this value and creating a new
// one. Callers should have already set up the SwapChainChanged
// callback, so this all works out.
_lastSwapChainHandle.attach(handle);

winrt::handle duplicatedHandle;
const auto processHandle = GetCurrentProcess();
THROW_IF_WIN32_BOOL_FALSE(DuplicateHandle(processHandle, sourceHandle, processHandle, duplicatedHandle.put(), 0, FALSE, DUPLICATE_SAME_ACCESS));

const auto weakThis{ get_weak() };

co_await wil::resume_foreground(_dispatcher);

if (auto core{ weakThis.get() })
{
// `this` is safe to use now

_lastSwapChainHandle = (std::move(duplicatedHandle));
// Now bubble the event up to the control.
_SwapChainChangedHandlers(*this, winrt::box_value<uint64_t>(reinterpret_cast<uint64_t>(_lastSwapChainHandle.get())));
}
// Now bubble the event up to the control.
_SwapChainChangedHandlers(*this, winrt::box_value<uint64_t>(reinterpret_cast<uint64_t>(handle)));
}

void ControlCore::_rendererBackgroundColorChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/ControlCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

#pragma region RendererCallbacks
void _rendererWarning(const HRESULT hr);
winrt::fire_and_forget _renderEngineSwapChainChanged(const HANDLE handle);
void _renderEngineSwapChainChanged(const HANDLE handle);
void _rendererBackgroundColorChanged();
void _rendererTabColorChanged();
#pragma endregion
Expand Down
36 changes: 23 additions & 13 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,28 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _core.ConnectionState();
}

void TermControl::RenderEngineSwapChainChanged(IInspectable /*sender*/, IInspectable args)
winrt::fire_and_forget TermControl::RenderEngineSwapChainChanged(IInspectable /*sender*/, IInspectable args)
{
// This event comes in on the UI thread
HANDLE h = reinterpret_cast<HANDLE>(winrt::unbox_value<uint64_t>(args));
_AttachDxgiSwapChainToXaml(h);
// This event comes in on the render thread, not the UI thread.

const auto weakThis{ get_weak() };

winrt::handle handle;

// Add a ref to the handle passed to us, so that the HANDLE will remain
// valid to the other side of the co_await.
handle.attach(reinterpret_cast<HANDLE>(winrt::unbox_value<uint64_t>(args)));

co_await wil::resume_foreground(Dispatcher());

if (auto control{ weakThis.get() })
{
_AttachDxgiSwapChainToXaml(handle.get());
}
// Detach from the handle. If you don't do this, we'll CloseHandle() on
// the handle when `handle` goes out of scope, resulting in the swap
// chain being closed.
handle.detach();
}

// Method Description:
Expand Down Expand Up @@ -1801,11 +1818,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
// GH#5421: Enable the UiaEngine before checking for the SearchBox
// That way, new selections are notified to automation clients.
// The _uiaEngine lives in _interactivity, so call into there to enable it.

if (_interactivity)
{
_interactivity.GotFocus();
}
_interactivity.GotFocus();

// If the searchbox is focused, we don't want TSFInputControl to think
// it has focus so it doesn't intercept IME input. We also don't want the
Expand Down Expand Up @@ -1860,10 +1873,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

// This will disable the accessibility notifications, because the
// UiaEngine lives in ControlInteractivity
if (_interactivity)
{
_interactivity.LostFocus();
}
_interactivity.LostFocus();

if (TSFInputControl() != nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation

void ToggleShaderEffects();

void RenderEngineSwapChainChanged(IInspectable sender, IInspectable args);
winrt::fire_and_forget RenderEngineSwapChainChanged(IInspectable sender, IInspectable args);
void _AttachDxgiSwapChainToXaml(HANDLE swapChainHandle);
winrt::fire_and_forget _RendererEnteredErrorState(IInspectable sender, IInspectable args);

Expand Down

0 comments on commit a86fd20

Please sign in to comment.