@@ -56,6 +56,10 @@ DWORD WINAPI PtySignalInputThread::StaticThreadProc(_In_ LPVOID lpParameter)
56
56
// (in and screen buffers) haven't yet been initialized.
57
57
// - NOTE: Call under LockConsole() to ensure other threads have an opportunity
58
58
// to set early-work state.
59
+ // - We need to do this specifically on the thread with the message pump. If the
60
+ // window is created on another thread, then the window won't have a message
61
+ // pump associated with it, and a DPI change in the connected terminal could
62
+ // end up HANGING THE CONPTY (for example).
59
63
// Arguments:
60
64
// - <none>
61
65
// Return Value:
@@ -71,6 +75,12 @@ void PtySignalInputThread::ConnectConsole() noexcept
71
75
{
72
76
_DoShowHide (_initialShowHide->show );
73
77
}
78
+
79
+ // If we were given a owner HWND, then manually start the pseudo window now.
80
+ if (_earlyReparent)
81
+ {
82
+ _DoSetWindowParent (*_earlyReparent);
83
+ }
74
84
}
75
85
76
86
// Method Description:
@@ -150,6 +160,28 @@ void PtySignalInputThread::ConnectConsole() noexcept
150
160
151
161
break ;
152
162
}
163
+ case PtySignal::SetParent:
164
+ {
165
+ SetParentData reparentMessage = { 0 };
166
+ _GetData (&reparentMessage, sizeof (reparentMessage));
167
+
168
+ LockConsole ();
169
+ auto Unlock = wil::scope_exit ([&] { UnlockConsole (); });
170
+
171
+ // If the client app hasn't yet connected, stash the new owner.
172
+ // We'll later (PtySignalInputThread::ConnectConsole) use the value
173
+ // to set up the owner of the conpty window.
174
+ if (!_consoleConnected)
175
+ {
176
+ _earlyReparent = reparentMessage;
177
+ }
178
+ else
179
+ {
180
+ _DoSetWindowParent (reparentMessage);
181
+ }
182
+
183
+ break ;
184
+ }
153
185
default :
154
186
{
155
187
THROW_HR (E_UNEXPECTED);
@@ -183,6 +215,20 @@ void PtySignalInputThread::_DoShowHide(const bool show)
183
215
_pConApi->ShowWindow (show);
184
216
}
185
217
218
+ // Method Description:
219
+ // - Update the owner of the pseudo-window we're using for the conpty HWND. This
220
+ // allows to mark the pseudoconsole windows as "owner" by the terminal HWND
221
+ // that's actually hosting them.
222
+ // - Refer to GH#2988
223
+ // Arguments:
224
+ // - data - Packet information containing owner HWND information
225
+ // Return Value:
226
+ // - <none>
227
+ void PtySignalInputThread::_DoSetWindowParent (const SetParentData& data)
228
+ {
229
+ _pConApi->ReparentWindow (data.handle );
230
+ }
231
+
186
232
// Method Description:
187
233
// - Retrieves bytes from the file stream and exits or throws errors should the pipe state
188
234
// be compromised.
0 commit comments