mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-08 13:49:31 +00:00
Manually hide our DesktopWindowXamlSource (#15165)
As discussed in #6507 Newer builds of Windows do this automatically. However, this was spotted in the wild on 1.18. It's possible the threading changes created a situation where the OS-side fix no longer applied to us. So let's just do it manually. It doesn't have any side effects. I saw this once on Win11, but couldn't repro it this morning when I tried to add this fix. I'm just gonna assume this worked, despite the fact that I can't repro it on win11 anymore. closes #6507 See also #14957 ## detailed description > `WindowsXamlManager::XamlCore::Initialize` calls `ConfigureCoreWindow`, which creates a `CoreWindow` on the thread > Problem is, we're calling that on the main thread (which doesn't have _any_ windows), and then eventually creating a `DesktopWindowXamlSource` on a second thread for the actual window > It's not that it "manages a window", it's that it "manages xaml on Windows OS". just use ICoreWindowInterop -- QI for ICoreWindowInterop and call get_WindowHandle. Also see: * [ICoreWindowInterop](https://learn.microsoft.com/en-us/windows/win32/api/corewindow/nn-corewindow-icorewindowinterop) * [WindowsXamlManager.InitializeForCurrentThread](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.hosting.windowsxamlmanager.initializeforcurrentthread?view=winrt-22621#windows-ui-xaml-hosting-windowsxamlmanager-initializeforcurrentthread) * The source code in `onecoreuap\windows\dxaml\xcp\dxaml\lib\WindowsXamlManager_Partial.*` * os.2020!6102020 which fixed MSFT:33498969, MSFT:27807465, MSFT:21854264
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "pch.h"
|
||||
#include "App.h"
|
||||
#include "App.g.cpp"
|
||||
#include <CoreWindow.h>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace winrt::Windows::ApplicationModel::Activation;
|
||||
@@ -32,6 +33,27 @@ namespace winrt::TerminalApp::implementation
|
||||
if (!dispatcherQueue)
|
||||
{
|
||||
_windowsXamlManager = xaml::Hosting::WindowsXamlManager::InitializeForCurrentThread();
|
||||
|
||||
// As of Process Model v3, terminal windows are all created on their
|
||||
// own threads, but we still initiate XAML for the App on the main
|
||||
// thread. Thing is, just initializing XAML creates a CoreWindow for
|
||||
// us. On Windows 10, that CoreWindow will show up as a visible
|
||||
// window on the taskbar, unless we hide it manually. So, go get it
|
||||
// and do the SW_HIDE thing on it.
|
||||
if (const auto& coreWindow{ winrt::Windows::UI::Core::CoreWindow::GetForCurrentThread() })
|
||||
{
|
||||
if (const auto& interop{ coreWindow.try_as<ICoreWindowInterop>() })
|
||||
{
|
||||
HWND coreHandle{ 0 };
|
||||
interop->get_WindowHandle(&coreHandle);
|
||||
if (coreHandle)
|
||||
{
|
||||
// This prevents an empty "DesktopWindowXamlSource" from
|
||||
// appearing on the taskbar
|
||||
ShowWindow(coreHandle, SW_HIDE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -307,6 +307,11 @@ void IslandWindow::Initialize()
|
||||
// stash the child interop handle so we can resize it when the main hwnd is resized
|
||||
interop->get_WindowHandle(&_interopWindowHandle);
|
||||
|
||||
// Immediately hide our XAML island hwnd. On earlier versions of Windows,
|
||||
// this HWND could sometimes appear as an actual window in the taskbar
|
||||
// without this!
|
||||
ShowWindow(_interopWindowHandle, SW_HIDE);
|
||||
|
||||
_rootGrid = winrt::Windows::UI::Xaml::Controls::Grid();
|
||||
_source.Content(_rootGrid);
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ protected:
|
||||
|
||||
HWND _interopWindowHandle;
|
||||
|
||||
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source;
|
||||
winrt::Windows::UI::Xaml::Controls::Grid _rootGrid;
|
||||
winrt::Windows::UI::Xaml::Hosting::DesktopWindowXamlSource _source; // nulled in ctor
|
||||
winrt::Windows::UI::Xaml::Controls::Grid _rootGrid; // nulled in ctor
|
||||
wil::com_ptr<ITaskbarList3> _taskbar;
|
||||
|
||||
std::function<void(const HWND, const til::rect&)> _pfnCreateCallback;
|
||||
|
||||
Reference in New Issue
Block a user