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 desktop param to globalSummon; set _quake = toCurrent #9954

Merged
merged 1 commit into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,33 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

```

## `VirtualDesktopUtils`

**Source**: [https://github.com/microsoft/PowerToys](https://github.com/microsoft/PowerToys)

### License

```
The MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
6 changes: 6 additions & 0 deletions src/cascadia/Remoting/Microsoft.Terminal.RemotingLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<ClInclude Include="SummonWindowSelectionArgs.h">
<DependentUpon>Monarch.idl</DependentUpon>
</ClInclude>
<ClInclude Include="SummonWindowBehavior.h">
<DependentUpon>Peasant.idl</DependentUpon>
</ClInclude>
<ClInclude Include="RenameRequestArgs.h">
<DependentUpon>Peasant.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -60,6 +63,9 @@
<ClCompile Include="SummonWindowSelectionArgs.cpp">
<DependentUpon>Monarch.idl</DependentUpon>
</ClCompile>
<ClCompile Include="SummonWindowBehavior.cpp">
<DependentUpon>Peasant.idl</DependentUpon>
</ClCompile>
<ClCompile Include="RenameRequestArgs.cpp">
<DependentUpon>Peasant.idl</DependentUpon>
</ClCompile>
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// If no name was provided, then just summon the MRU window.
if (searchedForName.empty())
{
windowId = _getMostRecentPeasantID(true);
// Use the value of the `desktop` arg to determine if we should
// limit to the current desktop (desktop:onCurrent) or not
// (desktop:any or desktop:toCurrent)
windowId = _getMostRecentPeasantID(args.OnCurrentDesktop());
}
else
{
Expand All @@ -720,7 +723,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
}
if (auto targetPeasant{ _getPeasant(windowId) })
{
targetPeasant.Summon();
targetPeasant.Summon(args.SummonBehavior());
args.FoundMatch(true);
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/Remoting/Monarch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ namespace Microsoft.Terminal.Remoting
SummonWindowSelectionArgs();
SummonWindowSelectionArgs(String windowName);
String WindowName;
Boolean OnCurrentDesktop;
// TODO GH#8888 Other options:
// * CurrentDesktop
// * CurrentMonitor

Boolean FoundMatch;
SummonWindowBehavior SummonBehavior;
}


[default_interface] runtimeclass Monarch {
Monarch();

Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/Remoting/Peasant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pch.h"
#include "Peasant.h"
#include "CommandlineArgs.h"
#include "SummonWindowBehavior.h"
#include "Peasant.g.cpp"
#include "../../types/inc/utils.hpp"

Expand Down Expand Up @@ -126,14 +127,17 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
// - <none>
// Return Value:
// - <none>
void Peasant::Summon()
void Peasant::Summon(const Remoting::SummonWindowBehavior& summonBehavior)
{
_SummonRequestedHandlers(*this, nullptr);
auto localCopy = winrt::make<implementation::SummonWindowBehavior>(summonBehavior);

TraceLoggingWrite(g_hRemotingProvider,
"Peasant_Summon",
TraceLoggingUInt64(GetID(), "peasantID", "Our ID"),
TraceLoggingUInt64(localCopy->MoveToCurrentDesktop(), "MoveToCurrentDesktop", "true if we should move to the current desktop"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));

_SummonRequestedHandlers(*this, localCopy);
}

// Method Description:
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/Remoting/Peasant.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
bool ExecuteCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs& args);
void ActivateWindow(const winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs& args);

void Summon();
void Summon(const Remoting::SummonWindowBehavior& summonBehavior);
void RequestIdentifyWindows();
void DisplayWindowId();
void RequestRename(const winrt::Microsoft::Terminal::Remoting::RenameRequestArgs& args);
Expand All @@ -39,7 +39,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TYPED_EVENT(IdentifyWindowsRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(DisplayWindowIdRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(RenameRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::RenameRequestArgs);
TYPED_EVENT(SummonRequested, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);
TYPED_EVENT(SummonRequested, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Remoting::SummonWindowBehavior);

private:
Peasant(const uint64_t testPID);
Expand Down
11 changes: 9 additions & 2 deletions src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ namespace Microsoft.Terminal.Remoting
Windows.Foundation.DateTime ActivatedTime { get; };
};

[default_interface] runtimeclass SummonWindowBehavior {
SummonWindowBehavior();
Boolean MoveToCurrentDesktop;
// Other options:
// * CurrentMonitor
}

interface IPeasant
{
CommandlineArgs InitialArgs { get; };
Expand All @@ -46,14 +53,14 @@ namespace Microsoft.Terminal.Remoting
String WindowName { get; };
void RequestIdentifyWindows(); // Tells us to raise a IdentifyWindowsRequested
void RequestRename(RenameRequestArgs args); // Tells us to raise a RenameRequested
void Summon();
void Summon(SummonWindowBehavior behavior);

event Windows.Foundation.TypedEventHandler<Object, WindowActivatedArgs> WindowActivated;
event Windows.Foundation.TypedEventHandler<Object, CommandlineArgs> ExecuteCommandlineRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> IdentifyWindowsRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> DisplayWindowIdRequested;
event Windows.Foundation.TypedEventHandler<Object, RenameRequestArgs> RenameRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> SummonRequested;
event Windows.Foundation.TypedEventHandler<Object, SummonWindowBehavior> SummonRequested;
};

[default_interface] runtimeclass Peasant : IPeasant
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/Remoting/SummonWindowBehavior.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "SummonWindowBehavior.h"
#include "SummonWindowBehavior.g.cpp"
35 changes: 35 additions & 0 deletions src/cascadia/Remoting/SummonWindowBehavior.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.

Class Name:
- SummonWindowBehavior.h

Abstract:
- TODO!
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

--*/

#pragma once

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

namespace winrt::Microsoft::Terminal::Remoting::implementation
{
struct SummonWindowBehavior : public SummonWindowBehaviorT<SummonWindowBehavior>
{
public:
SummonWindowBehavior() = default;
WINRT_PROPERTY(bool, MoveToCurrentDesktop, true);

public:
SummonWindowBehavior(const Remoting::SummonWindowBehavior& other) :
_MoveToCurrentDesktop{ other.MoveToCurrentDesktop() } {};
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
};
}

namespace winrt::Microsoft::Terminal::Remoting::factory_implementation
{
BASIC_FACTORY(SummonWindowBehavior);
}
3 changes: 3 additions & 0 deletions src/cascadia/Remoting/SummonWindowSelectionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
_WindowName{ name } {};

WINRT_PROPERTY(winrt::hstring, WindowName);

WINRT_PROPERTY(bool, FoundMatch, false);
WINRT_PROPERTY(bool, OnCurrentDesktop, false);
WINRT_PROPERTY(SummonWindowBehavior, SummonBehavior);
};
}

Expand Down
9 changes: 7 additions & 2 deletions src/cascadia/TerminalSettingsModel/ActionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1044,17 +1044,20 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{
GlobalSummonArgs() = default;
WINRT_PROPERTY(winrt::hstring, Name, L"");
WINRT_PROPERTY(Model::DesktopBehavior, Desktop, Model::DesktopBehavior::ToCurrent);

static constexpr std::string_view NameKey{ "name" };
static constexpr std::string_view DesktopKey{ "desktop" };

public:
hstring GenerateName() const;

bool Equals(const IActionArgs& other)
{
if (auto otherAsUs = other.try_as<GlobalSummonArgs>(); otherAsUs)
if (auto otherAsUs = other.try_as<GlobalSummonArgs>())
{
return otherAsUs->_Name == _Name;
return otherAsUs->_Name == _Name &&
otherAsUs->_Desktop == _Desktop;
}
return false;
};
Expand All @@ -1063,12 +1066,14 @@ 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<GlobalSummonArgs>();
JsonUtils::GetValueForKey(json, NameKey, args->_Name);
JsonUtils::GetValueForKey(json, DesktopKey, args->_Desktop);
return { *args, {} };
}
IActionArgs Copy() const
{
auto copy{ winrt::make_self<GlobalSummonArgs>() };
copy->_Name = _Name;
copy->_Desktop = _Desktop;
return *copy;
}
// SPECIAL! This deserializer creates a GlobalSummonArgs with the
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionArgs.idl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ namespace Microsoft.Terminal.Settings.Model
Disabled,
};

enum DesktopBehavior
{
Any,
ToCurrent,
OnCurrent,
};

[default_interface] runtimeclass NewTerminalArgs {
NewTerminalArgs();
NewTerminalArgs(Int32 profileIndex);
Expand Down Expand Up @@ -256,5 +263,6 @@ namespace Microsoft.Terminal.Settings.Model
[default_interface] runtimeclass GlobalSummonArgs : IActionArgs
{
String Name { get; };
DesktopBehavior Desktop { get; };
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,12 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::WindowingMode)
pair_type{ "useExisting", ValueType::UseExisting },
};
};

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::DesktopBehavior)
{
JSON_MAPPINGS(3) = {
pair_type{ "any", ValueType::Any },
pair_type{ "toCurrent", ValueType::ToCurrent },
pair_type{ "onCurrent", ValueType::OnCurrent },
};
};