03ea0f49ad
## Summary of the Pull Request This is a follow up to #9300. Now that we have names on our windows, it would be nice to see who is named what. So this adds two actions: * `identifyWindow`: This action will pop up a little toast (#8592) displaying the name and ID of the window, and is bound by default. ![identify-window-toast-000](https://user-images.githubusercontent.com/18356694/111529085-bf710580-872f-11eb-8880-b0b617596cfc.gif) * `identifyWindows`: This action will request that ALL windows pop up that toast. This is meant to feel like the "Identify" button on the Windows display settings. However, sometimes, it's wonky. ![teaching-tip-dismiss-001](https://user-images.githubusercontent.com/18356694/111529292-fe06c000-872f-11eb-8d4a-5688e4ce1175.gif) That's being tracked upstream on https://github.com/microsoft/microsoft-ui-xaml/issues/4382 Because it's so wonky, we won't bind that by default. Maybe if we get that fixed, then we'll change the default binding from `identifyWindow` to `identifyWindows` ## References ## PR Checklist * [x] Closes https://github.com/microsoft/terminal/projects/5#card-51431492 * [x] I work here * [x] Tests added/passed * [ ] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments You may note that there are some macros to make interacting with lots and lots of actions easier. There's a lot of boilerplate whenever you need to make a new action, so I thought: "Can we make that easier?" Turns out you can make it a _LOT_ easier, but that work is still behind another PR after this one. Get excited
90 lines
3.2 KiB
C++
90 lines
3.2 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
|
|
#include "Monarch.g.h"
|
|
#include "Peasant.h"
|
|
#include "../cascadia/inc/cppwinrt_utils.h"
|
|
#include "WindowActivatedArgs.h"
|
|
|
|
// We sure different GUIDs here depending on whether we're running a Release,
|
|
// Preview, or Dev build. This ensures that different installs don't
|
|
// accidentally talk to one another.
|
|
//
|
|
// * Release: {06171993-7eb1-4f3e-85f5-8bdd7386cce3}
|
|
// * Preview: {04221993-7eb1-4f3e-85f5-8bdd7386cce3}
|
|
// * Dev: {08302020-7eb1-4f3e-85f5-8bdd7386cce3}
|
|
constexpr GUID Monarch_clsid
|
|
{
|
|
#if defined(WT_BRANDING_RELEASE)
|
|
0x06171993,
|
|
#elif defined(WT_BRANDING_PREVIEW)
|
|
0x04221993,
|
|
#else
|
|
0x08302020,
|
|
#endif
|
|
0x7eb1,
|
|
0x4f3e,
|
|
{
|
|
0x85, 0xf5, 0x8b, 0xdd, 0x73, 0x86, 0xcc, 0xe3
|
|
}
|
|
};
|
|
|
|
namespace RemotingUnitTests
|
|
{
|
|
class RemotingTests;
|
|
};
|
|
|
|
namespace winrt::Microsoft::Terminal::Remoting::implementation
|
|
{
|
|
struct Monarch : public MonarchT<Monarch>
|
|
{
|
|
Monarch();
|
|
~Monarch();
|
|
|
|
uint64_t GetPID();
|
|
|
|
uint64_t AddPeasant(winrt::Microsoft::Terminal::Remoting::IPeasant peasant);
|
|
|
|
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);
|
|
uint64_t _ourPID;
|
|
|
|
uint64_t _nextPeasantID{ 1 };
|
|
uint64_t _thisPeasantID{ 0 };
|
|
|
|
winrt::com_ptr<IVirtualDesktopManager> _desktopManager{ nullptr };
|
|
|
|
std::unordered_map<uint64_t, winrt::Microsoft::Terminal::Remoting::IPeasant> _peasants;
|
|
|
|
std::vector<Remoting::WindowActivatedArgs> _mruPeasants;
|
|
|
|
winrt::Microsoft::Terminal::Remoting::IPeasant _getPeasant(uint64_t peasantID);
|
|
uint64_t _getMostRecentPeasantID(bool limitToCurrentDesktop);
|
|
uint64_t _lookupPeasantIdForName(std::wstring_view name);
|
|
|
|
void _peasantWindowActivated(const winrt::Windows::Foundation::IInspectable& sender,
|
|
const winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs& args);
|
|
void _doHandleActivatePeasant(const winrt::com_ptr<winrt::Microsoft::Terminal::Remoting::implementation::WindowActivatedArgs>& args);
|
|
void _clearOldMruEntries(const uint64_t peasantID);
|
|
|
|
void _identifyWindows(const winrt::Windows::Foundation::IInspectable& sender,
|
|
const winrt::Windows::Foundation::IInspectable& args);
|
|
|
|
void _forAllPeasantsIgnoringTheDead(std::function<void(const winrt::Microsoft::Terminal::Remoting::IPeasant&, const uint64_t)> callback,
|
|
std::function<void(const uint64_t)> errorCallback);
|
|
friend class RemotingUnitTests::RemotingTests;
|
|
};
|
|
}
|
|
|
|
namespace winrt::Microsoft::Terminal::Remoting::factory_implementation
|
|
{
|
|
BASIC_FACTORY(Monarch);
|
|
}
|