-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(A better) Refactoring of how connection restarting is handled #15240
Changes from 8 commits
977b9d0
f5be21d
ac50f3d
8fd2c60
35306ee
cf86693
7f53dbb
733b742
22ccd6b
ad1f333
04ade0b
7888277
8877336
d951cf7
c4dabe7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,21 +78,14 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
ControlCore::ControlCore(Control::IControlSettings settings, | ||
Control::IControlAppearance unfocusedAppearance, | ||
TerminalConnection::ITerminalConnection connection) : | ||
_connection{ connection }, | ||
_desiredFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, DEFAULT_FONT_SIZE, CP_UTF8 }, | ||
_actualFont{ DEFAULT_FONT_FACE, 0, DEFAULT_FONT_WEIGHT, { 0, DEFAULT_FONT_SIZE }, CP_UTF8, false } | ||
{ | ||
_settings = winrt::make_self<implementation::ControlSettings>(settings, unfocusedAppearance); | ||
|
||
_terminal = std::make_shared<::Microsoft::Terminal::Core::Terminal>(); | ||
|
||
// Subscribe to the connection's disconnected event and call our connection closed handlers. | ||
_connectionStateChangedRevoker = _connection.StateChanged(winrt::auto_revoke, [this](auto&& /*s*/, auto&& /*v*/) { | ||
_ConnectionStateChangedHandlers(*this, nullptr); | ||
}); | ||
|
||
// This event is explicitly revoked in the destructor: does not need weak_ref | ||
_connectionOutputEventToken = _connection.TerminalOutput({ this, &ControlCore::_connectionOutputHandler }); | ||
Connection(connection); | ||
|
||
_terminal->SetWriteInputCallback([this](std::wstring_view wstr) { | ||
_sendInputToConnection(wstr); | ||
|
@@ -256,6 +249,54 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
_AttachedHandlers(*this, nullptr); | ||
} | ||
|
||
TerminalConnection::ITerminalConnection ControlCore::Connection() | ||
{ | ||
return _connection; | ||
} | ||
|
||
// Method Description: | ||
// - Setup our event handlers for this connection. If we've currently got a | ||
// connection, then this'll revoke the existing connection's handlers. | ||
void ControlCore::Connection(const TerminalConnection::ITerminalConnection& newConnection) | ||
{ | ||
if (_connection) | ||
{ | ||
_connectionOutputEventRevoker.revoke(); | ||
} | ||
|
||
// Subscribe to the connection's disconnected event and call our connection closed handlers. | ||
_connectionStateChangedRevoker = newConnection.StateChanged(winrt::auto_revoke, [this](auto&& /*s*/, auto&& /*v*/) { | ||
zadjii-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_ConnectionStateChangedHandlers(*this, nullptr); | ||
}); | ||
|
||
// Get our current size in rows/cols, and hook them up to | ||
// this connection too. | ||
{ | ||
const auto vp = _terminal->GetViewport(); | ||
const auto width = vp.Width(); | ||
const auto height = vp.Height(); | ||
|
||
newConnection.Resize(height, width); | ||
lhecker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
// Window owner too. | ||
if (auto conpty{ newConnection.try_as<TerminalConnection::ConptyConnection>() }) | ||
{ | ||
conpty.ReparentWindow(_owningHwnd); | ||
} | ||
const bool replacing = _connection != nullptr; | ||
if (replacing) | ||
{ | ||
_connection.Close(); | ||
} | ||
_connection = newConnection; | ||
// This event is explicitly revoked in the destructor: does not need weak_ref | ||
_connectionOutputEventRevoker = _connection.TerminalOutput(winrt::auto_revoke, { this, &ControlCore::_connectionOutputHandler }); | ||
if (replacing) | ||
{ | ||
_connection.Start(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (A theoretical concern:) If the new connection is already started, this will re-start it. Either, we should replace |
||
} | ||
|
||
bool ControlCore::Initialize(const float actualWidth, | ||
const float actualHeight, | ||
const float compositionScale) | ||
|
@@ -427,8 +468,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
|
||
if (ch == Enter) | ||
{ | ||
_connection.Close(); | ||
_connection.Start(); | ||
// Ask the hosting application to give us a new connection. | ||
_RestartTerminalRequestedHandlers(*this, nullptr); | ||
return true; | ||
} | ||
} | ||
|
@@ -1541,7 +1582,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation | |
_midiAudio.BeginSkip(); | ||
|
||
// Stop accepting new output and state changes before we disconnect everything. | ||
_connection.TerminalOutput(_connectionOutputEventToken); | ||
_connectionOutputEventRevoker.revoke(); | ||
_connectionStateChangedRevoker.revoke(); | ||
_connection.Close(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems a little round-about. 😅