@@ -253,6 +253,29 @@ void WindowEmperor::CreateNewWindow(winrt::TerminalApp::WindowRequestedArgs args
253
253
254
254
_windowCount += 1 ;
255
255
_windows.emplace_back (std::move (host));
256
+
257
+ if (_windowCount == 1 )
258
+ {
259
+ // The first CoreWindow is created implicitly by XAML and parented to the
260
+ // first XAML island. We parent it to our initial window for 2 reasons:
261
+ // * On Windows 10 the CoreWindow will show up as a visible window on the taskbar
262
+ // due to a WinUI bug, and this will hide it, because our initial window is hidden.
263
+ // * When we DestroyWindow() the island it will destroy the CoreWindow,
264
+ // and it's not possible to recreate it. That's also a WinUI bug.
265
+ //
266
+ // Note that this must be done after the first window (= first island) is created.
267
+ if (const auto coreWindow = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread ())
268
+ {
269
+ if (const auto interop = coreWindow.try_as <ICoreWindowInterop>())
270
+ {
271
+ HWND coreHandle = nullptr ;
272
+ if (SUCCEEDED (interop->get_WindowHandle (&coreHandle)) && coreHandle)
273
+ {
274
+ SetParent (coreHandle, _window.get ());
275
+ }
276
+ }
277
+ }
278
+ }
256
279
}
257
280
258
281
AppHost* WindowEmperor::_mostRecentWindow () const noexcept
@@ -395,24 +418,6 @@ void WindowEmperor::HandleCommandlineArgs(int nCmdShow)
395
418
LOG_IF_WIN32_BOOL_FALSE (SetCurrentDirectoryW (system32.c_str ()));
396
419
}
397
420
398
- // The first CoreWindow is created implicitly by XAML and parented to the
399
- // first XAML island. We parent it to our initial window for 2 reasons:
400
- // * On Windows 10 the CoreWindow will show up as a visible window on the taskbar
401
- // due to a WinUI bug, and this will hide it, because our initial window is hidden.
402
- // * When we DestroyWindow() the island it will destroy the CoreWindow,
403
- // and it's not possible to recreate it. That's also a WinUI bug.
404
- if (const auto coreWindow = winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread ())
405
- {
406
- if (const auto interop = coreWindow.try_as <ICoreWindowInterop>())
407
- {
408
- HWND coreHandle = nullptr ;
409
- if (SUCCEEDED (interop->get_WindowHandle (&coreHandle)) && coreHandle)
410
- {
411
- SetParent (coreHandle, _window.get ());
412
- }
413
- }
414
- }
415
-
416
421
{
417
422
TerminalConnection::ConptyConnection::NewConnection ([this ](TerminalConnection::ConptyConnection conn) {
418
423
TerminalApp::CommandlineArgs args;
0 commit comments