I cannot believe it was that easy

This commit is contained in:
Mike Griese
2023-04-06 09:43:40 -05:00
parent e7afa5b6f6
commit 46db89cc51
8 changed files with 31 additions and 7 deletions

View File

@@ -14,9 +14,11 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
}
CommandlineArgs(const winrt::array_view<const winrt::hstring>& 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<const winrt::hstring>& value);
winrt::com_array<winrt::hstring> Commandline();
WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL); // SW_NORMAL is 1, 0 is SW_HIDE
private:
winrt::com_array<winrt::hstring> _args;
winrt::hstring _cwd;

View File

@@ -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<Windows::Foundation::Rect>& 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<Windows::Foundation::Rect>, InitialBounds);
private:

View File

@@ -26,6 +26,7 @@ namespace Microsoft.Terminal.Remoting
String[] Commandline { get; };
String CurrentDirectory { get; };
UInt32 ShowWindowCommand { get; };
String Content { get; };
Windows.Foundation.IReference<Windows.Foundation.Rect> InitialBounds { get; };

View File

@@ -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

View File

@@ -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<CommandlineArgs>(args.Commandline(), args.CurrentDirectory()));
p->ExecuteCommandline(*winrt::make_self<CommandlineArgs>(args.Commandline(), args.CurrentDirectory(), args.ShowWindowCommand()));
_monarch.AddPeasant(*p);

View File

@@ -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;

View File

@@ -43,6 +43,8 @@ private:
std::shared_ptr<ThrottledFuncTrailing<bool>> _showHideWindowThrottler;
uint32_t _launchShowWindowCommand{ SW_NORMAL };
void _preInit();
void _HandleCommandlineArgs(const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args);

View File

@@ -73,7 +73,15 @@ bool WindowEmperor::HandleCommandlineArgs()
_buildArgsFromCommandline(args);
auto cwd{ wil::GetCurrentDirectoryW<std::wstring>() };
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() };