Holy shit all the plumbing worked on the first try

This commit is contained in:
Mike Griese 2021-08-25 15:35:30 -05:00
parent 81a5a736fe
commit d8bd527996
22 changed files with 164 additions and 6 deletions

View file

@ -856,4 +856,24 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
};
_forAllPeasantsIgnoringTheDead(callback, onError);
}
void Monarch::RequestMovePane(winrt::hstring window,
winrt::guid contentGuid,
uint32_t tabIndex)
{
auto windowId = _lookupPeasantIdForName(window);
if (windowId == 0)
{ /* TODO! try the name as an integer ID */
return;
}
if (auto targetPeasant{ _getPeasant(windowId) })
{
auto request = winrt::make_self<implementation::AttachRequest>(contentGuid, tabIndex);
targetPeasant.AttachPaneToWindow(*request);
}
else
{ /*TODO! log */
}
}
}

View file

@ -55,6 +55,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void SummonAllWindows();
Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> GetPeasantNames();
void RequestMovePane(winrt::hstring window, winrt::guid contentGuid, uint32_t tabIndex);
TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);
TYPED_EVENT(ShowTrayIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(HideTrayIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);

View file

@ -44,6 +44,8 @@ namespace Microsoft.Terminal.Remoting
void SummonAllWindows();
Windows.Foundation.Collections.IMapView<UInt64, String> GetPeasantNames { get; };
void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex);
event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowTrayIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideTrayIconRequested;

View file

@ -7,6 +7,7 @@
#include "SummonWindowBehavior.h"
#include "Peasant.g.cpp"
#include "../../types/inc/utils.hpp"
#include "AttachRequest.g.cpp"
using namespace winrt;
using namespace winrt::Microsoft::Terminal;
@ -257,4 +258,21 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
void Peasant::AttachPaneToWindow(Remoting::AttachRequest request)
{
try
{
_AttachRequestedHandlers(*this, request);
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
}
TraceLoggingWrite(g_hRemotingProvider,
"Peasant_AttachPaneToWindow",
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
}

View file

@ -6,6 +6,7 @@
#include "Peasant.g.h"
#include "../cascadia/inc/cppwinrt_utils.h"
#include "RenameRequestArgs.h"
#include "AttachRequest.g.h"
namespace RemotingUnitTests
{
@ -13,6 +14,17 @@ namespace RemotingUnitTests
};
namespace winrt::Microsoft::Terminal::Remoting::implementation
{
struct AttachRequest : public AttachRequestT<AttachRequest>
{
WINRT_PROPERTY(winrt::guid, ContentGuid);
WINRT_PROPERTY(uint32_t, TabIndex);
public:
AttachRequest(winrt::guid contentGuid,
uint32_t tabIndex) :
_ContentGuid{ contentGuid }, _TabIndex{ tabIndex } {};
};
struct Peasant : public PeasantT<Peasant>
{
Peasant();
@ -31,6 +43,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void RequestShowTrayIcon();
void RequestHideTrayIcon();
void AttachPaneToWindow(Remoting::AttachRequest request);
winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs GetLastActivatedArgs();
winrt::Microsoft::Terminal::Remoting::CommandlineArgs InitialArgs();
@ -44,6 +58,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TYPED_EVENT(SummonRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::SummonWindowBehavior);
TYPED_EVENT(ShowTrayIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(HideTrayIconRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(AttachRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::AttachRequest);
private:
Peasant(const uint64_t testPID);

View file

@ -47,6 +47,11 @@ namespace Microsoft.Terminal.Remoting
MonitorBehavior ToMonitor;
}
[default_interface] runtimeclass AttachRequest {
Guid ContentGuid { get; };
UInt32 TabIndex { get; };
}
interface IPeasant
{
CommandlineArgs InitialArgs { get; };
@ -66,6 +71,7 @@ namespace Microsoft.Terminal.Remoting
void Summon(SummonWindowBehavior behavior);
void RequestShowTrayIcon();
void RequestHideTrayIcon();
void AttachPaneToWindow(AttachRequest request);
event Windows.Foundation.TypedEventHandler<Object, WindowActivatedArgs> WindowActivated;
event Windows.Foundation.TypedEventHandler<Object, CommandlineArgs> ExecuteCommandlineRequested;
@ -75,6 +81,7 @@ namespace Microsoft.Terminal.Remoting
event Windows.Foundation.TypedEventHandler<Object, SummonWindowBehavior> SummonRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowTrayIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideTrayIconRequested;
event Windows.Foundation.TypedEventHandler<Object, AttachRequest> AttachRequested;
};
[default_interface] runtimeclass Peasant : IPeasant

View file

@ -564,4 +564,12 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
return false;
}
winrt::fire_and_forget WindowManager::RequestMovePane(winrt::hstring window,
winrt::guid contentGuid,
uint32_t tabIndex)
{
co_await winrt::resume_background();
_monarch.RequestMovePane(window, contentGuid, tabIndex);
}
}

View file

@ -46,6 +46,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
winrt::fire_and_forget RequestShowTrayIcon();
winrt::fire_and_forget RequestHideTrayIcon();
bool DoesQuakeWindowExist();
winrt::fire_and_forget RequestMovePane(winrt::hstring window, winrt::guid contentGuid, uint32_t tabIndex);
TYPED_EVENT(FindTargetWindowRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::FindTargetWindowArgs);
TYPED_EVENT(BecameMonarch, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);

View file

@ -17,6 +17,9 @@ namespace Microsoft.Terminal.Remoting
void RequestHideTrayIcon();
Boolean DoesQuakeWindowExist();
Windows.Foundation.Collections.IMapView<UInt64, String> GetPeasantNames();
void RequestMovePane(String window, Guid contentGuid, UInt32 tabIndex);
event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> BecameMonarch;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowTrayIconRequested;

View file

@ -152,7 +152,7 @@ namespace winrt::TerminalApp::implementation
}
else if (const auto& realArgs = args.ActionArgs().try_as<MovePaneArgs>())
{
auto moved = _MovePane(realArgs.TabIndex());
auto moved = _MovePane(realArgs);
args.Handled(moved);
}
}

View file

@ -1477,4 +1477,12 @@ namespace winrt::TerminalApp::implementation
return false;
}
}
void AppLogic::AttachPane(winrt::guid contentGuid, uint32_t tabIndex)
{
if (_root)
{
_root->AttachPane(contentGuid, tabIndex);
}
}
}

View file

@ -94,6 +94,7 @@ namespace winrt::TerminalApp::implementation
bool GetMinimizeToTray();
bool GetAlwaysShowTrayIcon();
void AttachPane(winrt::guid contentGuid, uint32_t tabIndex);
winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> ShowDialog(winrt::Windows::UI::Xaml::Controls::ContentDialog dialog);
@ -171,6 +172,7 @@ namespace winrt::TerminalApp::implementation
FORWARDED_TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs, _root, RenameWindowRequested);
FORWARDED_TYPED_EVENT(IsQuakeWindowChanged, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IsQuakeWindowChanged);
FORWARDED_TYPED_EVENT(SummonWindowRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, SummonWindowRequested);
FORWARDED_TYPED_EVENT(RequestMovePane, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMovePaneArgs, _root, RequestMovePane);
#ifdef UNIT_TESTING
friend class TerminalAppLocalTests::CommandlineTest;

View file

@ -74,6 +74,7 @@ namespace TerminalApp
Boolean GetAlwaysShowTrayIcon();
FindTargetWindowResult FindTargetWindow(String[] args);
void AttachPane(Guid contentGuid, UInt32 tabIndex);
Windows.Foundation.Collections.IMapView<Microsoft.Terminal.Control.KeyChord, Microsoft.Terminal.Settings.Model.Command> GlobalHotkeys();
@ -95,5 +96,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> SettingsChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> SummonWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, RequestMovePaneArgs> RequestMovePane;
}
}

View file

@ -17,6 +17,7 @@
#include "DebugTapConnection.h"
#include "SettingsTab.h"
#include "RenameWindowRequestedArgs.g.cpp"
#include "RequestMovePaneArgs.g.cpp"
#include "../inc/WindowingBehavior.h"
#include <til/latch.h>
@ -1359,11 +1360,14 @@ namespace winrt::TerminalApp::implementation
// - No move will occur if the tabIdx is the same as the current tab, or if
// the specified tab is not a host of terminals (such as the settings tab).
// Arguments:
// - tabIdx: The target tab index.
// - TODO!
// Return Value:
// - true if the pane was successfully moved to the new tab.
bool TerminalPage::_MovePane(const uint32_t tabIdx)
bool TerminalPage::_MovePane(MovePaneArgs args)
{
const auto tabIdx{ args.TabIndex() };
const auto windowId{ args.Window() };
auto focusedTab{ _GetFocusedTabImpl() };
if (!focusedTab)
@ -1371,6 +1375,17 @@ namespace winrt::TerminalApp::implementation
return false;
}
if (!windowId.empty())
{
if (const auto& control{ _GetActiveControl() })
{
const auto currentContentGuid{ control.ContentGuid() };
auto request = winrt::make_self<RequestMovePaneArgs>(currentContentGuid, args);
_RequestMovePaneHandlers(*this, *request);
return true;
}
}
// If we are trying to move from the current tab to the current tab do nothing.
if (_GetFocusedTabIndex() == tabIdx)
{
@ -1401,6 +1416,16 @@ namespace winrt::TerminalApp::implementation
return true;
}
winrt::fire_and_forget TerminalPage::AttachPane(winrt::guid contentGuid, uint32_t tabIndex)
{
contentGuid;
tabIndex;
co_await winrt::resume_background();
const auto contentProc = _AttachToContentProcess(contentGuid);
contentProc;
co_await winrt::resume_foreground(Dispatcher());
}
// Method Description:
// - Split the focused pane either horizontally or vertically, and place the
// given TermControl into the newly created pane.

View file

@ -8,6 +8,7 @@
#include "AppKeyBindings.h"
#include "AppCommandlineArgs.h"
#include "RenameWindowRequestedArgs.g.h"
#include "RequestMovePaneArgs.g.h"
#include "Toast.h"
#define DECLARE_ACTION_HANDLER(action) void _Handle##action(const IInspectable& sender, const Microsoft::Terminal::Settings::Model::ActionEventArgs& args);
@ -45,6 +46,16 @@ namespace winrt::TerminalApp::implementation
_ProposedName{ name } {};
};
struct RequestMovePaneArgs : RequestMovePaneArgsT<RequestMovePaneArgs>
{
WINRT_PROPERTY(winrt::guid, ContentGuid);
WINRT_PROPERTY(Microsoft::Terminal::Settings::Model::MovePaneArgs, Args, nullptr);
public:
RequestMovePaneArgs(const winrt::guid& g, Microsoft::Terminal::Settings::Model::MovePaneArgs args) :
_ContentGuid{ g }, _Args{ args } {};
};
struct TerminalPage : TerminalPageT<TerminalPage>
{
public:
@ -107,6 +118,7 @@ namespace winrt::TerminalApp::implementation
winrt::hstring WindowIdForDisplay() const noexcept;
winrt::hstring WindowNameForDisplay() const noexcept;
bool IsQuakeWindow() const noexcept;
winrt::fire_and_forget AttachPane(winrt::guid contentGuid, uint32_t tabIndex);
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
@ -124,6 +136,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs);
TYPED_EVENT(IsQuakeWindowChanged, IInspectable, IInspectable);
TYPED_EVENT(SummonWindowRequested, IInspectable, IInspectable);
TYPED_EVENT(RequestMovePane, Windows::Foundation::IInspectable, winrt::TerminalApp::RequestMovePaneArgs);
private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
@ -246,7 +259,7 @@ namespace winrt::TerminalApp::implementation
bool _SelectTab(uint32_t tabIndex);
bool _MoveFocus(const Microsoft::Terminal::Settings::Model::FocusDirection& direction);
bool _SwapPane(const Microsoft::Terminal::Settings::Model::FocusDirection& direction);
bool _MovePane(const uint32_t tabIdx);
bool _MovePane(const Microsoft::Terminal::Settings::Model::MovePaneArgs args);
winrt::Microsoft::Terminal::Control::TermControl _GetActiveControl();
std::optional<uint32_t> _GetFocusedTabIndex() const noexcept;

View file

@ -10,6 +10,11 @@ namespace TerminalApp
{
String ProposedName { get; };
};
[default_interface] runtimeclass RequestMovePaneArgs
{
Microsoft.Terminal.Settings.Model.MovePaneArgs Args { get; };
Guid ContentGuid { get; };
};
interface IDialogPresenter
{
@ -44,6 +49,7 @@ namespace TerminalApp
String KeyboardServiceDisabledText { get; };
TaskbarState TaskbarState{ get; };
void AttachPane(Guid contentGuid, UInt32 tabIndex);
event Windows.Foundation.TypedEventHandler<Object, String> TitleChanged;
event Windows.Foundation.TypedEventHandler<Object, LastTabClosedEventArgs> LastTabClosed;
@ -57,5 +63,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, RenameWindowRequestedArgs> RenameWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> SummonWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, RequestMovePaneArgs> RequestMovePane;
}
}

View file

@ -28,6 +28,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
TermControl(winrt::guid contentGuid, IControlSettings settings, TerminalConnection::ITerminalConnection connection);
TermControl(IControlSettings settings, TerminalConnection::ITerminalConnection connection);
winrt::guid ContentGuid() const;
winrt::fire_and_forget UpdateSettings();
winrt::fire_and_forget UpdateAppearance(const IControlAppearance newAppearance);

View file

@ -24,6 +24,8 @@ namespace Microsoft.Terminal.Control
static Windows.Foundation.Size GetProposedDimensions(IControlSettings settings, UInt32 dpi);
Guid ContentGuid{ get; };
void UpdateSettings();
Microsoft.Terminal.Control.IControlSettings Settings;

View file

@ -15,6 +15,11 @@ using namespace winrt::Windows::System;
namespace winrt::Microsoft::Terminal::Control::implementation
{
winrt::guid TermControl::ContentGuid() const
{
return _contentIsOutOfProc() ? _contentProc.Guid() : winrt::guid{};
}
bool TermControl::_contentIsOutOfProc() const
{
return _contentProc != nullptr;

View file

@ -108,6 +108,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
ACTION_ARG(winrt::hstring, Profile, L"");
ACTION_ARG(Windows::Foundation::IReference<bool>, SuppressApplicationTitle, nullptr);
ACTION_ARG(winrt::hstring, ColorScheme);
ACTION_ARG(winrt::guid, ContentGuid);
static constexpr std::string_view CommandlineKey{ "commandline" };
static constexpr std::string_view StartingDirectoryKey{ "startingDirectory" };
@ -293,8 +294,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
MovePaneArgs(uint32_t& tabIndex) :
_TabIndex{ tabIndex } {};
ACTION_ARG(uint32_t, TabIndex, 0);
ACTION_ARG(winrt::hstring, Window, L"");
static constexpr std::string_view TabIndexKey{ "index" };
static constexpr std::string_view WindowKey{ "window" };
public:
hstring GenerateName() const;
@ -304,7 +307,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto otherAsUs = other.try_as<MovePaneArgs>();
if (otherAsUs)
{
return otherAsUs->_TabIndex == _TabIndex;
return otherAsUs->_TabIndex == _TabIndex && otherAsUs->_Window == _Window;
}
return false;
};
@ -313,6 +316,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
// LOAD BEARING: Not using make_self here _will_ break you in the future!
auto args = winrt::make_self<MovePaneArgs>();
JsonUtils::GetValueForKey(json, TabIndexKey, args->_TabIndex);
JsonUtils::GetValueForKey(json, WindowKey, args->_Window);
return { *args, {} };
}
static Json::Value ToJson(const IActionArgs& val)
@ -324,17 +328,19 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
Json::Value json{ Json::ValueType::objectValue };
const auto args{ get_self<MovePaneArgs>(val) };
JsonUtils::SetValueForKey(json, TabIndexKey, args->_TabIndex);
JsonUtils::SetValueForKey(json, WindowKey, args->_Window);
return json;
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<MovePaneArgs>() };
copy->_TabIndex = _TabIndex;
copy->_Window = _Window;
return *copy;
}
size_t Hash() const
{
return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(TabIndex());
return ::Microsoft::Terminal::Settings::Model::HashUtils::HashProperty(TabIndex(), Window());
}
};

View file

@ -119,6 +119,8 @@ namespace Microsoft.Terminal.Settings.Model
String ColorScheme;
Guid ContentGuid{ get; };
Boolean Equals(NewTerminalArgs other);
String GenerateName();
String ToCommandline();
@ -147,6 +149,7 @@ namespace Microsoft.Terminal.Settings.Model
{
MovePaneArgs(UInt32 tabIndex);
UInt32 TabIndex;
String Window;
};
[default_interface] runtimeclass SwitchToTabArgs : IActionArgs

View file

@ -214,6 +214,10 @@ void AppHost::_HandleCommandlineArgs()
peasant.DisplayWindowIdRequested({ this, &AppHost::_DisplayWindowId });
peasant.AttachRequested([this](auto&&, Remoting::AttachRequest args) {
_logic.AttachPane(args.ContentGuid(), args.TabIndex());
});
_logic.WindowName(peasant.WindowName());
_logic.WindowId(peasant.GetID());
}
@ -271,6 +275,9 @@ void AppHost::Initialize()
_logic.SettingsChanged({ this, &AppHost::_HandleSettingsChanged });
_logic.IsQuakeWindowChanged({ this, &AppHost::_IsQuakeWindowChanged });
_logic.SummonWindowRequested({ this, &AppHost::_SummonWindowRequested });
_logic.RequestMovePane([this](auto&&, winrt::TerminalApp::RequestMovePaneArgs args) {
_windowManager.RequestMovePane(args.Args().Window(), args.ContentGuid(), args.Args().TabIndex());
});
_window->UpdateTitle(_logic.Title());