Skip to content

Commit

Permalink
This does successfully get a window on the screen, which is pretty im…
Browse files Browse the repository at this point in the history
…pressive

  It exits itself after 30s, but hey it worked
  • Loading branch information
zadjii-msft committed Feb 1, 2023
1 parent 7a3e2e0 commit f655296
Show file tree
Hide file tree
Showing 10 changed files with 597 additions and 362 deletions.
1 change: 0 additions & 1 deletion src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace Microsoft.Terminal.Remoting
ToMouse,
};


[default_interface] runtimeclass SummonWindowBehavior {
SummonWindowBehavior();
Boolean MoveToCurrentDesktop;
Expand Down
152 changes: 151 additions & 1 deletion src/cascadia/Remoting/WindowManager2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
WindowManager2::WindowManager2()
{
}
WindowManager2::~WindowManager2()
{
// IMPORTANT! Tear down the registration as soon as we exit. If we're not a
// real peasant window (the monarch passed our commandline to someone else),
// then the monarch dies, we don't want our registration becoming the active
// monarch!
CoRevokeClassObject(_registrationHostClass);
_registrationHostClass = 0;
}

void WindowManager2::_createMonarch()
{
Expand All @@ -36,7 +45,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
//
// * If we're running unpackaged: the .winmd must be a sibling of the .exe
// * If we're running packaged: the .winmd must be in the package root
_monarch = create_instance<Remoting::IMonarch>(Monarch_clsid,
_monarch = try_create_instance<Remoting::IMonarch>(Monarch_clsid,
CLSCTX_LOCAL_SERVER);
}

Expand Down Expand Up @@ -292,4 +301,145 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// TraceLoggingKeyword(TIL_KEYWORD_TRACE));
// }
}

Remoting::Peasant WindowManager2::CreateAPeasant(Remoting::WindowRequestedArgs args)
{
auto p = winrt::make_self<Remoting::implementation::Peasant>();
if (args.Id())
{
p->AssignID(args.Id().Value());
}

// 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()));

_monarch.AddPeasant(*p);

// TODO!
// _peasant.GetWindowLayoutRequested({ get_weak(), &WindowManager::_GetWindowLayoutRequestedHandlers });

TraceLoggingWrite(g_hRemotingProvider,
"WindowManager_CreateOurPeasant",
TraceLoggingUInt64(p->GetID(), "peasantID", "The ID of our new peasant"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));

// If the peasant asks us to quit we should not try to act in future elections.
p->QuitRequested([weakThis{ get_weak() }](auto&&, auto&&) {
// if (auto wm = weakThis.get())
// {
// wm->_monarchWaitInterrupt.SetEvent();
// }
});

return *p;
}

void WindowManager2::SignalClose(Remoting::Peasant peasant)
{
if (_monarch)
{
try
{
_monarch.SignalClose(peasant.GetID());
}
CATCH_LOG()
}
}

void WindowManager2::SummonWindow(const Remoting::SummonWindowSelectionArgs& args)
{
// We should only ever get called when we are the monarch, because only
// the monarch ever registers for the global hotkey. So the monarch is
// the only window that will be calling this.
_monarch.SummonWindow(args);
}

void WindowManager2::SummonAllWindows()
{
_monarch.SummonAllWindows();
}

Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Terminal::Remoting::PeasantInfo> WindowManager2::GetPeasantInfos()
{
// We should only get called when we're the monarch since the monarch
// is the only one that knows about all peasants.
return _monarch.GetPeasantInfos();
}

uint64_t WindowManager2::GetNumberOfPeasants()
{
if (_monarch)
{
try
{
return _monarch.GetNumberOfPeasants();
}
CATCH_LOG()
}
return 0;
}

// Method Description:
// - Ask the monarch to show a notification icon.
// Arguments:
// - <none>
// Return Value:
// - <none>
winrt::fire_and_forget WindowManager2::RequestShowNotificationIcon(Remoting::Peasant peasant)
{
co_await winrt::resume_background();
peasant.RequestShowNotificationIcon();
}

// Method Description:
// - Ask the monarch to hide its notification icon.
// Arguments:
// - <none>
// Return Value:
// - <none>
winrt::fire_and_forget WindowManager2::RequestHideNotificationIcon(Remoting::Peasant peasant)
{
auto strongThis{ get_strong() };
co_await winrt::resume_background();
peasant.RequestHideNotificationIcon();
}

// Method Description:
// - Ask the monarch to quit all windows.
// Arguments:
// - <none>
// Return Value:
// - <none>
winrt::fire_and_forget WindowManager2::RequestQuitAll(Remoting::Peasant peasant)
{
auto strongThis{ get_strong() };
co_await winrt::resume_background();
peasant.RequestQuitAll();
}

bool WindowManager2::DoesQuakeWindowExist()
{
return _monarch.DoesQuakeWindowExist();
}

void WindowManager2::UpdateActiveTabTitle(winrt::hstring title, Remoting::Peasant peasant)
{
winrt::get_self<implementation::Peasant>(peasant)->ActiveTabTitle(title);
}

Windows::Foundation::Collections::IVector<winrt::hstring> WindowManager2::GetAllWindowLayouts()
{
if (_monarch)
{
try
{
return _monarch.GetAllWindowLayouts();
}
CATCH_LOG()
}
return nullptr;
}
}
22 changes: 22 additions & 0 deletions src/cascadia/Remoting/WindowManager2.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
public:
WindowManager2();
~WindowManager2();
winrt::Microsoft::Terminal::Remoting::ProposeCommandlineResult ProposeCommandline2(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs& args);
Remoting::Peasant CreateAPeasant(Remoting::WindowRequestedArgs args);

void SignalClose(Remoting::Peasant peasant);
void SummonWindow(const Remoting::SummonWindowSelectionArgs& args);
void SummonAllWindows();
Windows::Foundation::Collections::IVectorView<winrt::Microsoft::Terminal::Remoting::PeasantInfo> GetPeasantInfos();
uint64_t GetNumberOfPeasants();
winrt::fire_and_forget RequestShowNotificationIcon(Remoting::Peasant peasant);
winrt::fire_and_forget RequestHideNotificationIcon(Remoting::Peasant peasant);
winrt::fire_and_forget RequestQuitAll(Remoting::Peasant peasant);
void UpdateActiveTabTitle(winrt::hstring title, Remoting::Peasant peasant);
Windows::Foundation::Collections::IVector<winrt::hstring> GetAllWindowLayouts();
bool DoesQuakeWindowExist();

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

TYPED_EVENT(WindowCreated, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(WindowClosed, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(ShowNotificationIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(HideNotificationIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(QuitAllRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::QuitAllRequestedArgs);
TYPED_EVENT(GetWindowLayoutRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::GetWindowLayoutArgs);

private:
DWORD _registrationHostClass{ 0 };
winrt::Microsoft::Terminal::Remoting::IMonarch _monarch{ nullptr };
Expand Down
25 changes: 25 additions & 0 deletions src/cascadia/Remoting/WindowManager2.idl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,34 @@ namespace Microsoft.Terminal.Remoting
WindowManager2();

ProposeCommandlineResult ProposeCommandline2(CommandlineArgs args);
Peasant CreateAPeasant(WindowRequestedArgs args);

void SignalClose(Peasant p);
void RequestShowNotificationIcon(Peasant p);
void RequestHideNotificationIcon(Peasant p);
void UpdateActiveTabTitle(String title, Peasant p);
void RequestQuitAll(Peasant p);

void SummonWindow(SummonWindowSelectionArgs args);
void SummonAllWindows();

Windows.Foundation.Collections.IVector<String> GetAllWindowLayouts();
Windows.Foundation.Collections.IVectorView<PeasantInfo> GetPeasantInfos();

UInt64 GetNumberOfPeasants();


Boolean DoesQuakeWindowExist();

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

event Windows.Foundation.TypedEventHandler<Object, Object> WindowCreated;
event Windows.Foundation.TypedEventHandler<Object, Object> WindowClosed;
event Windows.Foundation.TypedEventHandler<Object, QuitAllRequestedArgs> QuitAllRequested;
event Windows.Foundation.TypedEventHandler<Object, GetWindowLayoutArgs> GetWindowLayoutRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowNotificationIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideNotificationIconRequested;


};
}
Loading

1 comment on commit f655296

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (2)

APeasant
connectecd

Previously acknowledged words that are now absent CLA demoable everytime Hirots inthread reingest unmark :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/migrie/oop/3/ainulindale branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/4067904128/attempts/1'
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.