From 46db89cc518acde102ee8798a817f7e40c1f5e54 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 6 Apr 2023 09:43:40 -0500 Subject: [PATCH] I cannot believe it was that easy --- src/cascadia/Remoting/CommandlineArgs.h | 8 ++++++-- src/cascadia/Remoting/Monarch.h | 4 +++- src/cascadia/Remoting/Monarch.idl | 1 + src/cascadia/Remoting/Peasant.idl | 3 ++- src/cascadia/Remoting/WindowManager.cpp | 2 +- src/cascadia/WindowsTerminal/AppHost.cpp | 8 +++++++- src/cascadia/WindowsTerminal/AppHost.h | 2 ++ src/cascadia/WindowsTerminal/WindowEmperor.cpp | 10 +++++++++- 8 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/cascadia/Remoting/CommandlineArgs.h b/src/cascadia/Remoting/CommandlineArgs.h index 5277e1c5f2..4d40c898a6 100644 --- a/src/cascadia/Remoting/CommandlineArgs.h +++ b/src/cascadia/Remoting/CommandlineArgs.h @@ -14,9 +14,11 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation } CommandlineArgs(const winrt::array_view& args, - winrt::hstring currentDirectory) : + winrt::hstring currentDirectory, + const uint32_t showWindowCommand) : _args{ args.begin(), args.end() }, - _cwd{ currentDirectory } + _cwd{ currentDirectory }, + _ShowWindowCommand{ showWindowCommand } { } @@ -25,6 +27,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation void Commandline(const winrt::array_view& value); winrt::com_array Commandline(); + WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL); // SW_NORMAL is 1, 0 is SW_HIDE + private: winrt::com_array _args; winrt::hstring _cwd; diff --git a/src/cascadia/Remoting/Monarch.h b/src/cascadia/Remoting/Monarch.h index ef311fad4e..3b5cc7d9ab 100644 --- a/src/cascadia/Remoting/Monarch.h +++ b/src/cascadia/Remoting/Monarch.h @@ -46,7 +46,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation _Id{ windowInfo.Id() ? windowInfo.Id().Value() : 0 }, // We'll use 0 as a sentinel, since no window will ever get to have that ID _WindowName{ windowInfo.WindowName() }, _args{ command.Commandline() }, - _CurrentDirectory{ command.CurrentDirectory() } {}; + _CurrentDirectory{ command.CurrentDirectory() }, + _ShowWindowCommand{ command.ShowWindowCommand() } {}; WindowRequestedArgs(const winrt::hstring& window, const winrt::hstring& content, const Windows::Foundation::IReference& bounds) : _Id{ 0u }, @@ -63,6 +64,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation WINRT_PROPERTY(winrt::hstring, WindowName); WINRT_PROPERTY(winrt::hstring, CurrentDirectory); WINRT_PROPERTY(winrt::hstring, Content); + WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL); WINRT_PROPERTY(Windows::Foundation::IReference, InitialBounds); private: diff --git a/src/cascadia/Remoting/Monarch.idl b/src/cascadia/Remoting/Monarch.idl index bc60fbe2c7..cc2c45f542 100644 --- a/src/cascadia/Remoting/Monarch.idl +++ b/src/cascadia/Remoting/Monarch.idl @@ -26,6 +26,7 @@ namespace Microsoft.Terminal.Remoting String[] Commandline { get; }; String CurrentDirectory { get; }; + UInt32 ShowWindowCommand { get; }; String Content { get; }; Windows.Foundation.IReference InitialBounds { get; }; diff --git a/src/cascadia/Remoting/Peasant.idl b/src/cascadia/Remoting/Peasant.idl index 2b8780cae8..89e2b52db2 100644 --- a/src/cascadia/Remoting/Peasant.idl +++ b/src/cascadia/Remoting/Peasant.idl @@ -7,10 +7,11 @@ namespace Microsoft.Terminal.Remoting runtimeclass CommandlineArgs { CommandlineArgs(); - CommandlineArgs(String[] args, String cwd); + CommandlineArgs(String[] args, String cwd, UInt32 showWindowCommand); String[] Commandline { get; set; }; String CurrentDirectory(); + UInt32 ShowWindowCommand { get; }; }; runtimeclass RenameRequestArgs diff --git a/src/cascadia/Remoting/WindowManager.cpp b/src/cascadia/Remoting/WindowManager.cpp index 6331e3e9eb..fe9925d52f 100644 --- a/src/cascadia/Remoting/WindowManager.cpp +++ b/src/cascadia/Remoting/WindowManager.cpp @@ -319,7 +319,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation // If the name wasn't specified, this will be an empty string. p->WindowName(args.WindowName()); - p->ExecuteCommandline(*winrt::make_self(args.Commandline(), args.CurrentDirectory())); + p->ExecuteCommandline(*winrt::make_self(args.Commandline(), args.CurrentDirectory(), args.ShowWindowCommand())); _monarch.AddPeasant(*p); diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index b0278ccacd..16fead4f77 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -195,6 +195,8 @@ void AppHost::_HandleCommandlineArgs(const Remoting::WindowRequestedArgs& window } } + _launchShowWindowCommand = windowArgs.ShowWindowCommand(); + // This is a fix for GH#12190 and hopefully GH#12169. // // If the commandline we were provided is going to result in us only @@ -1237,7 +1239,11 @@ winrt::fire_and_forget AppHost::_WindowInitializedHandler(const winrt::Windows:: // match the initial settings, and then call ShowWindow to finally make us // visible. - auto nCmdShow = SW_SHOWDEFAULT; + // Use the visibility that we were originally requested with as a base. We + // can't just use SW_SHOWDEFAULT, because that is set on a per-process + // basis. That means that a second window needs to have its STARTUPINFO's + // wShowCmd passed into the original process. + auto nCmdShow = _launchShowWindowCommand; if (WI_IsFlagSet(_launchMode, LaunchMode::MaximizedMode)) { nCmdShow = SW_MAXIMIZE; diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index 6fa0c5c219..695a07fc89 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -43,6 +43,8 @@ private: std::shared_ptr> _showHideWindowThrottler; + uint32_t _launchShowWindowCommand{ SW_NORMAL }; + void _preInit(); void _HandleCommandlineArgs(const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args); diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index 2438db1256..8f10752cde 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -73,7 +73,15 @@ bool WindowEmperor::HandleCommandlineArgs() _buildArgsFromCommandline(args); auto cwd{ wil::GetCurrentDirectoryW() }; - Remoting::CommandlineArgs eventArgs{ { args }, { cwd } }; + // Get the requested initial state of the window from our startup info. For + // something like `start /min`, this will set the wShowWindow member to + // SW_SHOWMINIMIZED. We'll need to make sure is bubbled all the way through, + // so we can open a new window with the stame state. + STARTUPINFOW si; + GetStartupInfoW(&si); + const auto showWindow = si.wShowWindow; + + Remoting::CommandlineArgs eventArgs{ { args }, { cwd }, showWindow }; const auto isolatedMode{ _app.Logic().IsolatedMode() };