Skip to content

Commit 46db89c

Browse files
committed
I cannot believe it was that easy
1 parent e7afa5b commit 46db89c

File tree

8 files changed

+31
-7
lines changed

8 files changed

+31
-7
lines changed

src/cascadia/Remoting/CommandlineArgs.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
1414
}
1515

1616
CommandlineArgs(const winrt::array_view<const winrt::hstring>& args,
17-
winrt::hstring currentDirectory) :
17+
winrt::hstring currentDirectory,
18+
const uint32_t showWindowCommand) :
1819
_args{ args.begin(), args.end() },
19-
_cwd{ currentDirectory }
20+
_cwd{ currentDirectory },
21+
_ShowWindowCommand{ showWindowCommand }
2022
{
2123
}
2224

@@ -25,6 +27,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
2527
void Commandline(const winrt::array_view<const winrt::hstring>& value);
2628
winrt::com_array<winrt::hstring> Commandline();
2729

30+
WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL); // SW_NORMAL is 1, 0 is SW_HIDE
31+
2832
private:
2933
winrt::com_array<winrt::hstring> _args;
3034
winrt::hstring _cwd;

src/cascadia/Remoting/Monarch.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
4646
_Id{ windowInfo.Id() ? windowInfo.Id().Value() : 0 }, // We'll use 0 as a sentinel, since no window will ever get to have that ID
4747
_WindowName{ windowInfo.WindowName() },
4848
_args{ command.Commandline() },
49-
_CurrentDirectory{ command.CurrentDirectory() } {};
49+
_CurrentDirectory{ command.CurrentDirectory() },
50+
_ShowWindowCommand{ command.ShowWindowCommand() } {};
5051

5152
WindowRequestedArgs(const winrt::hstring& window, const winrt::hstring& content, const Windows::Foundation::IReference<Windows::Foundation::Rect>& bounds) :
5253
_Id{ 0u },
@@ -63,6 +64,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
6364
WINRT_PROPERTY(winrt::hstring, WindowName);
6465
WINRT_PROPERTY(winrt::hstring, CurrentDirectory);
6566
WINRT_PROPERTY(winrt::hstring, Content);
67+
WINRT_PROPERTY(uint32_t, ShowWindowCommand, SW_NORMAL);
6668
WINRT_PROPERTY(Windows::Foundation::IReference<Windows::Foundation::Rect>, InitialBounds);
6769

6870
private:

src/cascadia/Remoting/Monarch.idl

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace Microsoft.Terminal.Remoting
2626

2727
String[] Commandline { get; };
2828
String CurrentDirectory { get; };
29+
UInt32 ShowWindowCommand { get; };
2930

3031
String Content { get; };
3132
Windows.Foundation.IReference<Windows.Foundation.Rect> InitialBounds { get; };

src/cascadia/Remoting/Peasant.idl

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ namespace Microsoft.Terminal.Remoting
77
runtimeclass CommandlineArgs
88
{
99
CommandlineArgs();
10-
CommandlineArgs(String[] args, String cwd);
10+
CommandlineArgs(String[] args, String cwd, UInt32 showWindowCommand);
1111

1212
String[] Commandline { get; set; };
1313
String CurrentDirectory();
14+
UInt32 ShowWindowCommand { get; };
1415
};
1516

1617
runtimeclass RenameRequestArgs

src/cascadia/Remoting/WindowManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
319319
// If the name wasn't specified, this will be an empty string.
320320
p->WindowName(args.WindowName());
321321

322-
p->ExecuteCommandline(*winrt::make_self<CommandlineArgs>(args.Commandline(), args.CurrentDirectory()));
322+
p->ExecuteCommandline(*winrt::make_self<CommandlineArgs>(args.Commandline(), args.CurrentDirectory(), args.ShowWindowCommand()));
323323

324324
_monarch.AddPeasant(*p);
325325

src/cascadia/WindowsTerminal/AppHost.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ void AppHost::_HandleCommandlineArgs(const Remoting::WindowRequestedArgs& window
195195
}
196196
}
197197

198+
_launchShowWindowCommand = windowArgs.ShowWindowCommand();
199+
198200
// This is a fix for GH#12190 and hopefully GH#12169.
199201
//
200202
// 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::
12371239
// match the initial settings, and then call ShowWindow to finally make us
12381240
// visible.
12391241

1240-
auto nCmdShow = SW_SHOWDEFAULT;
1242+
// Use the visibility that we were originally requested with as a base. We
1243+
// can't just use SW_SHOWDEFAULT, because that is set on a per-process
1244+
// basis. That means that a second window needs to have its STARTUPINFO's
1245+
// wShowCmd passed into the original process.
1246+
auto nCmdShow = _launchShowWindowCommand;
12411247
if (WI_IsFlagSet(_launchMode, LaunchMode::MaximizedMode))
12421248
{
12431249
nCmdShow = SW_MAXIMIZE;

src/cascadia/WindowsTerminal/AppHost.h

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class AppHost
4343

4444
std::shared_ptr<ThrottledFuncTrailing<bool>> _showHideWindowThrottler;
4545

46+
uint32_t _launchShowWindowCommand{ SW_NORMAL };
47+
4648
void _preInit();
4749

4850
void _HandleCommandlineArgs(const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args);

src/cascadia/WindowsTerminal/WindowEmperor.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ bool WindowEmperor::HandleCommandlineArgs()
7373
_buildArgsFromCommandline(args);
7474
auto cwd{ wil::GetCurrentDirectoryW<std::wstring>() };
7575

76-
Remoting::CommandlineArgs eventArgs{ { args }, { cwd } };
76+
// Get the requested initial state of the window from our startup info. For
77+
// something like `start /min`, this will set the wShowWindow member to
78+
// SW_SHOWMINIMIZED. We'll need to make sure is bubbled all the way through,
79+
// so we can open a new window with the stame state.
80+
STARTUPINFOW si;
81+
GetStartupInfoW(&si);
82+
const auto showWindow = si.wShowWindow;
83+
84+
Remoting::CommandlineArgs eventArgs{ { args }, { cwd }, showWindow };
7785

7886
const auto isolatedMode{ _app.Logic().IsolatedMode() };
7987

0 commit comments

Comments
 (0)