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

Add support for running a commandline in another WT window #8898

Merged
60 commits merged into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
3bef7bb
Get all the projects created and hooked up to the sln
zadjii-msft Dec 16, 2020
1f52d35
Yank all the M/P files, this builds?!
zadjii-msft Dec 16, 2020
5a9cdc8
Shockingly, this works, it works elevated, and it works unpackaged
zadjii-msft Dec 16, 2020
36539cf
This won't work, but I'm committing this becaus I finally got it to c…
zadjii-msft Dec 16, 2020
27ace16
whoop, we pass the commandline from the peasant, to the monarch, and …
zadjii-msft Dec 16, 2020
9a41647
HOLY SHIT I GOT THE COMANDLINE TO EXECUTE IN THE CURRENT WINDOW!!!!!!…
zadjii-msft Dec 17, 2020
5cabcfb
add a note to future me
zadjii-msft Dec 17, 2020
03bfc6e
This works as a unittest, but not a local test. That's batty
zadjii-msft Dec 17, 2020
590b9ff
this macro makes me feel dirty
zadjii-msft Dec 17, 2020
0579b24
LocalTests_Remoting -> UnitTests_Remoting
zadjii-msft Dec 17, 2020
a3faed6
finish renaming this test
zadjii-msft Dec 17, 2020
9c6eac4
Clean up a lot for review
zadjii-msft Dec 17, 2020
0103331
cleanup Peasant for review
zadjii-msft Dec 17, 2020
b4fe1bf
Final cleanup for review
zadjii-msft Dec 17, 2020
d08e65c
_final_ final cleanup for review
zadjii-msft Dec 17, 2020
e101efd
pr nits
zadjii-msft Dec 18, 2020
e1402d8
This seems to work to create a thread listening for the monarch, and …
zadjii-msft Dec 18, 2020
f978a9c
it's hard to believe he's gone / were it so easy
zadjii-msft Dec 18, 2020
5939636
Oh yea actually remove the thing
zadjii-msft Dec 18, 2020
c088895
last commit before the holidays
zadjii-msft Dec 18, 2020
fa2df47
Merge remote-tracking branch 'origin/main' into dev/migrie/f/remoting…
zadjii-msft Jan 5, 2021
0f5c24f
Enable audit mode
zadjii-msft Jan 5, 2021
921d915
nits
zadjii-msft Jan 5, 2021
00184e7
Merge branch 'dev/migrie/f/remoting.dll' into dev/migrie/f/the-first-…
zadjii-msft Jan 5, 2021
658db6b
Ask the TerminalApp to parse the commandline, and tell us what the wi…
zadjii-msft Jan 6, 2021
977db46
Holy bajesus, this works like a charm
zadjii-msft Jan 6, 2021
bcbef34
Add a note about commiting suicide
zadjii-msft Jan 6, 2021
813dbc6
notes, comments, cleanup
zadjii-msft Jan 6, 2021
0f0df5e
activate windows
zadjii-msft Jan 6, 2021
9fc2f0e
add some tracelogging
zadjii-msft Jan 6, 2021
6537686
The peasant will now correctly inform the monarch when it re-connects
zadjii-msft Jan 7, 2021
a75da0a
mostly just notes
zadjii-msft Jan 7, 2021
c02f25a
peasants now switch to the cwd that was requested
zadjii-msft Jan 7, 2021
3e39ab9
more comments
zadjii-msft Jan 7, 2021
52b2cb6
Allow the user to provide ids on the commandline
zadjii-msft Jan 7, 2021
bc492f1
Code cleanup
zadjii-msft Jan 7, 2021
88ffc6f
Merge remote-tracking branch 'origin/main' into dev/migrie/f/remoting…
zadjii-msft Jan 7, 2021
be74b2e
putting var in headers is bad, mkay?
zadjii-msft Jan 7, 2021
2a7bc94
branding
zadjii-msft Jan 7, 2021
81c09d9
Merge branch 'dev/migrie/f/remoting.dll' into dev/migrie/f/the-first-…
zadjii-msft Jan 8, 2021
c34e4ce
Merge remote-tracking branch 'origin/main' into dev/migrie/f/the-firs…
zadjii-msft Jan 8, 2021
5b8ace2
A bunch of tests for Monarch::ProposeCommandline
zadjii-msft Jan 8, 2021
689c385
sure yea that's a doc comment
zadjii-msft Jan 8, 2021
59deca1
Merge branch 'main' into dev/migrie/f/the-first-galactic-empire
zadjii-msft Jan 26, 2021
f02969b
More tests, more redundancy
zadjii-msft Jan 26, 2021
b2db317
man I can't spel
zadjii-msft Jan 26, 2021
d2a3438
Add try/catch's throughout Monarch.cpp
zadjii-msft Jan 27, 2021
a65f341
trycatch the window manager. A lot more going on there.
zadjii-msft Jan 27, 2021
faf4544
add some abstracts
zadjii-msft Jan 29, 2021
19765b1
Apply suggestions from code review
zadjii-msft Jan 29, 2021
4e007ae
a ton of PR feedback
zadjii-msft Jan 29, 2021
c493607
bunch of PR feedback
zadjii-msft Feb 2, 2021
8de368a
Merge remote-tracking branch 'origin/main' into dev/migrie/f/the-firs…
zadjii-msft Feb 2, 2021
e6bd315
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
a62d53f
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
147b187
!!! THIS NEEDS TO BE MOVED TO THE PARENT BRANCH !!!
zadjii-msft Jan 28, 2021
a102f44
bad merge
zadjii-msft Feb 2, 2021
b627fd9
Merge remote-tracking branch 'origin/main' into dev/migrie/f/the-firs…
zadjii-msft Feb 2, 2021
2367db1
What? No yea I always run the tests
zadjii-msft Feb 2, 2021
c29fbe7
Merge remote-tracking branch 'origin/main' into dev/migrie/f/the-firs…
zadjii-msft Feb 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect/web.txt
Expand Up @@ -13,3 +13,4 @@ fixterms
uk
winui
appshellintegration
cppreference
11 changes: 7 additions & 4 deletions OpenConsole.sln
Expand Up @@ -362,6 +362,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests_Remoting", "src\c
{27B5AAEB-A548-44CF-9777-F8BAA32AF7AE} = {27B5AAEB-A548-44CF-9777-F8BAA32AF7AE}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wpf", "wpf", "{4DAF0299-495E-4CD1-A982-9BAC16A45932}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AuditMode|Any CPU = AuditMode|Any CPU
Expand Down Expand Up @@ -2475,7 +2477,7 @@ Global
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|DotNet_x64Test.ActiveCfg = AuditMode|Win32
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|DotNet_x86Test.ActiveCfg = AuditMode|Win32
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|x64.ActiveCfg = Release|x64
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|x64.Build.0 = AuditMode|x64
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|x64.Build.0 = Release|x64
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|x86.ActiveCfg = AuditMode|Win32
{43CE4CE5-0010-4B99-9569-672670D26E26}.AuditMode|x86.Build.0 = AuditMode|Win32
{43CE4CE5-0010-4B99-9569-672670D26E26}.Debug|Any CPU.ActiveCfg = Debug|Win32
Expand Down Expand Up @@ -2613,8 +2615,8 @@ Global
{05500DEF-2294-41E3-AF9A-24E580B82836} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
{1E4A062E-293B-4817-B20D-BF16B979E350} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
{34DE34D3-1CD6-4EE3-8BD9-A26B5B27EC73} = {89CDCC5C-9F53-4054-97A4-639D99F169CD}
{84848BFA-931D-42CE-9ADF-01EE54DE7890} = {59840756-302F-44DF-AA47-441A9D673202}
{376FE273-6B84-4EB5-8B30-8DE9D21B022C} = {59840756-302F-44DF-AA47-441A9D673202}
{84848BFA-931D-42CE-9ADF-01EE54DE7890} = {4DAF0299-495E-4CD1-A982-9BAC16A45932}
{376FE273-6B84-4EB5-8B30-8DE9D21B022C} = {4DAF0299-495E-4CD1-A982-9BAC16A45932}
{CA5CAD1A-9333-4D05-B12A-1905CBF112F9} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
{CA5CAD1A-9A12-429C-B551-8562EC954746} = {59840756-302F-44DF-AA47-441A9D673202}
{CA5CAD1A-B11C-4DDB-A4FE-C3AFAE9B5506} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
Expand All @@ -2634,7 +2636,7 @@ Global
{024052DE-83FB-4653-AEA4-90790D29D5BD} = {E8F24881-5E37-4362-B191-A3BA0ED7F4EB}
{067F0A06-FCB7-472C-96E9-B03B54E8E18D} = {59840756-302F-44DF-AA47-441A9D673202}
{6BAE5851-50D5-4934-8D5E-30361A8A40F3} = {81C352DB-1818-45B7-A284-18E259F1CC87}
{1588FD7C-241E-4E7D-9113-43735F3E6BAD} = {59840756-302F-44DF-AA47-441A9D673202}
{1588FD7C-241E-4E7D-9113-43735F3E6BAD} = {4DAF0299-495E-4CD1-A982-9BAC16A45932}
{506FD703-BAA7-4F6E-9361-64F550EC8FCA} = {59840756-302F-44DF-AA47-441A9D673202}
{CA5CAD1A-0B5E-45C3-96A8-BB496BFE4E32} = {59840756-302F-44DF-AA47-441A9D673202}
{CA5CAD1A-D7EC-4107-B7C6-79CB77AE2907} = {59840756-302F-44DF-AA47-441A9D673202}
Expand All @@ -2645,6 +2647,7 @@ Global
{43CE4CE5-0010-4B99-9569-672670D26E26} = {59840756-302F-44DF-AA47-441A9D673202}
{27B5AAEB-A548-44CF-9777-F8BAA32AF7AE} = {59840756-302F-44DF-AA47-441A9D673202}
{68A10CD3-AA64-465B-AF5F-ED4E9700543C} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
{4DAF0299-495E-4CD1-A982-9BAC16A45932} = {59840756-302F-44DF-AA47-441A9D673202}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3140B1B7-C8EE-43D1-A772-D82A7061A271}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/CascadiaPackage/CascadiaPackage.wapproj
Expand Up @@ -5,6 +5,7 @@
<PropertyGroup Label="Configuration">
<!-- This is necessary so the build system doesn't think we're a .NET project... -->
<TargetRuntime>Native</TargetRuntime>
<NuGetTargetMoniker>win</NuGetTargetMoniker>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
<!--
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/Remoting/FindTargetWindowArgs.cpp
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "FindTargetWindowArgs.h"
#include "FindTargetWindowArgs.g.cpp"
17 changes: 17 additions & 0 deletions src/cascadia/Remoting/FindTargetWindowArgs.h
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
// Licensed under the MIT license.

#pragma once

#include "FindTargetWindowArgs.g.h"
#include "../cascadia/inc/cppwinrt_utils.h"

namespace winrt::Microsoft::Terminal::Remoting::implementation
{
struct FindTargetWindowArgs : public FindTargetWindowArgsT<FindTargetWindowArgs>
{
public:
GETSET_PROPERTY(winrt::Microsoft::Terminal::Remoting::CommandlineArgs, Args, nullptr);
GETSET_PROPERTY(int, ResultTargetWindow, -1);
};
}
19 changes: 19 additions & 0 deletions src/cascadia/Remoting/Microsoft.Terminal.RemotingLib.vcxproj
Expand Up @@ -19,6 +19,15 @@
<ClInclude Include="Monarch.h">
<DependentUpon>Monarch.idl</DependentUpon>
</ClInclude>
<ClInclude Include="FindTargetWindowArgs.h">
<DependentUpon>Monarch.idl</DependentUpon>
</ClInclude>
<ClInclude Include="ProposeCommandlineResult.h">
<DependentUpon>Monarch.idl</DependentUpon>
</ClInclude>
<ClInclude Include="WindowActivatedArgs.h">
<DependentUpon>Peasant.idl</DependentUpon>
</ClInclude>
<ClInclude Include="pch.h" />
<ClInclude Include="MonarchFactory.h" />
<ClInclude Include="Peasant.h">
Expand All @@ -36,6 +45,15 @@
<ClCompile Include="Monarch.cpp">
<DependentUpon>Monarch.idl</DependentUpon>
</ClCompile>
<ClCompile Include="FindTargetWindowArgs.cpp">
<DependentUpon>Monarch.idl</DependentUpon>
</ClCompile>
<ClCompile Include="ProposeCommandlineResult.cpp">
<DependentUpon>Monarch.idl</DependentUpon>
</ClCompile>
<ClCompile Include="WindowActivatedArgs.cpp">
<DependentUpon>Peasant.idl</DependentUpon>
</ClCompile>
<ClCompile Include="pch.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
Expand All @@ -49,6 +67,7 @@
<DependentUpon>Peasant.idl</DependentUpon>
</ClCompile>
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
<ClCompile Include="init.cpp" />
</ItemGroup>
<!-- ========================= idl Files ======================== -->
<ItemGroup>
Expand Down
169 changes: 143 additions & 26 deletions src/cascadia/Remoting/Monarch.cpp
Expand Up @@ -4,6 +4,8 @@
#include "pch.h"
#include "Monarch.h"
#include "CommandlineArgs.h"
#include "FindTargetWindowArgs.h"
#include "ProposeCommandlineResult.h"

#include "Monarch.g.cpp"
#include "../../types/inc/utils.hpp"
Expand Down Expand Up @@ -66,9 +68,11 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// Add an event listener to the peasant's WindowActivated event.
peasant.WindowActivated({ this, &Monarch::_peasantWindowActivated });

// TODO:projects/5 Wait on the peasant's PID, and remove them from the
// map if they die. This won't work great in tests though, with fake
// PIDs.
TraceLoggingWrite(g_hRemotingProvider,
"Monarch_AddPeasant",
TraceLoggingUInt64(providedID, "providedID", "the provided ID for the peasant"),
TraceLoggingUInt64(newPeasantsId, "peasantID", "the ID of the new peasant"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

return newPeasantsId;
}
Expand All @@ -79,19 +83,13 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// window".
// Arguments:
// - sender: the Peasant that raised this event. This might be out-of-proc!
// - args: a bundle of the peasant ID, timestamp, and desktop ID, for the activated peasant
// Return Value:
// - <none>
void Monarch::_peasantWindowActivated(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& /*args*/)
void Monarch::_peasantWindowActivated(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const Remoting::WindowActivatedArgs& args)
{
// TODO:projects/5 Pass the desktop and timestamp of when the window was
// activated in `args`.

if (auto peasant{ sender.try_as<Remoting::Peasant>() })
{
auto theirID = peasant.GetID();
_setMostRecentPeasant(theirID);
}
HandleActivatePeasant(args);
}

// Method Description:
Expand All @@ -102,17 +100,71 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// - the peasant if it exists in our map, otherwise null
Remoting::IPeasant Monarch::_getPeasant(uint64_t peasantID)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
auto peasantSearch = _peasants.find(peasantID);
return peasantSearch == _peasants.end() ? nullptr : peasantSearch->second;
try
{
auto peasantSearch = _peasants.find(peasantID);
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
auto maybeThePeasant = peasantSearch == _peasants.end() ? nullptr : peasantSearch->second;
if (maybeThePeasant)
{
maybeThePeasant.GetPID();
}
return maybeThePeasant;
}
catch (...)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
LOG_CAUGHT_EXCEPTION();
// Remove the peasant from the list of peasants
_peasants.erase(peasantID);
return nullptr;
}
}

void Monarch::_setMostRecentPeasant(const uint64_t peasantID)
void Monarch::HandleActivatePeasant(const Remoting::WindowActivatedArgs& args)
{
// TODO:projects/5 Use a heap/priority queue per-desktop to track which
// peasant was the most recent per-desktop. When we want to get the most
// recent of all desktops (WindowingBehavior::UseExisting), then use the
// most recent of all desktops.
_mostRecentPeasant = peasantID;
const auto oldLastActiveTime = _lastActivatedTime.time_since_epoch().count();
const auto newLastActiveTime = args.ActivatedTime().time_since_epoch().count();

// For now, we'll just pay attention to whoever the most recent peasant
// was. We're not too worried about the mru peasant dying. Worst case -
// when the user executes a `wt -w 0`, we won't be able to find that
// peasant, and it'll open in a new window instead of the current one.
if (args.ActivatedTime() > _lastActivatedTime)
{
_mostRecentPeasant = args.PeasantID();
_lastActivatedTime = args.ActivatedTime();
}

TraceLoggingWrite(g_hRemotingProvider,
"Monarch_SetMostRecentPeasant",
TraceLoggingUInt64(args.PeasantID(), "peasantID", "the ID of the activated peasant"),
TraceLoggingInt64(oldLastActiveTime, "oldLastActiveTime", "The previous lastActiveTime"),
TraceLoggingInt64(newLastActiveTime, "newLastActiveTime", "The provided args.ActivatedTime()"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}

uint64_t Monarch::_getMostRecentPeasantID()
{
if (_mostRecentPeasant == 0)
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
{
// We haven't yet been told the MRU peasant. Just use the first one.
// This is just gonna be a random one, but really shouldn't happen
// in practice. The WindowManager should set the MRU peasant
// immediately as soon as it creates the monarch/peasant for the
// first window.
if (_peasants.size() > 0)
{
return _peasants.begin()->second.GetID();
}
return 0;
}
else
{
return _mostRecentPeasant;
}
}

// Method Description:
Expand All @@ -122,16 +174,81 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// Arguments:
// - <none>
// Return Value:
// - <none>
bool Monarch::ProposeCommandline(const Remoting::CommandlineArgs& /*args*/)
// - true if the caller should create a new window for this commandline.
// False otherwise - the monarch should have dispatched this commandline
// to another window in this case.
Remoting::ProposeCommandlineResult Monarch::ProposeCommandline(const Remoting::CommandlineArgs& args)
{
// TODO:projects/5
// The branch dev/migrie/f/remote-commandlines has a more complete
// version of this function, with a naive implementation. For now, we
// always want to create a new window, so we'll just return true. This
// will tell the caller that we didn't handle the commandline, and they
// should open a new window to deal with it themselves.
return true;
// Raise an event, to ask how to handle this commandline. We can't ask
// the app ourselves - we exist isolated from that knowledge (and
// dependency hell). The WindowManager will raise this up to the app
// host, which will then ask the AppLogic, who will then parse the
// commandline and determine the provided ID of the window.
auto findWindowArgs = winrt::make_self<Remoting::implementation::FindTargetWindowArgs>();
findWindowArgs->Args(args);
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved

_FindTargetWindowRequestedHandlers(*this, *findWindowArgs);

// After the event was handled, ResultTargetWindow() will be filled with
// the parsed result.
const auto targetWindow = findWindowArgs->ResultTargetWindow();

// If there's a valid ID returned, then let's try and find the peasant that goes with it.
if (targetWindow >= 0)
{
uint64_t windowID = ::base::saturated_cast<uint64_t>(targetWindow);

if (windowID == 0)
{
windowID = _getMostRecentPeasantID();
}

if (auto targetPeasant{ _getPeasant(windowID) })
{
// This will raise the peasant's ExecuteCommandlineRequested
// event, which will then ask the AppHost to handle the
// commandline, which will then pass it to AppLogic for
// handling.
targetPeasant.ExecuteCommandline(args);

TraceLoggingWrite(g_hRemotingProvider,
"Monarch_ProposeCommandline_Existing",
TraceLoggingUInt64(windowID, "peasantID", "the ID of the matching peasant"),
TraceLoggingBoolean(true, "foundMatch", "true if we found a peasant with that ID"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>();
result->ShouldCreateWindow(false);
return *result;
}
else if (windowID > 0)
{
// In this case, an ID was provided, but there's no
// peasant with that ID. Instead, we should tell the caller that
// they should make a new window, but _with that ID_.

TraceLoggingWrite(g_hRemotingProvider,
"Monarch_ProposeCommandline_Existing",
TraceLoggingUInt64(windowID, "peasantID", "the ID of the matching peasant"),
TraceLoggingBoolean(false, "foundMatch", "true if we found a peasant with that ID"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>();
result->ShouldCreateWindow(true);
result->Id(windowID);
return *result;
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}
}

TraceLoggingWrite(g_hRemotingProvider,
"Monarch_ProposeCommandline_NewWindow",
TraceLoggingInt64(targetWindow, "targetWindow", "The provided ID"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

// In this case, no usable ID was provided. Return { true, nullopt }
auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>();
result->ShouldCreateWindow(true);
return *result;
carlos-zamora marked this conversation as resolved.
Show resolved Hide resolved
}

}
11 changes: 8 additions & 3 deletions src/cascadia/Remoting/Monarch.h
Expand Up @@ -52,7 +52,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation

uint64_t AddPeasant(winrt::Microsoft::Terminal::Remoting::IPeasant peasant);

bool ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs& args);
winrt::Microsoft::Terminal::Remoting::ProposeCommandlineResult ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs& args);
void HandleActivatePeasant(const winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs& args);

TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);

private:
Monarch(const uint64_t testPID);
Expand All @@ -61,14 +64,16 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
uint64_t _nextPeasantID{ 1 };
uint64_t _thisPeasantID{ 0 };
uint64_t _mostRecentPeasant{ 0 };
winrt::Windows::Foundation::DateTime _lastActivatedTime{};

WindowingBehavior _windowingBehavior{ WindowingBehavior::UseNew };
std::unordered_map<uint64_t, winrt::Microsoft::Terminal::Remoting::IPeasant> _peasants;

winrt::Microsoft::Terminal::Remoting::IPeasant _getPeasant(uint64_t peasantID);
void _setMostRecentPeasant(const uint64_t peasantID);
uint64_t _getMostRecentPeasantID();

void _peasantWindowActivated(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Windows::Foundation::IInspectable& args);
const winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs& args);

friend class RemotingUnitTests::RemotingTests;
};
Expand Down
17 changes: 16 additions & 1 deletion src/cascadia/Remoting/Monarch.idl
Expand Up @@ -5,11 +5,26 @@ import "Peasant.idl";

namespace Microsoft.Terminal.Remoting
{

[default_interface] runtimeclass FindTargetWindowArgs {
CommandlineArgs Args;
Int32 ResultTargetWindow;
}

[default_interface] runtimeclass ProposeCommandlineResult {
Windows.Foundation.IReference<UInt64> Id { get; };
// TODO:projects/5 - also return the name here, if the name was set on the commandline
Boolean ShouldCreateWindow { get; }; // If you name this `CreateWindow`, the compiler will explode
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
}

[default_interface] runtimeclass Monarch {
Monarch();

UInt64 GetPID();
UInt64 AddPeasant(IPeasant peasant);
Boolean ProposeCommandline(CommandlineArgs args);
ProposeCommandlineResult ProposeCommandline(CommandlineArgs args);
void HandleActivatePeasant(WindowActivatedArgs args);

event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
};
}