Skip to content

Commit

Permalink
it's working
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 1, 2023
1 parent f655296 commit 274d62d
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
result->WindowName(targetWindowName);
result->ShouldCreateWindow(true);

_RequestNewWindowHandlers(*this, *winrt::make_self<WindowRequestedArgs>(*result, args));

// If this fails, it'll be logged in the following
// TraceLoggingWrite statement, with succeeded=false
}
Expand Down Expand Up @@ -760,6 +762,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
auto result{ winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(true) };
result->Id(windowID);
result->WindowName(targetWindowName);

_RequestNewWindowHandlers(*this, *winrt::make_self<WindowRequestedArgs>(*result, args));

return *result;
}
}
Expand All @@ -774,6 +779,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// In this case, no usable ID was provided. Return { true, nullopt }
auto result = winrt::make_self<Remoting::implementation::ProposeCommandlineResult>(true);
result->WindowName(targetWindowName);

_RequestNewWindowHandlers(*this, *winrt::make_self<WindowRequestedArgs>(*result, args));

return *result;
}

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/Remoting/Monarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TYPED_EVENT(WindowClosed, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(QuitAllRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::QuitAllRequestedArgs);

TYPED_EVENT(RequestNewWindow, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs);

private:
uint64_t _ourPID;

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/Remoting/Monarch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace Microsoft.Terminal.Remoting
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, WindowRequestedArgs> RequestNewWindow;
};

runtimeclass Monarch : [default] IMonarch
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/Remoting/WindowManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ namespace Microsoft.Terminal.Remoting
event Windows.Foundation.TypedEventHandler<Object, GetWindowLayoutArgs> GetWindowLayoutRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowNotificationIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideNotificationIconRequested;

};
}
35 changes: 34 additions & 1 deletion src/cascadia/Remoting/WindowManager2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,28 @@ 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 = try_create_instance<Remoting::IMonarch>(Monarch_clsid,
CLSCTX_LOCAL_SERVER);
CLSCTX_LOCAL_SERVER);
}

// Check if we became the king, and if we are, wire up callbacks.
void WindowManager2::_createCallbacks()
{
assert(_monarch);
// Here, we're the king!
//
// This is where you should do any additional setup that might need to be
// done when we become the king. This will be called both for the first
// window, and when the current monarch dies.

_monarch.WindowCreated({ get_weak(), &WindowManager2::_WindowCreatedHandlers });
_monarch.WindowClosed({ get_weak(), &WindowManager2::_WindowClosedHandlers });
_monarch.FindTargetWindowRequested({ this, &WindowManager2::_raiseFindTargetWindowRequested });
_monarch.ShowNotificationIconRequested([this](auto&&, auto&&) { _ShowNotificationIconRequestedHandlers(*this, nullptr); });
_monarch.HideNotificationIconRequested([this](auto&&, auto&&) { _HideNotificationIconRequestedHandlers(*this, nullptr); });
_monarch.QuitAllRequested({ get_weak(), &WindowManager2::_QuitAllRequestedHandlers });

_monarch.RequestNewWindow({ get_weak(), &WindowManager2::_raiseRequestNewWindow });
// _BecameMonarchHandlers(*this, nullptr);
}

void WindowManager2::_registerAsMonarch()
Expand All @@ -58,6 +79,17 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
&_registrationHostClass));
}

void WindowManager2::_raiseFindTargetWindowRequested(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs& args)
{
_FindTargetWindowRequestedHandlers(sender, args);
}
void WindowManager2::_raiseRequestNewWindow(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args)
{
_RequestNewWindowHandlers(sender, args);
}

Remoting::ProposeCommandlineResult WindowManager2::ProposeCommandline2(const Remoting::CommandlineArgs& args)
{
bool shouldCreateWindow = false;
Expand Down Expand Up @@ -105,6 +137,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// getting any windows.
_registerAsMonarch();
_createMonarch();
_createCallbacks();
if (!_monarch)
{
// TODO! something catastrophically bad happened here.
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/Remoting/WindowManager2.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TYPED_EVENT(QuitAllRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::QuitAllRequestedArgs);
TYPED_EVENT(GetWindowLayoutRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::GetWindowLayoutArgs);

TYPED_EVENT(RequestNewWindow, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs);

private:
DWORD _registrationHostClass{ 0 };
winrt::Microsoft::Terminal::Remoting::IMonarch _monarch{ nullptr };
Expand All @@ -46,6 +48,12 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void _proposeToMonarch(const Remoting::CommandlineArgs& args,
std::optional<uint64_t>& givenID,
winrt::hstring& givenName);

void _createCallbacks();
void _raiseFindTargetWindowRequested(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs& args);
void _raiseRequestNewWindow(const winrt::Windows::Foundation::IInspectable& sender,
const winrt::Microsoft::Terminal::Remoting::WindowRequestedArgs& args);
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/Remoting/WindowManager2.idl
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ namespace Microsoft.Terminal.Remoting
event Windows.Foundation.TypedEventHandler<Object, Object> HideNotificationIconRequested;


event Windows.Foundation.TypedEventHandler<Object, WindowRequestedArgs> RequestNewWindow;

};
}
14 changes: 13 additions & 1 deletion src/cascadia/WindowsTerminal/WindowEmperor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ bool WindowEmperor::HandleCommandlineArgs()
if (result.ShouldCreateWindow())
{
CreateNewWindowThread(Remoting::WindowRequestedArgs{ result, eventArgs });

_manager.RequestNewWindow([this](auto&&, const Remoting::WindowRequestedArgs& args) {
CreateNewWindowThread(args);
});
}

return result.ShouldCreateWindow();
Expand Down Expand Up @@ -95,7 +99,15 @@ void WindowEmperor::WaitForWindows()
// one.join();
// two.join();

Sleep(30000); //30s
// Sleep(30000); //30s

MSG message;

while (GetMessage(&message, nullptr, 0, 0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}

void WindowEmperor::CreateNewWindowThread(Remoting::WindowRequestedArgs args)
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,8 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
if (emperor.HandleCommandlineArgs())
{
emperor.WaitForWindows();



}
}

1 comment on commit 274d62d

@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 git@github.com: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/4068200998/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.