From 103beb4be156d138cce09df2f355304cae526641 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 18 Jul 2022 14:59:19 -0500 Subject: [PATCH 01/15] I just want to run the scratch project, I have no idea how this got so brboken --- .../ScratchIslandApp/Package/Package.wapproj | 4 +- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 24 +++--------- scratch/ScratchIslandApp/SampleApp/MyPage.h | 2 + .../ScratchIslandApp/SampleApp/MyPage.xaml | 4 +- .../SampleApp/SampleAppLib.vcxproj | 13 +++++-- .../SampleApp/dll/SampleApp.vcxproj | 18 +++++++-- scratch/ScratchIslandApp/SampleApp/pch.h | 6 +-- .../WindowExe/SampleIslandWindow.cpp | 2 - .../WindowExe/WindowExe.vcxproj | 38 +++++++++---------- 9 files changed, 56 insertions(+), 55 deletions(-) diff --git a/scratch/ScratchIslandApp/Package/Package.wapproj b/scratch/ScratchIslandApp/Package/Package.wapproj index 4e4ba1090fd..cc12ebd9be5 100644 --- a/scratch/ScratchIslandApp/Package/Package.wapproj +++ b/scratch/ScratchIslandApp/Package/Package.wapproj @@ -49,7 +49,7 @@ - + diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index fbea8e334f1..ed192957d53 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -5,7 +5,6 @@ #include "MyPage.h" #include #include "MyPage.g.cpp" -#include "MySettings.h" using namespace std::chrono_literals; using namespace winrt::Microsoft::Terminal; @@ -26,24 +25,6 @@ namespace winrt::SampleApp::implementation void MyPage::Create() { - auto settings = winrt::make_self(); - - auto connectionSettings{ TerminalConnection::ConptyConnection::CreateSettings(L"cmd.exe /k echo This TermControl is hosted in-proc...", - winrt::hstring{}, - L"", - nullptr, - 32, - 80, - winrt::guid()) }; - - // "Microsoft.Terminal.TerminalConnection.ConptyConnection" - winrt::hstring myClass{ winrt::name_of() }; - TerminalConnection::ConnectionInformation connectInfo{ myClass, connectionSettings }; - - TerminalConnection::ITerminalConnection conn{ TerminalConnection::ConnectionInformation::CreateConnection(connectInfo) }; - Control::TermControl control{ *settings, *settings, conn }; - - InProcContent().Children().Append(control); } // Method Description: @@ -58,4 +39,9 @@ namespace winrt::SampleApp::implementation return { L"Sample Application" }; } + winrt::fire_and_forget MyPage::Create_Click(const winrt::Windows::Foundation::IInspectable& s, const winrt::Windows::Foundation::IInspectable& e) + { + co_await winrt::resume_foreground(Dispatcher()); + } + } diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.h b/scratch/ScratchIslandApp/SampleApp/MyPage.h index c16c02bb39c..e1de8404c08 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.h +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.h @@ -17,6 +17,8 @@ namespace winrt::SampleApp::implementation hstring Title(); + winrt::fire_and_forget Create_Click(const winrt::Windows::Foundation::IInspectable& s, const winrt::Windows::Foundation::IInspectable& e); + private: friend struct MyPageT; // for Xaml to bind events }; diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index 0c132dea21b..eea4605534a 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -9,7 +9,6 @@ xmlns:local="using:SampleApp" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mux="using:Microsoft.UI.Xaml.Controls" - xmlns:terminal="using:Microsoft.Terminal.Control" mc:Ignorable="d"> - diff --git a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj index 3eb935e358e..7022e75d46e 100644 --- a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj +++ b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj @@ -17,9 +17,15 @@ false nested + + + true + true + + - + @@ -147,14 +153,15 @@ + + + - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - true + + + true + true + + - + + @@ -79,15 +86,18 @@ + + + + + - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - @@ -101,5 +111,5 @@ /INCLUDE:DllMain %(AdditionalOptions) - + diff --git a/scratch/ScratchIslandApp/SampleApp/pch.h b/scratch/ScratchIslandApp/SampleApp/pch.h index ba01e45e453..4ac21c1e2ac 100644 --- a/scratch/ScratchIslandApp/SampleApp/pch.h +++ b/scratch/ScratchIslandApp/SampleApp/pch.h @@ -63,9 +63,9 @@ TRACELOGGING_DECLARE_PROVIDER(g_hSampleAppProvider); #include #include -#include -#include -#include +// #include +// #include +// #include // Manually include til after we include Windows.Foundation to give it winrt superpowers #include "til.h" diff --git a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp index 1c5cf10d053..112b47fc17f 100644 --- a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp +++ b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp @@ -104,8 +104,6 @@ void SampleIslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) void SampleIslandWindow::Initialize() { - const bool initialized = (_interopWindowHandle != nullptr); - _source = DesktopWindowXamlSource{}; auto interop = _source.as(); diff --git a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj index 0f2e78cba39..51105bedfec 100644 --- a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj +++ b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj @@ -1,6 +1,5 @@ - {b4427499-9fde-4208-b456-5bc580637633} @@ -16,7 +15,14 @@ Windows + + true + true + true + + + @@ -30,7 +36,7 @@ $(OpenConsoleDir)\src\inc;$(OpenConsoleDir)\dep;$(OpenConsoleDir)\dep\Console;$(OpenConsoleDir)\dep\Win32K;$(OpenConsoleDir)\dep\gsl\include;%(AdditionalIncludeDirectories); - %(AdditionalDependencies) + gdi32.lib;dwmapi.lib;Shcore.lib;UxTheme.lib;%(AdditionalDependencies) @@ -85,7 +91,7 @@ interfaces). However, it too is necessary for Terminal.Control to be able to marshall the Core types across the boundary. --> - + - + - + - - - - - + + From c795793f4c966142a40b1bff47ec5ae4f831fb5f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 18 Jul 2022 14:59:58 -0500 Subject: [PATCH 02/15] Revert "I just want to run the scratch project, I have no idea how this got so brboken" This reverts commit 103beb4be156d138cce09df2f355304cae526641. --- .../ScratchIslandApp/Package/Package.wapproj | 4 +- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 24 +++++++++--- scratch/ScratchIslandApp/SampleApp/MyPage.h | 2 - .../ScratchIslandApp/SampleApp/MyPage.xaml | 4 +- .../SampleApp/SampleAppLib.vcxproj | 13 ++----- .../SampleApp/dll/SampleApp.vcxproj | 18 ++------- scratch/ScratchIslandApp/SampleApp/pch.h | 6 +-- .../WindowExe/SampleIslandWindow.cpp | 2 + .../WindowExe/WindowExe.vcxproj | 38 ++++++++++--------- 9 files changed, 55 insertions(+), 56 deletions(-) diff --git a/scratch/ScratchIslandApp/Package/Package.wapproj b/scratch/ScratchIslandApp/Package/Package.wapproj index cc12ebd9be5..4e4ba1090fd 100644 --- a/scratch/ScratchIslandApp/Package/Package.wapproj +++ b/scratch/ScratchIslandApp/Package/Package.wapproj @@ -49,7 +49,7 @@ - + diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index ed192957d53..fbea8e334f1 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -5,6 +5,7 @@ #include "MyPage.h" #include #include "MyPage.g.cpp" +#include "MySettings.h" using namespace std::chrono_literals; using namespace winrt::Microsoft::Terminal; @@ -25,6 +26,24 @@ namespace winrt::SampleApp::implementation void MyPage::Create() { + auto settings = winrt::make_self(); + + auto connectionSettings{ TerminalConnection::ConptyConnection::CreateSettings(L"cmd.exe /k echo This TermControl is hosted in-proc...", + winrt::hstring{}, + L"", + nullptr, + 32, + 80, + winrt::guid()) }; + + // "Microsoft.Terminal.TerminalConnection.ConptyConnection" + winrt::hstring myClass{ winrt::name_of() }; + TerminalConnection::ConnectionInformation connectInfo{ myClass, connectionSettings }; + + TerminalConnection::ITerminalConnection conn{ TerminalConnection::ConnectionInformation::CreateConnection(connectInfo) }; + Control::TermControl control{ *settings, *settings, conn }; + + InProcContent().Children().Append(control); } // Method Description: @@ -39,9 +58,4 @@ namespace winrt::SampleApp::implementation return { L"Sample Application" }; } - winrt::fire_and_forget MyPage::Create_Click(const winrt::Windows::Foundation::IInspectable& s, const winrt::Windows::Foundation::IInspectable& e) - { - co_await winrt::resume_foreground(Dispatcher()); - } - } diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.h b/scratch/ScratchIslandApp/SampleApp/MyPage.h index e1de8404c08..c16c02bb39c 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.h +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.h @@ -17,8 +17,6 @@ namespace winrt::SampleApp::implementation hstring Title(); - winrt::fire_and_forget Create_Click(const winrt::Windows::Foundation::IInspectable& s, const winrt::Windows::Foundation::IInspectable& e); - private: friend struct MyPageT; // for Xaml to bind events }; diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index eea4605534a..0c132dea21b 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -9,6 +9,7 @@ xmlns:local="using:SampleApp" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mux="using:Microsoft.UI.Xaml.Controls" + xmlns:terminal="using:Microsoft.Terminal.Control" mc:Ignorable="d"> - diff --git a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj index 7022e75d46e..3eb935e358e 100644 --- a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj +++ b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj @@ -17,15 +17,9 @@ false nested - - - true - true - - - + @@ -153,15 +147,14 @@ - - - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + true - - - true - true - - - - + @@ -86,18 +79,15 @@ - - - - - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + @@ -111,5 +101,5 @@ /INCLUDE:DllMain %(AdditionalOptions) - + diff --git a/scratch/ScratchIslandApp/SampleApp/pch.h b/scratch/ScratchIslandApp/SampleApp/pch.h index 4ac21c1e2ac..ba01e45e453 100644 --- a/scratch/ScratchIslandApp/SampleApp/pch.h +++ b/scratch/ScratchIslandApp/SampleApp/pch.h @@ -63,9 +63,9 @@ TRACELOGGING_DECLARE_PROVIDER(g_hSampleAppProvider); #include #include -// #include -// #include -// #include +#include +#include +#include // Manually include til after we include Windows.Foundation to give it winrt superpowers #include "til.h" diff --git a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp index 112b47fc17f..1c5cf10d053 100644 --- a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp +++ b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp @@ -104,6 +104,8 @@ void SampleIslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) void SampleIslandWindow::Initialize() { + const bool initialized = (_interopWindowHandle != nullptr); + _source = DesktopWindowXamlSource{}; auto interop = _source.as(); diff --git a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj index 51105bedfec..0f2e78cba39 100644 --- a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj +++ b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj @@ -1,5 +1,6 @@ + {b4427499-9fde-4208-b456-5bc580637633} @@ -15,14 +16,7 @@ Windows - - true - true - true - - - @@ -36,7 +30,7 @@ $(OpenConsoleDir)\src\inc;$(OpenConsoleDir)\dep;$(OpenConsoleDir)\dep\Console;$(OpenConsoleDir)\dep\Win32K;$(OpenConsoleDir)\dep\gsl\include;%(AdditionalIncludeDirectories); - gdi32.lib;dwmapi.lib;Shcore.lib;UxTheme.lib;%(AdditionalDependencies) + %(AdditionalDependencies) @@ -91,7 +85,7 @@ interfaces). However, it too is necessary for Terminal.Control to be able to marshall the Core types across the boundary. --> - + - + - + - - + + + + + From 11bfc7340058dd2665415d7e500e9803cb1fda2f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 18 Jul 2022 15:05:42 -0500 Subject: [PATCH 03/15] A BLANK SCRATCH COMMIT --- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 32 ++++++++-------- scratch/ScratchIslandApp/SampleApp/MyPage.h | 9 ++++- .../ScratchIslandApp/SampleApp/MyPage.xaml | 38 ++++++++++++++++--- .../SampleApp/SampleAppLib.vcxproj | 17 ++++++--- .../SampleApp/dll/SampleApp.vcxproj | 11 ++++-- .../WindowExe/SampleIslandWindow.cpp | 6 +-- .../WindowExe/WindowExe.vcxproj | 33 +++++++++++----- 7 files changed, 101 insertions(+), 45 deletions(-) diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index fbea8e334f1..b230f573fb0 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -3,9 +3,11 @@ #include "pch.h" #include "MyPage.h" +#include "MySettings.h" #include #include "MyPage.g.cpp" -#include "MySettings.h" +#include "..\..\..\src\cascadia\UnitTests_Control\MockControlSettings.h" +#include "..\..\..\src\types\inc\utils.hpp" using namespace std::chrono_literals; using namespace winrt::Microsoft::Terminal; @@ -26,24 +28,22 @@ namespace winrt::SampleApp::implementation void MyPage::Create() { - auto settings = winrt::make_self(); - - auto connectionSettings{ TerminalConnection::ConptyConnection::CreateSettings(L"cmd.exe /k echo This TermControl is hosted in-proc...", - winrt::hstring{}, - L"", - nullptr, - 32, - 80, - winrt::guid()) }; + } - // "Microsoft.Terminal.TerminalConnection.ConptyConnection" - winrt::hstring myClass{ winrt::name_of() }; - TerminalConnection::ConnectionInformation connectInfo{ myClass, connectionSettings }; + winrt::fire_and_forget MyPage::CreateClicked(const IInspectable& sender, + const WUX::Input::TappedRoutedEventArgs& eventArgs) + { + co_await winrt::resume_background(); + } - TerminalConnection::ITerminalConnection conn{ TerminalConnection::ConnectionInformation::CreateConnection(connectInfo) }; - Control::TermControl control{ *settings, *settings, conn }; + void MyPage::CloseClicked(const IInspectable& /*sender*/, + const WUX::Input::TappedRoutedEventArgs& /*eventArgs*/) + { + } - InProcContent().Children().Append(control); + void MyPage::KillClicked(const IInspectable& /*sender*/, + const WUX::Input::TappedRoutedEventArgs& /*eventArgs*/) + { } // Method Description: diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.h b/scratch/ScratchIslandApp/SampleApp/MyPage.h index c16c02bb39c..88afbbdc0e7 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.h +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.h @@ -14,11 +14,18 @@ namespace winrt::SampleApp::implementation MyPage(); void Create(); - hstring Title(); + winrt::fire_and_forget CreateClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); + void CloseClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); + void KillClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); + private: friend struct MyPageT; // for Xaml to bind events + + wil::unique_process_information piContentProcess; + + winrt::fire_and_forget _writeToLog(std::wstring_view str); }; } diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index 0c132dea21b..033651fae76 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -23,9 +23,23 @@ - + + @@ -46,14 +60,26 @@ VerticalAlignment="Stretch" Background="#ff0000" /> - + VerticalAlignment="Stretch"> + + + + + + + + diff --git a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj index 3eb935e358e..5f7a6f1c282 100644 --- a/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj +++ b/scratch/ScratchIslandApp/SampleApp/SampleAppLib.vcxproj @@ -17,9 +17,15 @@ false nested + + + true + true + + - + @@ -147,14 +153,15 @@ - - + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - + true + + true + true + + - @@ -81,13 +85,11 @@ - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - @@ -102,4 +104,7 @@ + + + diff --git a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp index 1c5cf10d053..eb646f8888a 100644 --- a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp +++ b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp @@ -57,8 +57,8 @@ void SampleIslandWindow::MakeWindow() noexcept WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, - CW_USEDEFAULT, + 1024, + 860, nullptr, nullptr, wc.hInstance, @@ -104,8 +104,6 @@ void SampleIslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) void SampleIslandWindow::Initialize() { - const bool initialized = (_interopWindowHandle != nullptr); - _source = DesktopWindowXamlSource{}; auto interop = _source.as(); diff --git a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj index 0f2e78cba39..0286965dadc 100644 --- a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj +++ b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj @@ -1,6 +1,5 @@ - {b4427499-9fde-4208-b456-5bc580637633} @@ -16,7 +15,15 @@ Windows + + true + true + true + true + + + @@ -138,16 +145,11 @@ - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + <_OpenConsoleExe Include="$(OpenConsoleCommonOutDir)\OpenConsole.exe" /> + + $(ProjectName) + BuiltProjectOutputGroup + %(Filename)%(Extension) + + + - + + + From 1dd6e993401042e318f43a4240804e731cde520e Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 18 Jul 2022 16:57:00 -0500 Subject: [PATCH 04/15] prototype --- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 77 ++++++++++++++++++- .../ScratchIslandApp/SampleApp/MyPage.xaml | 29 +++---- .../SampleApp/dll/SampleApp.vcxproj | 7 ++ scratch/ScratchIslandApp/SampleApp/pch.h | 4 + 4 files changed, 96 insertions(+), 21 deletions(-) diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index b230f573fb0..9c0e2b76053 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -8,7 +8,10 @@ #include "MyPage.g.cpp" #include "..\..\..\src\cascadia\UnitTests_Control\MockControlSettings.h" #include "..\..\..\src\types\inc\utils.hpp" - +#include +#include +#include +#include using namespace std::chrono_literals; using namespace winrt::Microsoft::Terminal; @@ -19,6 +22,9 @@ namespace winrt using IInspectable = Windows::Foundation::IInspectable; } +using namespace winrt::Windows::Graphics::Imaging; +using namespace winrt::Windows::Storage::Streams; + namespace winrt::SampleApp::implementation { MyPage::MyPage() @@ -30,10 +36,79 @@ namespace winrt::SampleApp::implementation { } + winrt::Windows::Graphics::Imaging::SoftwareBitmap MyConvertToSoftwareBitmap(HICON hicon, + winrt::Windows::Graphics::Imaging::BitmapPixelFormat pixelFormat, + winrt::Windows::Graphics::Imaging::BitmapAlphaMode alphaMode, + IWICImagingFactory* imagingFactory) + { + // Load the icon into an IWICBitmap + wil::com_ptr iconBitmap; + THROW_IF_FAILED(imagingFactory->CreateBitmapFromHICON(hicon, iconBitmap.put())); + + // Put the IWICBitmap into a SoftwareBitmap. This may fail if WICBitmap's format is not supported by + // SoftwareBitmap. CreateBitmapFromHICON always creates RGBA8 so we're ok. + auto softwareBitmap = winrt::capture( + winrt::create_instance(CLSID_SoftwareBitmapNativeFactory), + &ISoftwareBitmapNativeFactory::CreateFromWICBitmap, + iconBitmap.get(), + false); + + // Convert the pixel format and alpha mode if necessary + if (softwareBitmap.BitmapPixelFormat() != pixelFormat || softwareBitmap.BitmapAlphaMode() != alphaMode) + { + softwareBitmap = winrt::Windows::Graphics::Imaging::SoftwareBitmap::Convert(softwareBitmap, pixelFormat, alphaMode); + } + + return softwareBitmap; + } + + winrt::Windows::Graphics::Imaging::SoftwareBitmap MyGetBitmapFromIconFileAsync(const winrt::hstring& iconPath, + int32_t iconIndex, + uint32_t iconSize) + { + wil::unique_hicon hicon; + LOG_IF_FAILED(SHDefExtractIcon(iconPath.c_str(), iconIndex, 0, &hicon, nullptr, iconSize)); + + if (!hicon) + { + return nullptr; + } + + wil::com_ptr wicImagingFactory; + THROW_IF_FAILED(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicImagingFactory))); + + return MyConvertToSoftwareBitmap(hicon.get(), BitmapPixelFormat::Bgra8, BitmapAlphaMode::Premultiplied, wicImagingFactory.get()); + } + winrt::fire_and_forget MyPage::CreateClicked(const IInspectable& sender, const WUX::Input::TappedRoutedEventArgs& eventArgs) { + // Try: + // * c:\Windows\System32\SHELL32.dll, 210 + // * c:\Windows\System32\notepad.exe, 0 + // * C:\Program Files\PowerShell\6-preview\pwsh.exe, 0 (this doesn't exist for me) + // * C:\Program Files\PowerShell\7\pwsh.exe, 0 + auto text{ GuidInput().Text() }; + auto index{ static_cast(IconIndex().Value()) }; + co_await winrt::resume_background(); + auto swBitmap{ MyGetBitmapFromIconFileAsync(text, index, 32) }; + if (swBitmap == nullptr) + { + co_return; + } + co_await winrt::resume_foreground(Dispatcher()); + winrt::Windows::UI::Xaml::Media::Imaging::SoftwareBitmapSource bitmapSource{}; + co_await bitmapSource.SetBitmapAsync(swBitmap); + co_await winrt::resume_foreground(Dispatcher()); + + winrt::Microsoft::UI::Xaml::Controls::ImageIconSource imageIconSource{}; + imageIconSource.ImageSource(bitmapSource); + winrt::Microsoft::UI::Xaml::Controls::ImageIcon icon{}; + icon.Source(bitmapSource); + icon.Width(32); + icon.Height(32); + InProcContent().Children().Append(icon); } void MyPage::CloseClicked(const IInspectable& /*sender*/, diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index 033651fae76..cb87b5fe6d4 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -22,24 +22,12 @@ + PlaceholderText="path here" /> + - - @@ -53,12 +41,13 @@ - + + + + + + $(OpenConsoleCommonOutDir)\ConTypes.lib;WindowsApp.lib;shell32.lib;user32.lib;%(AdditionalDependencies) + + diff --git a/scratch/ScratchIslandApp/SampleApp/pch.h b/scratch/ScratchIslandApp/SampleApp/pch.h index ba01e45e453..347389b44a1 100644 --- a/scratch/ScratchIslandApp/SampleApp/pch.h +++ b/scratch/ScratchIslandApp/SampleApp/pch.h @@ -33,6 +33,8 @@ #include #include #include +#include +// #include #include #include #include @@ -41,10 +43,12 @@ #include #include #include +#include #include #include #include "winrt/Windows.UI.Xaml.Markup.h" #include "winrt/Windows.UI.ViewManagement.h" +#include "winrt/Windows.Storage.Streams.h" #include #include From 874a15b89bf88ac071531bf41b4e6c94a09f80d2 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Jul 2022 11:14:17 -0500 Subject: [PATCH 05/15] Good-news-everyone.gif This hooks up the defterm interface to pass more info along in the startup. It's notably not the actual link title, but it does work from a plumbing standpoint This is for #9458 --- src/cascadia/TerminalApp/TerminalPage.cpp | 1 + .../TerminalConnection/CTerminalHandoff.cpp | 4 +- .../TerminalConnection/CTerminalHandoff.h | 5 +- .../TerminalConnection/ConptyConnection.cpp | 33 +++++++- .../TerminalConnection/ConptyConnection.h | 16 +++- .../TerminalConnection/ConptyConnection.idl | 1 + src/host/proxy/ITerminalHandoff.idl | 11 ++- src/host/srvinit.cpp | 77 ++++++++++++++++++- .../inc/ISystemConfigurationProvider.hpp | 9 ++- .../onecore/SystemConfigurationProvider.cpp | 3 +- .../win32/SystemConfigurationProvider.cpp | 13 +++- .../win32/SystemConfigurationProvider.hpp | 3 +- 12 files changed, 159 insertions(+), 17 deletions(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index f4b2f262d62..fdd1699f8b7 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -3191,6 +3191,7 @@ namespace winrt::TerminalApp::implementation { NewTerminalArgs newTerminalArgs; newTerminalArgs.Commandline(connection.Commandline()); + newTerminalArgs.TabTitle(connection.Title()); // GH #12370: We absolutely cannot allow a defterm connection to // auto-elevate. Defterm doesn't work for elevated scenarios in the // first place. If we try accepting the connection, the spawning an diff --git a/src/cascadia/TerminalConnection/CTerminalHandoff.cpp b/src/cascadia/TerminalConnection/CTerminalHandoff.cpp index 1f8d089a626..cf33c4002a1 100644 --- a/src/cascadia/TerminalConnection/CTerminalHandoff.cpp +++ b/src/cascadia/TerminalConnection/CTerminalHandoff.cpp @@ -102,7 +102,7 @@ static HRESULT _duplicateHandle(const HANDLE in, HANDLE& out) noexcept // - E_NOT_VALID_STATE if a event handler is not registered before calling. `::DuplicateHandle` // error codes if we cannot manage to make our own copy of handles to retain. Or S_OK/error // from the registered handler event function. -HRESULT CTerminalHandoff::EstablishPtyHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client) +HRESULT CTerminalHandoff::EstablishPtyHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client, TERMINAL_STARTUP_INFO startupInfo) { try { @@ -132,7 +132,7 @@ HRESULT CTerminalHandoff::EstablishPtyHandoff(HANDLE in, HANDLE out, HANDLE sign THROW_IF_FAILED(_duplicateHandle(client, client)); // Call registered handler from when we started listening. - THROW_IF_FAILED(localPfnHandoff(in, out, signal, ref, server, client)); + THROW_IF_FAILED(localPfnHandoff(in, out, signal, ref, server, client, startupInfo)); #pragma warning(suppress : 26477) TraceLoggingWrite( diff --git a/src/cascadia/TerminalConnection/CTerminalHandoff.h b/src/cascadia/TerminalConnection/CTerminalHandoff.h index 4e43c7b744c..4325e86c2f0 100644 --- a/src/cascadia/TerminalConnection/CTerminalHandoff.h +++ b/src/cascadia/TerminalConnection/CTerminalHandoff.h @@ -26,7 +26,7 @@ Author(s): #define __CLSID_CTerminalHandoff "051F34EE-C1FD-4B19-AF75-9BA54648434C" #endif -using NewHandoffFunction = HRESULT (*)(HANDLE, HANDLE, HANDLE, HANDLE, HANDLE, HANDLE); +using NewHandoffFunction = HRESULT (*)(HANDLE, HANDLE, HANDLE, HANDLE, HANDLE, HANDLE, TERMINAL_STARTUP_INFO); struct __declspec(uuid(__CLSID_CTerminalHandoff)) CTerminalHandoff : public Microsoft::WRL::RuntimeClass, ITerminalHandoff> @@ -37,7 +37,8 @@ struct __declspec(uuid(__CLSID_CTerminalHandoff)) HANDLE signal, HANDLE ref, HANDLE server, - HANDLE client) override; + HANDLE client, + TERMINAL_STARTUP_INFO startupInfo) override; #pragma endregion diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index 6fee6a797e0..6c5b459db4b 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -203,7 +203,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation const HANDLE hOut, const HANDLE hRef, const HANDLE hServerProcess, - const HANDLE hClientProcess) : + const HANDLE hClientProcess, + TERMINAL_STARTUP_INFO startupInfo) : _initialRows{ 25 }, _initialCols{ 80 }, _guid{ Utils::CreateGuid() }, @@ -213,6 +214,27 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation THROW_IF_FAILED(ConptyPackPseudoConsole(hServerProcess, hRef, hSig, &_hPC)); _piClient.hProcess = hClientProcess; +#pragma warning(suppress : 26477 26485 26494 26482 26446) // We don't control TraceLoggingWrite + TraceLoggingWrite( + g_hTerminalConnectionProvider, + "ConptyConnection_CreatedForDefTerm", + TraceLoggingDescription("Event emitted when ConPTY connection is started for a defterm connection"), + TraceLoggingGuid(_guid, "SessionGuid", "The new connection's GUID"), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + + _startupInfo.title = winrt::hstring{ startupInfo.pszTitle }; + _startupInfo.iconPath = winrt::hstring{ startupInfo.pszIconPath }; + _startupInfo.iconIndex = startupInfo.iconIndex; + +#pragma warning(suppress : 26477 26485 26494 26482 26446) // We don't control TraceLoggingWrite + TraceLoggingWrite( + g_hTerminalConnectionProvider, + "ConPty_GotStartupInfoConnected", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingWideString(_startupInfo.title.c_str(), "Title", "The title from the connection"), + TraceLoggingWideString(_startupInfo.iconPath.c_str(), "Icon", "The icon from the connection"), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + // DebugBreak(); try { _commandline = _commandlineFromProcess(hClientProcess); @@ -288,6 +310,11 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation return _commandline; } + winrt::hstring ConptyConnection::Title() const + { + return _startupInfo.title; + } + void ConptyConnection::Start() try { @@ -667,10 +694,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation winrt::event_token ConptyConnection::NewConnection(const NewConnectionHandler& handler) { return _newConnectionHandlers.add(handler); }; void ConptyConnection::NewConnection(const winrt::event_token& token) { _newConnectionHandlers.remove(token); }; - HRESULT ConptyConnection::NewHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client) noexcept + HRESULT ConptyConnection::NewHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client, TERMINAL_STARTUP_INFO startupInfo) noexcept try { - _newConnectionHandlers(winrt::make(signal, in, out, ref, server, client)); + _newConnectionHandlers(winrt::make(signal, in, out, ref, server, client, startupInfo)); return S_OK; } diff --git a/src/cascadia/TerminalConnection/ConptyConnection.h b/src/cascadia/TerminalConnection/ConptyConnection.h index d54ad7e03a3..11d135ff439 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.h +++ b/src/cascadia/TerminalConnection/ConptyConnection.h @@ -8,6 +8,8 @@ #include +#include "ITerminalHandoff.h" + namespace wil { // These belong in WIL upstream, so when we reingest the change that has them we'll get rid of ours. @@ -23,7 +25,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation const HANDLE hOut, const HANDLE hRef, const HANDLE hServerProcess, - const HANDLE hClientProcess); + const HANDLE hClientProcess, + TERMINAL_STARTUP_INFO startupInfo); ConptyConnection() noexcept = default; void Initialize(const Windows::Foundation::Collections::ValueSet& settings); @@ -42,6 +45,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation winrt::guid Guid() const noexcept; winrt::hstring Commandline() const; + winrt::hstring Title() const; static void StartInboundListener(); static void StopInboundListener(); @@ -60,7 +64,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation WINRT_CALLBACK(TerminalOutput, TerminalOutputHandler); private: - static HRESULT NewHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client) noexcept; + static HRESULT NewHandoff(HANDLE in, HANDLE out, HANDLE signal, HANDLE ref, HANDLE server, HANDLE client, TERMINAL_STARTUP_INFO startupInfo) noexcept; static winrt::hstring _commandlineFromProcess(HANDLE process); HRESULT _LaunchAttachedClient() noexcept; @@ -93,6 +97,14 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation std::array _buffer{}; bool _passthroughMode{}; + struct StartupInfoFromDefTerm + { + winrt::hstring title{}; + winrt::hstring iconPath{}; + int32_t iconIndex{}; + + } _startupInfo{}; + DWORD _OutputThread(); }; } diff --git a/src/cascadia/TerminalConnection/ConptyConnection.idl b/src/cascadia/TerminalConnection/ConptyConnection.idl index 82f51b70db3..67e075d0a18 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.idl +++ b/src/cascadia/TerminalConnection/ConptyConnection.idl @@ -12,6 +12,7 @@ namespace Microsoft.Terminal.TerminalConnection ConptyConnection(); Guid Guid { get; }; String Commandline { get; }; + String Title { get; }; void ClearBuffer(); diff --git a/src/host/proxy/ITerminalHandoff.idl b/src/host/proxy/ITerminalHandoff.idl index d06799658ac..3625bff1565 100644 --- a/src/host/proxy/ITerminalHandoff.idl +++ b/src/host/proxy/ITerminalHandoff.idl @@ -4,6 +4,14 @@ import "oaidl.idl"; import "ocidl.idl"; + +typedef struct _TERMINAL_STARTUP_INFO +{ + /*[in, string] */LPCWSTR pszTitle; + /*[in, string] */LPCWSTR pszIconPath; + LONG iconIndex; +} TERMINAL_STARTUP_INFO; + [ object, uuid(59D55CCE-FC8A-48B4-ACE8-0A9286C6557F) @@ -14,5 +22,6 @@ import "ocidl.idl"; [in, system_handle(sh_pipe)] HANDLE signal, [in, system_handle(sh_file)] HANDLE ref, [in, system_handle(sh_process)] HANDLE server, - [in, system_handle(sh_process)] HANDLE client); + [in, system_handle(sh_process)] HANDLE client, + [in] TERMINAL_STARTUP_INFO startupInfo); }; diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index 285809d7002..5728fe568e1 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -18,6 +18,7 @@ #include "../server/Entrypoints.h" #include "../server/IoSorter.h" +#include "../interactivity/inc/ISystemConfigurationProvider.hpp" #include "../interactivity/inc/ServiceLocator.hpp" #include "../interactivity/base/ApiDetector.hpp" #include "../interactivity/base/RemoteConsoleControl.hpp" @@ -179,7 +180,7 @@ static bool s_IsOnDesktop() // We need to see if we were spawned from a link. If we were, we need to // call back into the shell to try to get all the console information from the link. - ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName); + ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName, nullptr); // If we weren't started from a link, this will already be set. // If LoadLinkInfo couldn't find anything, it will remove the flag so we can dig in the registry. @@ -509,12 +510,78 @@ try TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + // DebugBreak(); + + g.pDeviceComm = new ConDrvDeviceComm(Server); + connectMessage->_pDeviceComm = g.pDeviceComm; + + // TODO! Here, add the additional info we pulled out of the StartupInfo + // { + // NEW: + Microsoft::Console::Interactivity::IconInfo icon; + // Old + + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_BeforeConsoleInitializeConnectInfo", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + + CONSOLE_API_CONNECTINFO Cac; + THROW_IF_NTSTATUS_FAILED(ConsoleInitializeConnectInfo(connectMessage, &Cac)); + + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_GotCac", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + // BEGIN ConsoleAllocateConsole(PCONSOLE_API_CONNECTINFO p) + // CALL auto Status = SetUpConsole(&p->ConsoleInfo, p->TitleLength, p->Title, p->CurDir, p->AppName); + Settings* pStartupSettings = &Cac.ConsoleInfo; + DWORD TitleLength = Cac.TitleLength; + LPWSTR Title = Cac.Title; + LPCWSTR CurDir = Cac.CurDir; + LPCWSTR AppName = Cac.AppName; + // BEGIN SetUpConsole(_Inout_ Settings* pStartupSettings, _In_ DWORD TitleLength, _In_reads_bytes_(TitleLength) LPWSTR Title, _In_ LPCWSTR CurDir, _In_ LPCWSTR AppName) + // auto& settings = ServiceLocator::LocateGlobals().getConsoleInformation(); + Settings settings{}; + // We need to see if we were spawned from a link. If we were, we need to + // call back into the shell to try to get all the console information from the link. + ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName, &icon); + + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_LoadedFromLink", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + + // 1. The settings we were passed contains STARTUPINFO structure settings to be applied last. + settings.ApplyStartupInfo(pStartupSettings); + // } + + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_AppliedStartupInfo", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + + TERMINAL_STARTUP_INFO myStartupInfo{ Title, icon.path.c_str(), icon.index }; + + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_CreatedStartupInfo", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingWideString(myStartupInfo.pszTitle, "Title", "The title for the connection"), + TraceLoggingWideString(myStartupInfo.pszIconPath, "Icon", "The icon for the connection"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + RETURN_IF_FAILED(handoff->EstablishPtyHandoff(inPipeTheirSide.get(), outPipeTheirSide.get(), signalPipeTheirSide.get(), refHandle.get(), serverProcess, - clientProcess.get())); + clientProcess.get(), + myStartupInfo)); TraceLoggingWrite(g_hConhostV2EventTraceProvider, "SrvInit_DelegateToTerminalSucceeded", @@ -734,6 +801,12 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand, auto Status = NTSTATUS_FROM_HRESULT(Message->ReadMessageInput(0, &Data, sizeof(Data))); if (!NT_SUCCESS(Status)) { + TraceLoggingWrite(g_hConhostV2EventTraceProvider, + "SrvInit_ConsoleInitializeConnectInfo_ReadMessageInputFailed", + TraceLoggingDescription("TODO! debugging only"), + TraceLoggingUInt64(Status, "Status", "something happened"), + TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), + TraceLoggingKeyword(TIL_KEYWORD_TRACE)); return Status; } diff --git a/src/interactivity/inc/ISystemConfigurationProvider.hpp b/src/interactivity/inc/ISystemConfigurationProvider.hpp index 90431fa51b0..3237d6e51c8 100644 --- a/src/interactivity/inc/ISystemConfigurationProvider.hpp +++ b/src/interactivity/inc/ISystemConfigurationProvider.hpp @@ -19,6 +19,12 @@ class Settings; namespace Microsoft::Console::Interactivity { + struct IconInfo + { + std::wstring path; + int index = 0; + }; + class ISystemConfigurationProvider { public: @@ -36,6 +42,7 @@ namespace Microsoft::Console::Interactivity _Inout_updates_bytes_(*pdwTitleLength) LPWSTR pwszTitle, _Inout_ PDWORD pdwTitleLength, _In_ PCWSTR pwszCurrDir, - _In_ PCWSTR pwszAppName) = 0; + _In_ PCWSTR pwszAppName, + _Inout_opt_ IconInfo* iconInfo) = 0; }; } diff --git a/src/interactivity/onecore/SystemConfigurationProvider.cpp b/src/interactivity/onecore/SystemConfigurationProvider.cpp index 72f06a5b935..21de54447af 100644 --- a/src/interactivity/onecore/SystemConfigurationProvider.cpp +++ b/src/interactivity/onecore/SystemConfigurationProvider.cpp @@ -49,7 +49,8 @@ void SystemConfigurationProvider::GetSettingsFromLink( _Inout_updates_bytes_(*pdwTitleLength) LPWSTR /*pwszTitle*/, _Inout_ PDWORD /*pdwTitleLength*/, _In_ PCWSTR /*pwszCurrDir*/, - _In_ PCWSTR /*pwszAppName*/) + _In_ PCWSTR /*pwszAppName*/, + _Inout_opt_ IconInfo* /*iconInfo*/) { // While both OneCore console renderers use TrueType fonts, there is no // advanced font support on that platform. Namely, there is no way to pick diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index 3aeb9a85432..ab824b0f943 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -60,7 +60,8 @@ void SystemConfigurationProvider::GetSettingsFromLink( _Inout_updates_bytes_(*pdwTitleLength) LPWSTR pwszTitle, _Inout_ PDWORD pdwTitleLength, _In_ PCWSTR pwszCurrDir, - _In_ PCWSTR pwszAppName) + _In_ PCWSTR pwszAppName, + _Inout_opt_ IconInfo* iconInfo) { auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); WCHAR wszLinkTarget[MAX_PATH] = { 0 }; @@ -191,7 +192,15 @@ void SystemConfigurationProvider::GetSettingsFromLink( if (wszIconLocation[0] != L'\0') { - LOG_IF_FAILED(Icon::Instance().LoadIconsFromPath(wszIconLocation, iIconIndex)); + if (iconInfo) + { + iconInfo->path = std::wstring{ wszIconLocation }; + iconInfo->index = iIconIndex; + } + else + { + LOG_IF_FAILED(Icon::Instance().LoadIconsFromPath(wszIconLocation, iIconIndex)); + } } if (!IsValidCodePage(pLinkSettings->GetCodePage())) diff --git a/src/interactivity/win32/SystemConfigurationProvider.hpp b/src/interactivity/win32/SystemConfigurationProvider.hpp index 8c5d9bf65e7..9f743cb00a2 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.hpp +++ b/src/interactivity/win32/SystemConfigurationProvider.hpp @@ -37,7 +37,8 @@ namespace Microsoft::Console::Interactivity::Win32 _Inout_updates_bytes_(*pdwTitleLength) LPWSTR pwszTitle, _Inout_ PDWORD pdwTitleLength, _In_ PCWSTR pwszCurrDir, - _In_ PCWSTR pwszAppName); + _In_ PCWSTR pwszAppName, + _Inout_opt_ IconInfo* iconInfo); private: static const ULONG s_DefaultCursorWidth = 1; From dc78b3267aa56bc77ff0db632579f3f7ba68a9f4 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Jul 2022 12:07:03 -0500 Subject: [PATCH 06/15] this does temporarily get the title out of the link, but then it's lose --- src/host/srvinit.cpp | 1 + src/interactivity/win32/SystemConfigurationProvider.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index 5728fe568e1..b414406be22 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -547,6 +547,7 @@ try Settings settings{}; // We need to see if we were spawned from a link. If we were, we need to // call back into the shell to try to get all the console information from the link. + settings.SetStartupFlags(pStartupSettings->GetStartupFlags()); ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName, &icon); TraceLoggingWrite(g_hConhostV2EventTraceProvider, diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index ab824b0f943..a15b28bafa5 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -73,8 +73,11 @@ void SystemConfigurationProvider::GetSettingsFromLink( // Did we get started from a link? if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME) { - if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) + auto initializeCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + // If it's RPC_E_CHANGED_MODE, that's okay, we're doing a defterm and already started COM + if (SUCCEEDED(initializeCom) || initializeCom == RPC_E_CHANGED_MODE) { + const auto cch = *pdwTitleLength / sizeof(wchar_t); gci.SetLinkTitle(std::wstring(pwszTitle, cch)); @@ -157,7 +160,8 @@ void SystemConfigurationProvider::GetSettingsFromLink( // settings based on title. pLinkSettings->UnsetStartupFlag(STARTF_TITLEISLINKNAME); } - CoUninitialize(); + if (SUCCEEDED(initializeCom)) { + CoUninitialize(); } } } From 9a2ee6a7c29c6bb4c25314acf0e8993594cfbca9 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Jul 2022 12:30:26 -0500 Subject: [PATCH 07/15] Cleanup, comments, etc. --- src/host/srvinit.cpp | 16 +++++++++++++++ .../win32/SystemConfigurationProvider.cpp | 20 +++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index b414406be22..a6505a84d2e 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -199,6 +199,22 @@ static bool s_IsOnDesktop() // strong nudge in that direction. If an application _doesn't_ want VT // processing, it's free to disable this setting, even in conpty mode. settings.SetVirtTermLevel(1); + + // GH#9458 - In the case of a DefTerm handoff, the OriginalTitle might + // be stashed in the lnk. We want to crack that lnk open, so we can get + // that title from it, but we want to discard everything else. So build + // a dummy Settings object here, and read the link settings into it. + // `Title` will get filled with the title from the lnk, which we'll use + // below. + + Settings temp; + // We're not gonna copy over StartupFlags to the main gci settings, + // because we generally don't think those are valuable in ConPTY mode. + // However, we do need to apply them to the temp we've created, so that + // GetSettingsFromLink will actually look for the link settings (it will + // skip that if STARTF_TITLEISLINKNAME is not set). + temp.SetStartupFlags(pStartupSettings->GetStartupFlags()); + ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&temp, Title, &TitleLength, CurDir, AppName, nullptr); } // 1. The settings we were passed contains STARTUPINFO structure settings to be applied last. diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index a15b28bafa5..c8b595d813c 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -73,11 +73,21 @@ void SystemConfigurationProvider::GetSettingsFromLink( // Did we get started from a link? if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME) { - auto initializeCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); - // If it's RPC_E_CHANGED_MODE, that's okay, we're doing a defterm and already started COM - if (SUCCEEDED(initializeCom) || initializeCom == RPC_E_CHANGED_MODE) + auto initializedCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + // GH#9458: If it's RPC_E_CHANGED_MODE, that's okay, we're doing a + // defterm and have already started COM. We can continue on here. + if (SUCCEEDED(initializedCom) || initializedCom == RPC_E_CHANGED_MODE) { - + // Don't CoUninitialize if we still need COM for defterm. + auto unInitCom = wil::scope_exit[initializedCom]() + { + if (SUCCEEDED(initializedCom)) + { + CoUninitialize(); + } + }; + const auto cch = *pdwTitleLength / sizeof(wchar_t); gci.SetLinkTitle(std::wstring(pwszTitle, cch)); @@ -160,8 +170,6 @@ void SystemConfigurationProvider::GetSettingsFromLink( // settings based on title. pLinkSettings->UnsetStartupFlag(STARTF_TITLEISLINKNAME); } - if (SUCCEEDED(initializeCom)) { - CoUninitialize(); } } } From fd75c5e1ea6545682f4d10f3c56e5912a51cb7f9 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 21 Jul 2022 15:07:52 -0500 Subject: [PATCH 08/15] I think this is all the prototyping I need --- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 96 +++++++++++++++++++ .../ScratchIslandApp/SampleApp/MyPage.xaml | 25 ++++- .../win32/SystemConfigurationProvider.cpp | 8 +- 3 files changed, 119 insertions(+), 10 deletions(-) diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index 9c0e2b76053..421670f5f9f 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -35,6 +35,49 @@ namespace winrt::SampleApp::implementation void MyPage::Create() { } +#pragma region BitmapIconSource + template + struct BitmapIconSource + { + }; + + template<> + struct BitmapIconSource + { + using type = winrt::Microsoft::UI::Xaml::Controls::BitmapIconSource; + }; + + template<> + struct BitmapIconSource + { + using type = winrt::Windows::UI::Xaml::Controls::BitmapIconSource; + }; +#pragma endregion + + winrt::Windows::UI::Xaml::Controls::IconSource _getColoredBitmapIcon(const winrt::hstring& path) + { + if (!path.empty()) + { + try + { + winrt::Windows::Foundation::Uri iconUri{ path }; + winrt::Windows::UI::Xaml::Controls::BitmapIconSource iconSource{}; + // Make sure to set this to false, so we keep the RGB data of the + // image. Otherwise, the icon will be white for all the + // non-transparent pixels in the image. + iconSource.ShowAsMonochrome(false); + iconSource.UriSource(iconUri); + return iconSource; + } + CATCH_LOG(); + } + + return nullptr; + } + winrt::Windows::UI::Xaml::Controls::IconSource IconSourceWUX(hstring path) + { + return _getColoredBitmapIcon(path); + } winrt::Windows::Graphics::Imaging::SoftwareBitmap MyConvertToSoftwareBitmap(HICON hicon, winrt::Windows::Graphics::Imaging::BitmapPixelFormat pixelFormat, @@ -109,11 +152,64 @@ namespace winrt::SampleApp::implementation icon.Width(32); icon.Height(32); InProcContent().Children().Append(icon); + + //winrt::Windows::UI::Xaml::Controls::IconSourceElement ise; + //auto casted = imageIconSource.try_as(); + //ise.IconSource(casted); + //icon.Width(32); + //icon.Height(32); + //InProcContent().Children().Append(icon); + + /*NOT this + + + + // WUX::Controls::MenuFlyout menu; + WUX::Controls::MenuFlyoutItem foo; + // auto toWux = icon.try_as(); + WUX::Controls::IconSourceElement wuxIconSourceElem; + wuxIconSourceElem.IconSource(imageIconSource); + foo.Icon(wuxIconSourceElem); // toWux + foo.Text(text); + MyMenu().Items().Append(foo); + + */ + + // WUX::Controls::MenuFlyout menu; + // WUX::Controls::MenuFlyoutItem foo; + // auto toWux = icon.try_as(); + // wuxIconSourceElem.IconSource(imageIconSource); + // foo.Icon(toWux); // toWux + // foo.Text(text); + // MyMenu().Items().Append(foo); + + // const auto iconSource{ IconSourceWUX(text) }; + // WUX::Controls::IconSourceElement iconElement; + // iconElement.IconSource(imageIconSource); + + /////////////////// Try #4 + winrt::Microsoft::UI::Xaml::Controls::ImageIcon icon2{}; + icon2.Source(bitmapSource); + icon2.Width(32); + icon2.Height(32); + WUX::Controls::MenuFlyoutItem foo; + foo.Icon(icon2); + foo.Text(text); + MyMenu().Items().Append(foo); } void MyPage::CloseClicked(const IInspectable& /*sender*/, const WUX::Input::TappedRoutedEventArgs& /*eventArgs*/) { + auto text{ GuidInput().Text() }; + auto bitmapSource = IconSourceWUX(text); + // winrt::Microsoft::UI::Xaml::Controls::ImageIconSource imageIconSource{}; + // imageIconSource.ImageSource(bitmapSource); + winrt::Windows::UI::Xaml::Controls::IconSourceElement icon{}; + icon.IconSource(bitmapSource); + icon.Width(32); + icon.Height(32); + InProcContent().Children().Append(icon); } void MyPage::KillClicked(const IInspectable& /*sender*/, diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index cb87b5fe6d4..dfb50df7f52 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -22,12 +22,31 @@ - + Margin="8" + PlaceholderText="path here" + Text="C:\Program Files\PowerShell\7\pwsh.exe" /> + + + + Lookie here + + + first + + + + diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index c8b595d813c..135b5dfe3dd 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -80,13 +80,7 @@ void SystemConfigurationProvider::GetSettingsFromLink( if (SUCCEEDED(initializedCom) || initializedCom == RPC_E_CHANGED_MODE) { // Don't CoUninitialize if we still need COM for defterm. - auto unInitCom = wil::scope_exit[initializedCom]() - { - if (SUCCEEDED(initializedCom)) - { - CoUninitialize(); - } - }; + auto unInitCom = wil::scope_exit([initializedCom]() { if (SUCCEEDED(initializedCom)){CoUninitialize();} }); const auto cch = *pdwTitleLength / sizeof(wchar_t); From 7268e96ef0ecc39b72a34c962da40dcd795f3167 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 22 Jul 2022 11:00:10 -0500 Subject: [PATCH 09/15] Remove scratch work --- scratch/ScratchIslandApp/SampleApp/MyPage.cpp | 203 ++---------------- scratch/ScratchIslandApp/SampleApp/MyPage.h | 9 +- .../ScratchIslandApp/SampleApp/MyPage.xaml | 62 ++---- scratch/ScratchIslandApp/SampleApp/pch.h | 4 - .../WindowExe/SampleIslandWindow.cpp | 4 +- 5 files changed, 33 insertions(+), 249 deletions(-) diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp index 421670f5f9f..fbea8e334f1 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.cpp +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.cpp @@ -3,15 +3,10 @@ #include "pch.h" #include "MyPage.h" -#include "MySettings.h" #include #include "MyPage.g.cpp" -#include "..\..\..\src\cascadia\UnitTests_Control\MockControlSettings.h" -#include "..\..\..\src\types\inc\utils.hpp" -#include -#include -#include -#include +#include "MySettings.h" + using namespace std::chrono_literals; using namespace winrt::Microsoft::Terminal; @@ -22,9 +17,6 @@ namespace winrt using IInspectable = Windows::Foundation::IInspectable; } -using namespace winrt::Windows::Graphics::Imaging; -using namespace winrt::Windows::Storage::Streams; - namespace winrt::SampleApp::implementation { MyPage::MyPage() @@ -34,187 +26,24 @@ namespace winrt::SampleApp::implementation void MyPage::Create() { - } -#pragma region BitmapIconSource - template - struct BitmapIconSource - { - }; - - template<> - struct BitmapIconSource - { - using type = winrt::Microsoft::UI::Xaml::Controls::BitmapIconSource; - }; - - template<> - struct BitmapIconSource - { - using type = winrt::Windows::UI::Xaml::Controls::BitmapIconSource; - }; -#pragma endregion - - winrt::Windows::UI::Xaml::Controls::IconSource _getColoredBitmapIcon(const winrt::hstring& path) - { - if (!path.empty()) - { - try - { - winrt::Windows::Foundation::Uri iconUri{ path }; - winrt::Windows::UI::Xaml::Controls::BitmapIconSource iconSource{}; - // Make sure to set this to false, so we keep the RGB data of the - // image. Otherwise, the icon will be white for all the - // non-transparent pixels in the image. - iconSource.ShowAsMonochrome(false); - iconSource.UriSource(iconUri); - return iconSource; - } - CATCH_LOG(); - } - - return nullptr; - } - winrt::Windows::UI::Xaml::Controls::IconSource IconSourceWUX(hstring path) - { - return _getColoredBitmapIcon(path); - } + auto settings = winrt::make_self(); - winrt::Windows::Graphics::Imaging::SoftwareBitmap MyConvertToSoftwareBitmap(HICON hicon, - winrt::Windows::Graphics::Imaging::BitmapPixelFormat pixelFormat, - winrt::Windows::Graphics::Imaging::BitmapAlphaMode alphaMode, - IWICImagingFactory* imagingFactory) - { - // Load the icon into an IWICBitmap - wil::com_ptr iconBitmap; - THROW_IF_FAILED(imagingFactory->CreateBitmapFromHICON(hicon, iconBitmap.put())); + auto connectionSettings{ TerminalConnection::ConptyConnection::CreateSettings(L"cmd.exe /k echo This TermControl is hosted in-proc...", + winrt::hstring{}, + L"", + nullptr, + 32, + 80, + winrt::guid()) }; - // Put the IWICBitmap into a SoftwareBitmap. This may fail if WICBitmap's format is not supported by - // SoftwareBitmap. CreateBitmapFromHICON always creates RGBA8 so we're ok. - auto softwareBitmap = winrt::capture( - winrt::create_instance(CLSID_SoftwareBitmapNativeFactory), - &ISoftwareBitmapNativeFactory::CreateFromWICBitmap, - iconBitmap.get(), - false); - - // Convert the pixel format and alpha mode if necessary - if (softwareBitmap.BitmapPixelFormat() != pixelFormat || softwareBitmap.BitmapAlphaMode() != alphaMode) - { - softwareBitmap = winrt::Windows::Graphics::Imaging::SoftwareBitmap::Convert(softwareBitmap, pixelFormat, alphaMode); - } - - return softwareBitmap; - } - - winrt::Windows::Graphics::Imaging::SoftwareBitmap MyGetBitmapFromIconFileAsync(const winrt::hstring& iconPath, - int32_t iconIndex, - uint32_t iconSize) - { - wil::unique_hicon hicon; - LOG_IF_FAILED(SHDefExtractIcon(iconPath.c_str(), iconIndex, 0, &hicon, nullptr, iconSize)); + // "Microsoft.Terminal.TerminalConnection.ConptyConnection" + winrt::hstring myClass{ winrt::name_of() }; + TerminalConnection::ConnectionInformation connectInfo{ myClass, connectionSettings }; - if (!hicon) - { - return nullptr; - } + TerminalConnection::ITerminalConnection conn{ TerminalConnection::ConnectionInformation::CreateConnection(connectInfo) }; + Control::TermControl control{ *settings, *settings, conn }; - wil::com_ptr wicImagingFactory; - THROW_IF_FAILED(CoCreateInstance(CLSID_WICImagingFactory, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wicImagingFactory))); - - return MyConvertToSoftwareBitmap(hicon.get(), BitmapPixelFormat::Bgra8, BitmapAlphaMode::Premultiplied, wicImagingFactory.get()); - } - - winrt::fire_and_forget MyPage::CreateClicked(const IInspectable& sender, - const WUX::Input::TappedRoutedEventArgs& eventArgs) - { - // Try: - // * c:\Windows\System32\SHELL32.dll, 210 - // * c:\Windows\System32\notepad.exe, 0 - // * C:\Program Files\PowerShell\6-preview\pwsh.exe, 0 (this doesn't exist for me) - // * C:\Program Files\PowerShell\7\pwsh.exe, 0 - auto text{ GuidInput().Text() }; - auto index{ static_cast(IconIndex().Value()) }; - - co_await winrt::resume_background(); - auto swBitmap{ MyGetBitmapFromIconFileAsync(text, index, 32) }; - if (swBitmap == nullptr) - { - co_return; - } - co_await winrt::resume_foreground(Dispatcher()); - winrt::Windows::UI::Xaml::Media::Imaging::SoftwareBitmapSource bitmapSource{}; - co_await bitmapSource.SetBitmapAsync(swBitmap); - co_await winrt::resume_foreground(Dispatcher()); - - winrt::Microsoft::UI::Xaml::Controls::ImageIconSource imageIconSource{}; - imageIconSource.ImageSource(bitmapSource); - winrt::Microsoft::UI::Xaml::Controls::ImageIcon icon{}; - icon.Source(bitmapSource); - icon.Width(32); - icon.Height(32); - InProcContent().Children().Append(icon); - - //winrt::Windows::UI::Xaml::Controls::IconSourceElement ise; - //auto casted = imageIconSource.try_as(); - //ise.IconSource(casted); - //icon.Width(32); - //icon.Height(32); - //InProcContent().Children().Append(icon); - - /*NOT this - - - - // WUX::Controls::MenuFlyout menu; - WUX::Controls::MenuFlyoutItem foo; - // auto toWux = icon.try_as(); - WUX::Controls::IconSourceElement wuxIconSourceElem; - wuxIconSourceElem.IconSource(imageIconSource); - foo.Icon(wuxIconSourceElem); // toWux - foo.Text(text); - MyMenu().Items().Append(foo); - - */ - - // WUX::Controls::MenuFlyout menu; - // WUX::Controls::MenuFlyoutItem foo; - // auto toWux = icon.try_as(); - // wuxIconSourceElem.IconSource(imageIconSource); - // foo.Icon(toWux); // toWux - // foo.Text(text); - // MyMenu().Items().Append(foo); - - // const auto iconSource{ IconSourceWUX(text) }; - // WUX::Controls::IconSourceElement iconElement; - // iconElement.IconSource(imageIconSource); - - /////////////////// Try #4 - winrt::Microsoft::UI::Xaml::Controls::ImageIcon icon2{}; - icon2.Source(bitmapSource); - icon2.Width(32); - icon2.Height(32); - WUX::Controls::MenuFlyoutItem foo; - foo.Icon(icon2); - foo.Text(text); - MyMenu().Items().Append(foo); - } - - void MyPage::CloseClicked(const IInspectable& /*sender*/, - const WUX::Input::TappedRoutedEventArgs& /*eventArgs*/) - { - auto text{ GuidInput().Text() }; - auto bitmapSource = IconSourceWUX(text); - // winrt::Microsoft::UI::Xaml::Controls::ImageIconSource imageIconSource{}; - // imageIconSource.ImageSource(bitmapSource); - winrt::Windows::UI::Xaml::Controls::IconSourceElement icon{}; - icon.IconSource(bitmapSource); - icon.Width(32); - icon.Height(32); - InProcContent().Children().Append(icon); - } - - void MyPage::KillClicked(const IInspectable& /*sender*/, - const WUX::Input::TappedRoutedEventArgs& /*eventArgs*/) - { + InProcContent().Children().Append(control); } // Method Description: diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.h b/scratch/ScratchIslandApp/SampleApp/MyPage.h index 88afbbdc0e7..c16c02bb39c 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.h +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.h @@ -14,18 +14,11 @@ namespace winrt::SampleApp::implementation MyPage(); void Create(); - hstring Title(); - winrt::fire_and_forget CreateClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); - void CloseClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); - void KillClicked(const IInspectable& sender, const Windows::UI::Xaml::Input::TappedRoutedEventArgs& eventArgs); + hstring Title(); private: friend struct MyPageT; // for Xaml to bind events - - wil::unique_process_information piContentProcess; - - winrt::fire_and_forget _writeToLog(std::wstring_view str); }; } diff --git a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml index dfb50df7f52..0c132dea21b 100644 --- a/scratch/ScratchIslandApp/SampleApp/MyPage.xaml +++ b/scratch/ScratchIslandApp/SampleApp/MyPage.xaml @@ -22,31 +22,10 @@ - - - - - Lookie here - - - first - - - - @@ -60,34 +39,21 @@ - - - + VerticalAlignment="Stretch" + Background="#ff0000" /> - - - - + - - - diff --git a/scratch/ScratchIslandApp/SampleApp/pch.h b/scratch/ScratchIslandApp/SampleApp/pch.h index 347389b44a1..ba01e45e453 100644 --- a/scratch/ScratchIslandApp/SampleApp/pch.h +++ b/scratch/ScratchIslandApp/SampleApp/pch.h @@ -33,8 +33,6 @@ #include #include #include -#include -// #include #include #include #include @@ -43,12 +41,10 @@ #include #include #include -#include #include #include #include "winrt/Windows.UI.Xaml.Markup.h" #include "winrt/Windows.UI.ViewManagement.h" -#include "winrt/Windows.Storage.Streams.h" #include #include diff --git a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp index eb646f8888a..112b47fc17f 100644 --- a/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp +++ b/scratch/ScratchIslandApp/WindowExe/SampleIslandWindow.cpp @@ -57,8 +57,8 @@ void SampleIslandWindow::MakeWindow() noexcept WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, - 1024, - 860, + CW_USEDEFAULT, + CW_USEDEFAULT, nullptr, nullptr, wc.hInstance, From e333661a15f86d18cbb2f2a62980af1fa0e64ed5 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 22 Jul 2022 13:08:27 -0500 Subject: [PATCH 10/15] cleanup for review --- .../CascadiaPackage/Package-Dev.appxmanifest | 2 +- .../CascadiaPackage/Package-Pre.appxmanifest | 2 +- .../CascadiaPackage/Package.appxmanifest | 2 +- .../TerminalConnection/ConptyConnection.cpp | 17 --- src/host/proxy/ITerminalHandoff.idl | 6 +- src/host/srvinit.cpp | 102 ++++++++---------- 6 files changed, 52 insertions(+), 79 deletions(-) diff --git a/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest b/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest index bc5ec672090..af72612f0db 100644 --- a/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest @@ -99,7 +99,7 @@ - + diff --git a/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest b/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest index eb968f870c6..b1032d58cb5 100644 --- a/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest @@ -188,7 +188,7 @@ - + diff --git a/src/cascadia/CascadiaPackage/Package.appxmanifest b/src/cascadia/CascadiaPackage/Package.appxmanifest index fb494d98aff..8b1dd355cb1 100644 --- a/src/cascadia/CascadiaPackage/Package.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package.appxmanifest @@ -188,7 +188,7 @@ - + diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index 6c5b459db4b..a7577061ef8 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -214,27 +214,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation THROW_IF_FAILED(ConptyPackPseudoConsole(hServerProcess, hRef, hSig, &_hPC)); _piClient.hProcess = hClientProcess; -#pragma warning(suppress : 26477 26485 26494 26482 26446) // We don't control TraceLoggingWrite - TraceLoggingWrite( - g_hTerminalConnectionProvider, - "ConptyConnection_CreatedForDefTerm", - TraceLoggingDescription("Event emitted when ConPTY connection is started for a defterm connection"), - TraceLoggingGuid(_guid, "SessionGuid", "The new connection's GUID"), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - _startupInfo.title = winrt::hstring{ startupInfo.pszTitle }; _startupInfo.iconPath = winrt::hstring{ startupInfo.pszIconPath }; _startupInfo.iconIndex = startupInfo.iconIndex; -#pragma warning(suppress : 26477 26485 26494 26482 26446) // We don't control TraceLoggingWrite - TraceLoggingWrite( - g_hTerminalConnectionProvider, - "ConPty_GotStartupInfoConnected", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingWideString(_startupInfo.title.c_str(), "Title", "The title from the connection"), - TraceLoggingWideString(_startupInfo.iconPath.c_str(), "Icon", "The icon from the connection"), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - // DebugBreak(); try { _commandline = _commandlineFromProcess(hClientProcess); diff --git a/src/host/proxy/ITerminalHandoff.idl b/src/host/proxy/ITerminalHandoff.idl index 3625bff1565..f333a8f0b6b 100644 --- a/src/host/proxy/ITerminalHandoff.idl +++ b/src/host/proxy/ITerminalHandoff.idl @@ -7,14 +7,14 @@ import "ocidl.idl"; typedef struct _TERMINAL_STARTUP_INFO { - /*[in, string] */LPCWSTR pszTitle; - /*[in, string] */LPCWSTR pszIconPath; + LPCWSTR pszTitle; + LPCWSTR pszIconPath; LONG iconIndex; } TERMINAL_STARTUP_INFO; [ object, - uuid(59D55CCE-FC8A-48B4-ACE8-0A9286C6557F) + uuid(AA6B364F-4A50-4176-9002-0AE755E7B5EF) ] interface ITerminalHandoff : IUnknown { HRESULT EstablishPtyHandoff([in, system_handle(sh_pipe)] HANDLE in, diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index a6505a84d2e..4f9f1003b27 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -526,71 +526,61 @@ try TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - // DebugBreak(); + // As a part of defterm handoff, we're gonna try to pull a lot of + // information out of the link and startup info, so we can let the terminal + // know these things as well. + // + // To let the terminal know these things, we have to look them up now, + // before we normally would. + // + // Typically, we'll just go into `ConsoleCreateIoThread` below, which will + // pull out the CONSOLE_API_CONNECTINFO from this connect message, and then + // get the liink properties out of the title later. Below are elements of + // ConsoleAllocateConsole and SetUpConsole that get the bits of STARTUP_INFO + // we care about for defterm handoffs. + + // A placeholder that we'll read icon information into, instead of setting + // the globals icon state. + Microsoft::Console::Interactivity::IconInfo icon; + // To be able to actually process this connect message into a + // CONSOLE_API_CONNECTINFO, we need to hook up the ConDrvDeviceComm to the + // message. Usually, we'd create the ConDrvDeviceComm later, in + // ConsoleServerInitialization, but we can set it up early here. + // ConsoleServerInitialization will safely no-op if it already finds one. g.pDeviceComm = new ConDrvDeviceComm(Server); + // load bearing: if you don't set this, the ConsoleInitializeConnectInfo will fail. connectMessage->_pDeviceComm = g.pDeviceComm; - - // TODO! Here, add the additional info we pulled out of the StartupInfo - // { - // NEW: - Microsoft::Console::Interactivity::IconInfo icon; - // Old - - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_BeforeConsoleInitializeConnectInfo", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - CONSOLE_API_CONNECTINFO Cac; - THROW_IF_NTSTATUS_FAILED(ConsoleInitializeConnectInfo(connectMessage, &Cac)); + RETURN_IF_NTSTATUS_FAILED(ConsoleInitializeConnectInfo(connectMessage, &Cac)); - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_GotCac", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - // BEGIN ConsoleAllocateConsole(PCONSOLE_API_CONNECTINFO p) - // CALL auto Status = SetUpConsole(&p->ConsoleInfo, p->TitleLength, p->Title, p->CurDir, p->AppName); - Settings* pStartupSettings = &Cac.ConsoleInfo; - DWORD TitleLength = Cac.TitleLength; - LPWSTR Title = Cac.Title; - LPCWSTR CurDir = Cac.CurDir; - LPCWSTR AppName = Cac.AppName; - // BEGIN SetUpConsole(_Inout_ Settings* pStartupSettings, _In_ DWORD TitleLength, _In_reads_bytes_(TitleLength) LPWSTR Title, _In_ LPCWSTR CurDir, _In_ LPCWSTR AppName) - // auto& settings = ServiceLocator::LocateGlobals().getConsoleInformation(); + // BEGIN code from SetUpConsole + // Create a temporary Settings object to parse the settings into, rather + // than parsing them into the global settings object (gci). Settings settings{}; // We need to see if we were spawned from a link. If we were, we need to - // call back into the shell to try to get all the console information from the link. - settings.SetStartupFlags(pStartupSettings->GetStartupFlags()); - ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, Title, &TitleLength, CurDir, AppName, &icon); - - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_LoadedFromLink", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + // call back into the OS shell to try to get all the console information from the link. + // + // load bearing: if you don't pass the StartupFlags, then + // GetSettingsFromLink might not even bother attempting to check the lnk. + settings.SetStartupFlags(Cac.ConsoleInfo.GetStartupFlags()); + ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&settings, + Cac.Title, + &Cac.TitleLength, + Cac.CurDir, + Cac.AppName, + &icon); // 1. The settings we were passed contains STARTUPINFO structure settings to be applied last. - settings.ApplyStartupInfo(pStartupSettings); - // } - - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_AppliedStartupInfo", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); - - TERMINAL_STARTUP_INFO myStartupInfo{ Title, icon.path.c_str(), icon.index }; - - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_CreatedStartupInfo", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingWideString(myStartupInfo.pszTitle, "Title", "The title for the connection"), - TraceLoggingWideString(myStartupInfo.pszIconPath, "Icon", "The icon for the connection"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); + settings.ApplyStartupInfo(&Cac.ConsoleInfo); + // END code from SetUpConsole + + // Take what we've collected, and bundle it up for handoff. + TERMINAL_STARTUP_INFO myStartupInfo{ + Cac.Title, + icon.path.c_str(), + icon.index + }; RETURN_IF_FAILED(handoff->EstablishPtyHandoff(inPipeTheirSide.get(), outPipeTheirSide.get(), From 879a955f3b0c18bb5f5b9d98e8641393812d4860 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 22 Jul 2022 13:13:31 -0500 Subject: [PATCH 11/15] more comments, cleanup --- src/host/srvinit.cpp | 6 ------ src/interactivity/win32/SystemConfigurationProvider.cpp | 4 ++++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index 4f9f1003b27..88b5e08aaac 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -808,12 +808,6 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand, auto Status = NTSTATUS_FROM_HRESULT(Message->ReadMessageInput(0, &Data, sizeof(Data))); if (!NT_SUCCESS(Status)) { - TraceLoggingWrite(g_hConhostV2EventTraceProvider, - "SrvInit_ConsoleInitializeConnectInfo_ReadMessageInputFailed", - TraceLoggingDescription("TODO! debugging only"), - TraceLoggingUInt64(Status, "Status", "something happened"), - TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE), - TraceLoggingKeyword(TIL_KEYWORD_TRACE)); return Status; } diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index 135b5dfe3dd..982311cb7e3 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -198,6 +198,10 @@ void SystemConfigurationProvider::GetSettingsFromLink( if (wszIconLocation[0] != L'\0') { + // GH#9458, GH#13111 - when this is executed during defterm startup, + // we'll pass in an iconInfo pointer, which we should fill wiht the + // selected icon path and index, rather than loading the icon with our + // global Icon class. if (iconInfo) { iconInfo->path = std::wstring{ wszIconLocation }; From 5bf3c1ee5066413c7166995512dee462b7d9e7c6 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 26 Jul 2022 10:29:48 -0500 Subject: [PATCH 12/15] had this all before the long weekend --- .github/actions/spelling/expect/expect.txt | 6 ++--- .../TerminalConnection/CTerminalHandoff.h | 2 +- src/host/proxy/ITerminalHandoff.idl | 23 ++++++++++++++++++- src/host/srvinit.cpp | 4 ++-- .../win32/SystemConfigurationProvider.cpp | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 507f33cb5cb..c091d97fef3 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -1831,9 +1831,9 @@ placeholders platforming playsound plist -PLOC -PLOCA -PLOCM +ploc +ploca +plocm PLOGICAL plugin PMv diff --git a/src/cascadia/TerminalConnection/CTerminalHandoff.h b/src/cascadia/TerminalConnection/CTerminalHandoff.h index 4325e86c2f0..cdeb87f6af9 100644 --- a/src/cascadia/TerminalConnection/CTerminalHandoff.h +++ b/src/cascadia/TerminalConnection/CTerminalHandoff.h @@ -29,7 +29,7 @@ Author(s): using NewHandoffFunction = HRESULT (*)(HANDLE, HANDLE, HANDLE, HANDLE, HANDLE, HANDLE, TERMINAL_STARTUP_INFO); struct __declspec(uuid(__CLSID_CTerminalHandoff)) - CTerminalHandoff : public Microsoft::WRL::RuntimeClass, ITerminalHandoff> + CTerminalHandoff : public Microsoft::WRL::RuntimeClass, ITerminalHandoff2> { #pragma region ITerminalHandoff STDMETHODIMP EstablishPtyHandoff(HANDLE in, diff --git a/src/host/proxy/ITerminalHandoff.idl b/src/host/proxy/ITerminalHandoff.idl index f333a8f0b6b..9c92157eb62 100644 --- a/src/host/proxy/ITerminalHandoff.idl +++ b/src/host/proxy/ITerminalHandoff.idl @@ -12,10 +12,31 @@ typedef struct _TERMINAL_STARTUP_INFO LONG iconIndex; } TERMINAL_STARTUP_INFO; +// LOAD BEARING! +// +// There is only ever one OpenConsoleProxy.dll loaded by COM for _ALL_ terminal +// instances, across Dev, Preview, Stable, whatever. So we have to keep all old +// versions of interfaces in the file here, even if the old version is no longer +// in use. + [ object, - uuid(AA6B364F-4A50-4176-9002-0AE755E7B5EF) + uuid(59D55CCE-FC8A-48B4-ACE8-0A9286C6557F) ] interface ITerminalHandoff : IUnknown +{ + // DEPRECATED! + HRESULT EstablishPtyHandoff([in, system_handle(sh_pipe)] HANDLE in, + [in, system_handle(sh_pipe)] HANDLE out, + [in, system_handle(sh_pipe)] HANDLE signal, + [in, system_handle(sh_file)] HANDLE ref, + [in, system_handle(sh_process)] HANDLE server, + [in, system_handle(sh_process)] HANDLE client); +}; + +[ + object, + uuid(AA6B364F-4A50-4176-9002-0AE755E7B5EF) +] interface ITerminalHandoff2 : IUnknown { HRESULT EstablishPtyHandoff([in, system_handle(sh_pipe)] HANDLE in, [in, system_handle(sh_pipe)] HANDLE out, diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index 88b5e08aaac..22463407905 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -511,7 +511,7 @@ try const auto serverProcess = GetCurrentProcess(); - ::Microsoft::WRL::ComPtr handoff; + ::Microsoft::WRL::ComPtr handoff; TraceLoggingWrite(g_hConhostV2EventTraceProvider, "SrvInit_PrepareToCreateDelegationTerminal", @@ -535,7 +535,7 @@ try // // Typically, we'll just go into `ConsoleCreateIoThread` below, which will // pull out the CONSOLE_API_CONNECTINFO from this connect message, and then - // get the liink properties out of the title later. Below are elements of + // get the link properties out of the title later. Below are elements of // ConsoleAllocateConsole and SetUpConsole that get the bits of STARTUP_INFO // we care about for defterm handoffs. diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index 982311cb7e3..c4c74865c92 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -199,7 +199,7 @@ void SystemConfigurationProvider::GetSettingsFromLink( if (wszIconLocation[0] != L'\0') { // GH#9458, GH#13111 - when this is executed during defterm startup, - // we'll pass in an iconInfo pointer, which we should fill wiht the + // we'll pass in an iconInfo pointer, which we should fill with the // selected icon path and index, rather than loading the icon with our // global Icon class. if (iconInfo) From 18a62bdae7053c4b19643b1159aa93ad153eeece Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 26 Jul 2022 10:43:36 -0500 Subject: [PATCH 13/15] I think I'm gonna need to put EVERYTHING in here --- src/host/proxy/ITerminalHandoff.idl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/host/proxy/ITerminalHandoff.idl b/src/host/proxy/ITerminalHandoff.idl index 9c92157eb62..0ce985829f0 100644 --- a/src/host/proxy/ITerminalHandoff.idl +++ b/src/host/proxy/ITerminalHandoff.idl @@ -7,9 +7,27 @@ import "ocidl.idl"; typedef struct _TERMINAL_STARTUP_INFO { + // In STARTUPINFO LPCWSTR pszTitle; + + // Also wanted LPCWSTR pszIconPath; LONG iconIndex; + + // The rest of STARTUPINFO + DWORD dwX; + DWORD dwY; + DWORD dwXSize; + DWORD dwYSize; + DWORD dwXCountChars; + DWORD dwYCountChars; + DWORD dwFillAttribute; + DWORD dwFlags; + WORD wShowWindow; + + // Something else we may be interested in? + LPCWSTR fontFace; + LONG fontSize; } TERMINAL_STARTUP_INFO; // LOAD BEARING! From 3ce349e81b79336c21679b9c19818810dd5a3e81 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 12 Aug 2022 12:56:07 -0500 Subject: [PATCH 14/15] big s/o to whoever added the onecore projects to the oss repo, so we caught it --- src/interactivity/onecore/SystemConfigurationProvider.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interactivity/onecore/SystemConfigurationProvider.hpp b/src/interactivity/onecore/SystemConfigurationProvider.hpp index 658c8e69548..054e8053af6 100644 --- a/src/interactivity/onecore/SystemConfigurationProvider.hpp +++ b/src/interactivity/onecore/SystemConfigurationProvider.hpp @@ -37,7 +37,8 @@ namespace Microsoft::Console::Interactivity::OneCore _Inout_updates_bytes_(*pdwTitleLength) LPWSTR pwszTitle, _Inout_ PDWORD pdwTitleLength, _In_ PCWSTR pwszCurrDir, - _In_ PCWSTR pwszAppName) override; + _In_ PCWSTR pwszAppName, + _Inout_opt_ IconInfo* iconInfo) override; private: static constexpr UINT s_DefaultCaretBlinkTime = 530; // milliseconds From 38de95efa842bdee74976e1317630f92a649a018 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 19 Aug 2022 10:04:37 -0500 Subject: [PATCH 15/15] Code review notes --- src/cascadia/CascadiaPackage/Package-Dev.appxmanifest | 3 ++- src/cascadia/CascadiaPackage/Package-Pre.appxmanifest | 3 ++- src/cascadia/CascadiaPackage/Package.appxmanifest | 3 ++- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- src/cascadia/TerminalConnection/ConptyConnection.cpp | 8 +++++--- src/cascadia/TerminalConnection/ConptyConnection.h | 2 +- src/cascadia/TerminalConnection/ConptyConnection.idl | 2 +- src/host/proxy/ITerminalHandoff.idl | 8 ++------ src/host/srvinit.cpp | 6 ++++-- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest b/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest index af72612f0db..102539275c6 100644 --- a/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package-Dev.appxmanifest @@ -99,7 +99,8 @@ - + + diff --git a/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest b/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest index b1032d58cb5..934a105044c 100644 --- a/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package-Pre.appxmanifest @@ -188,7 +188,8 @@ - + + diff --git a/src/cascadia/CascadiaPackage/Package.appxmanifest b/src/cascadia/CascadiaPackage/Package.appxmanifest index 8b1dd355cb1..82b1ce1b5de 100644 --- a/src/cascadia/CascadiaPackage/Package.appxmanifest +++ b/src/cascadia/CascadiaPackage/Package.appxmanifest @@ -188,7 +188,8 @@ - + + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 5fcf4cf4092..36937f4481d 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -3270,7 +3270,7 @@ namespace winrt::TerminalApp::implementation { NewTerminalArgs newTerminalArgs; newTerminalArgs.Commandline(connection.Commandline()); - newTerminalArgs.TabTitle(connection.Title()); + newTerminalArgs.TabTitle(connection.StartingTitle()); // GH #12370: We absolutely cannot allow a defterm connection to // auto-elevate. Defterm doesn't work for elevated scenarios in the // first place. If we try accepting the connection, the spawning an diff --git a/src/cascadia/TerminalConnection/ConptyConnection.cpp b/src/cascadia/TerminalConnection/ConptyConnection.cpp index a7577061ef8..2f0b55ca9c5 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.cpp +++ b/src/cascadia/TerminalConnection/ConptyConnection.cpp @@ -214,8 +214,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation THROW_IF_FAILED(ConptyPackPseudoConsole(hServerProcess, hRef, hSig, &_hPC)); _piClient.hProcess = hClientProcess; - _startupInfo.title = winrt::hstring{ startupInfo.pszTitle }; - _startupInfo.iconPath = winrt::hstring{ startupInfo.pszIconPath }; + _startupInfo.title = winrt::hstring{ startupInfo.pszTitle, SysStringLen(startupInfo.pszTitle) }; + SysFreeString(startupInfo.pszTitle); + _startupInfo.iconPath = winrt::hstring{ startupInfo.pszIconPath, SysStringLen(startupInfo.pszIconPath) }; + SysFreeString(startupInfo.pszIconPath); _startupInfo.iconIndex = startupInfo.iconIndex; try @@ -293,7 +295,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation return _commandline; } - winrt::hstring ConptyConnection::Title() const + winrt::hstring ConptyConnection::StartingTitle() const { return _startupInfo.title; } diff --git a/src/cascadia/TerminalConnection/ConptyConnection.h b/src/cascadia/TerminalConnection/ConptyConnection.h index 11d135ff439..beaaac058f1 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.h +++ b/src/cascadia/TerminalConnection/ConptyConnection.h @@ -45,7 +45,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation winrt::guid Guid() const noexcept; winrt::hstring Commandline() const; - winrt::hstring Title() const; + winrt::hstring StartingTitle() const; static void StartInboundListener(); static void StopInboundListener(); diff --git a/src/cascadia/TerminalConnection/ConptyConnection.idl b/src/cascadia/TerminalConnection/ConptyConnection.idl index 67e075d0a18..d284e2ce4a9 100644 --- a/src/cascadia/TerminalConnection/ConptyConnection.idl +++ b/src/cascadia/TerminalConnection/ConptyConnection.idl @@ -12,7 +12,7 @@ namespace Microsoft.Terminal.TerminalConnection ConptyConnection(); Guid Guid { get; }; String Commandline { get; }; - String Title { get; }; + String StartingTitle { get; }; void ClearBuffer(); diff --git a/src/host/proxy/ITerminalHandoff.idl b/src/host/proxy/ITerminalHandoff.idl index 0ce985829f0..37906770f0d 100644 --- a/src/host/proxy/ITerminalHandoff.idl +++ b/src/host/proxy/ITerminalHandoff.idl @@ -8,10 +8,10 @@ import "ocidl.idl"; typedef struct _TERMINAL_STARTUP_INFO { // In STARTUPINFO - LPCWSTR pszTitle; + BSTR pszTitle; // Also wanted - LPCWSTR pszIconPath; + BSTR pszIconPath; LONG iconIndex; // The rest of STARTUPINFO @@ -24,10 +24,6 @@ typedef struct _TERMINAL_STARTUP_INFO DWORD dwFillAttribute; DWORD dwFlags; WORD wShowWindow; - - // Something else we may be interested in? - LPCWSTR fontFace; - LONG fontSize; } TERMINAL_STARTUP_INFO; // LOAD BEARING! diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index 22463407905..6b12075cc67 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -576,9 +576,11 @@ try // END code from SetUpConsole // Take what we've collected, and bundle it up for handoff. + auto title = wil::make_bstr(Cac.Title); + auto iconPath = wil::make_bstr(icon.path.data()); TERMINAL_STARTUP_INFO myStartupInfo{ - Cac.Title, - icon.path.c_str(), + title.get(), + iconPath.get(), icon.index };