Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect the startup info state initially passed to wt via ShellExecute #13838

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
103beb4
I just want to run the scratch project, I have no idea how this got s…
zadjii-msft Jul 18, 2022
c795793
Revert "I just want to run the scratch project, I have no idea how th…
zadjii-msft Jul 18, 2022
11bfc73
A BLANK SCRATCH COMMIT
zadjii-msft Jul 18, 2022
1dd6e99
prototype
zadjii-msft Jul 18, 2022
874a15b
Good-news-everyone.gif
zadjii-msft Jul 19, 2022
dc78b32
this does temporarily get the title out of the link, but then it's lose
zadjii-msft Jul 19, 2022
9a2ee6a
Cleanup, comments, etc.
zadjii-msft Jul 19, 2022
fd75c5e
I think this is all the prototyping I need
zadjii-msft Jul 21, 2022
4b717db
Merge remote-tracking branch 'origin/main' into dev/migrie/f/9458-sta…
zadjii-msft Jul 22, 2022
c0b4840
Merge remote-tracking branch 'origin/main' into dev/migrie/f/9458-sta…
zadjii-msft Jul 22, 2022
7268e96
Remove scratch work
zadjii-msft Jul 22, 2022
e333661
cleanup for review
zadjii-msft Jul 22, 2022
879a955
more comments, cleanup
zadjii-msft Jul 22, 2022
5bf3c1e
had this all before the long weekend
zadjii-msft Jul 26, 2022
01420b9
Merge remote-tracking branch 'origin/main' into dev/migrie/f/9458-sta…
zadjii-msft Jul 26, 2022
18a62bd
I think I'm gonna need to put EVERYTHING in here
zadjii-msft Jul 26, 2022
d2336e3
Merge remote-tracking branch 'origin/main' into dev/migrie/f/9458-sta…
zadjii-msft Aug 11, 2022
3ce349e
big s/o to whoever added the onecore projects to the oss repo, so we …
zadjii-msft Aug 12, 2022
5849279
Merge branch 'main' into dev/migrie/f/9458-startupInfoToTerminal
zadjii-msft Aug 19, 2022
38de95e
Code review notes
zadjii-msft Aug 19, 2022
4c08b9a
Revert "Revert "Hide the window from DWM until we're finished with in…
zadjii-msft Aug 19, 2022
a1fd241
Well this fixes it but I need to sort out the last bits of the launch…
zadjii-msft Aug 19, 2022
c34495d
yea this does it
zadjii-msft Aug 19, 2022
1fac403
until we can be sure, lets take this out
zadjii-msft Aug 22, 2022
9bb5fbb
Revert "until we can be sure, lets take this out"
zadjii-msft Aug 22, 2022
7fca59f
Migrate spelling-0.0.21 changes from main
DHowett Aug 22, 2022
42a5fc9
Merge remote-tracking branch 'origin/main' into dev/migrie/b/9053-att…
zadjii-msft Aug 26, 2022
b37ed82
Migrate spelling-0.0.21 changes from main
DHowett Aug 26, 2022
8c66d90
Merge remote-tracking branch 'origin/main' into dev/migrie/b/9053-att…
zadjii-msft Dec 1, 2022
6a20741
Merge branch 'dev/migrie/b/9053-attempt-2' of https://github.com/micr…
zadjii-msft Dec 1, 2022
e99af2d
Merge branch 'main' into dev/migrie/b/9053-attempt-2
zadjii-msft Jan 24, 2023
8b14a22
Merge branch 'main' into dev/migrie/b/9053-attempt-2
zadjii-msft Apr 5, 2023
6a99f25
as a point of bookmarking - this works
zadjii-msft Apr 5, 2023
431b26a
as it turns out, we don't need the invalidate. that's at least _less_…
zadjii-msft Apr 5, 2023
e67bfb3
this is cleaner
zadjii-msft Apr 5, 2023
02f5bfa
cleanup comment
zadjii-msft Apr 5, 2023
35db280
VS *shake fist*
zadjii-msft Apr 5, 2023
e7afa5b
Merge branch 'dev/migrie/b/9053-attempt-2' into dev/migrie/b/9053-par…
zadjii-msft Apr 5, 2023
46db89c
I cannot believe it was that easy
zadjii-msft Apr 6, 2023
9cbf883
I'll stame you
zadjii-msft Apr 6, 2023
b7ea20c
update this comment
zadjii-msft Apr 6, 2023
5289c23
You know, I don't think we need allowsetforeground
zadjii-msft Apr 6, 2023
e6d96cf
Merge branch 'dev/migrie/b/9053-attempt-2' into dev/migrie/b/9053-par…
zadjii-msft Apr 6, 2023
df08a66
Merge remote-tracking branch 'origin/main' into dev/migrie/b/9053-par…
zadjii-msft Apr 6, 2023
e20d0dd
Merge branch 'main' into dev/migrie/b/9053-part-3-the-actual-doing-of…
zadjii-msft Apr 11, 2023
c448749
fix the tests
zadjii-msft Apr 11, 2023
049f940
Merge remote-tracking branch 'origin/main' into dev/migrie/b/9053-par…
zadjii-msft Apr 17, 2023
03c1430
Always show from explorer. Closes #15193
zadjii-msft Apr 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ HIBYTE
hicon
HIDEWINDOW
hinst
Hirots
HISTORYBUFS
HISTORYNODUP
HISTORYSIZE
Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/Remoting/CommandlineArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
{
}

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/Remoting/Monarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/Remoting/Monarch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/Remoting/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,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);

Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/ShellExtension/OpenTerminalHere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ try
STARTUPINFOEX siEx{ 0 };
siEx.StartupInfo.cb = sizeof(STARTUPINFOEX);

// Explicitly create the terminal window visible.
siEx.StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
siEx.StartupInfo.wShowWindow = SW_SHOWNORMAL;

std::filesystem::path modulePath{ wil::GetModuleFileNameW<std::wstring>(wil::GetModuleInstanceHandle()) };
std::wstring cmdline;
if (runElevated)
Expand Down
34 changes: 17 additions & 17 deletions src/cascadia/UnitTests_Remoting/RemotingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ namespace RemotingUnitTests
m0->FindTargetWindowRequested(&RemotingTests::_findTargetWindowHelper);

std::vector<winrt::hstring> args{};
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace RemotingUnitTests
});

std::vector<winrt::hstring> args{ L"1", L"arg[1]" };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
Expand All @@ -489,15 +489,15 @@ namespace RemotingUnitTests

{
std::vector<winrt::hstring> args{ L"-1" };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id());
}
{
std::vector<winrt::hstring> args{ L"-2" };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
Expand Down Expand Up @@ -534,7 +534,7 @@ namespace RemotingUnitTests
winrt::clock().now() };
p1->ActivateWindow(activatedArgs);

Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
Expand All @@ -559,7 +559,7 @@ namespace RemotingUnitTests
p2->ActivateWindow(activatedArgs);

Log::Comment(L"Send a commandline to the current window, which should be p2");
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" }, SW_NORMAL };
auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id());
Expand All @@ -572,7 +572,7 @@ namespace RemotingUnitTests
p1->ActivateWindow(activatedArgs);

Log::Comment(L"Send a commandline to the current window, which should be p1 again");
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" }, SW_NORMAL };
auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id());
Expand All @@ -593,7 +593,7 @@ namespace RemotingUnitTests

{
std::vector<winrt::hstring> args{ L"2" };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
Expand All @@ -602,7 +602,7 @@ namespace RemotingUnitTests
}
{
std::vector<winrt::hstring> args{ L"10" };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
Expand Down Expand Up @@ -648,15 +648,15 @@ namespace RemotingUnitTests
{
Log::Comment(L"Send a commandline to p2, who is still alive. We won't create a new window.");

Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id());
}
{
Log::Comment(L"Send a commandline to p1, who is dead. We will create a new window.");
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" }, SW_NORMAL };

auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
Expand Down Expand Up @@ -1359,7 +1359,7 @@ namespace RemotingUnitTests
std::vector<winrt::hstring> p2Args{ L"two", L"this is for p2" };

{
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p1Args }, { L"" }, SW_NORMAL };
auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id()); // Casting to (bool) checks if the reference has a value
Expand All @@ -1368,7 +1368,7 @@ namespace RemotingUnitTests

{
Log::Comment(L"Send a commandline to \"two\", which should be p2");
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" }, SW_NORMAL };
auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(false, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id()); // Casting to (bool) checks if the reference has a value
Expand All @@ -1380,7 +1380,7 @@ namespace RemotingUnitTests

{
Log::Comment(L"Send a commandline to \"two\", who is now dead.");
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { p2Args }, { L"" }, SW_NORMAL };
auto result = m0->ProposeCommandline(eventArgs);
VERIFY_ARE_EQUAL(true, result.ShouldCreateWindow());
VERIFY_ARE_EQUAL(false, (bool)result.Id()); // Casting to (bool) checks if the reference has a value
Expand Down Expand Up @@ -2392,7 +2392,7 @@ namespace RemotingUnitTests
VERIFY_ARE_EQUAL(p1->GetID(), m0->_mruPeasants[1].PeasantID());

std::vector<winrt::hstring> commandlineArgs{ L"0", L"arg[1]" };
Remoting::CommandlineArgs eventArgs{ { commandlineArgs }, { L"" } };
Remoting::CommandlineArgs eventArgs{ { commandlineArgs }, { L"" }, SW_NORMAL };

Log::Comment(L"When we attempt to send a commandline to the MRU window,"
L" we should find peasant 1 (who's name is \"one\"), not 2"
Expand Down Expand Up @@ -2577,15 +2577,15 @@ namespace RemotingUnitTests
auto m0 = make_private<Remoting::implementation::Monarch>(monarch0PID);

{
Remoting::CommandlineArgs args{ { L"wt.exe" }, { L"-Embedding" } };
Remoting::CommandlineArgs args{ { L"wt.exe" }, { L"-Embedding" }, SW_NORMAL };
const auto result = m0->ProposeCommandline(args);
auto shouldCreateWindow = result.ShouldCreateWindow();
VERIFY_IS_TRUE(shouldCreateWindow);
}

auto m1 = make_self<DeadMonarch>();
{
Remoting::CommandlineArgs args{ { L"wt.exe" }, { L"-Embedding" } };
Remoting::CommandlineArgs args{ { L"wt.exe" }, { L"-Embedding" }, SW_NORMAL };

try
{
Expand Down
9 changes: 8 additions & 1 deletion src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,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
Expand Down Expand Up @@ -1247,7 +1249,12 @@ 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_SHOW;
// 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;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class AppHost

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

uint32_t _launchShowWindowCommand{ SW_NORMAL };

void _preInit();

void _HandleCommandlineArgs(const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args);
Expand Down
10 changes: 9 additions & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 same state.
STARTUPINFOW si;
GetStartupInfoW(&si);
const auto showWindow = si.wShowWindow;

Remoting::CommandlineArgs eventArgs{ { args }, { cwd }, showWindow };

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

Expand Down