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 Minimize to Tray and Tray Icon #10368

Merged
68 commits merged into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
150efbb
initial
leonMSFT May 20, 2021
87238e1
give it a fresh look
leonMSFT May 20, 2021
b3ae922
scaffolding for MinimizeToTray action
leonMSFT May 20, 2021
7964b5a
scoping to quek only
leonMSFT May 24, 2021
eee447c
cleanup
leonMSFT May 25, 2021
a83686a
using the correct term
leonMSFT May 25, 2021
e8462e0
not sure if necessary, but try not to add every single time
leonMSFT May 25, 2021
b2b76ca
remove when no longer quake
leonMSFT May 25, 2021
ce22c0c
pr comments, spelling
leonMSFT May 26, 2021
8fa4718
ok ok ok fine
leonMSFT May 26, 2021
bdfef54
saving progress
leonMSFT May 28, 2021
5f84958
run it back
leonMSFT May 28, 2021
2707769
merge conflicts
leonMSFT May 28, 2021
f432539
add a hwnd check
leonMSFT May 28, 2021
604c204
merge conflicts'
leonMSFT Jun 1, 2021
bd1a8a7
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
leonMSFT Jun 2, 2021
b90f0aa
remove this
leonMSFT Jun 2, 2021
f82cffa
smooth like butter
leonMSFT Jun 7, 2021
46af976
bring out your dead
leonMSFT Jun 7, 2021
ef3230d
using menucommand instead
leonMSFT Jun 8, 2021
9006092
bringing things in line
leonMSFT Jun 8, 2021
3aebbbd
ok....
leonMSFT Jun 8, 2021
e519aa4
i missed you, spellchk
leonMSFT Jun 8, 2021
03f138f
pr comments, updates'
leonMSFT Jun 15, 2021
cc1ec72
add the two settings
leonMSFT Jun 15, 2021
07467bc
formatting?
leonMSFT Jun 15, 2021
57c2117
creating enum for menu item action
leonMSFT Jun 16, 2021
30e01ba
fix focus terminal action
leonMSFT Jun 16, 2021
084c73f
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
leonMSFT Jun 16, 2021
8347e5a
moving SummonWindow to use ID
leonMSFT Jun 16, 2021
63f8d6b
cleanup
leonMSFT Jun 16, 2021
be222d2
removing unnecessaries
leonMSFT Jun 16, 2021
6e65805
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
leonMSFT Jun 16, 2021
f7cf496
formatting
leonMSFT Jun 16, 2021
178a4b4
please let this work
leonMSFT Jun 16, 2021
49d8d37
just let me be wrong
leonMSFT Jun 16, 2021
c70b11a
different casts
leonMSFT Jun 16, 2021
5b10d2e
ezilacol
leonMSFT Jun 16, 2021
6f1e795
more ptr
leonMSFT Jun 16, 2021
b68fdc5
nits
leonMSFT Jun 17, 2021
56dca6f
comments and formatting
leonMSFT Jun 17, 2021
d917b3f
merge conflicts
leonMSFT Jun 17, 2021
5def1a8
PR Comments
leonMSFT Jun 23, 2021
5131457
in its own little room
leonMSFT Jun 24, 2021
3e6e5f5
feature flags woohoo
leonMSFT Jun 24, 2021
4f58b42
feature flags woohoo 2
leonMSFT Jun 25, 2021
31901a5
use alwaysDisabledReleaseTokens
leonMSFT Jun 26, 2021
5670a5b
merge conflicts
leonMSFT Jun 28, 2021
722e176
formatting
leonMSFT Jun 28, 2021
df6a765
manual resource load, vcxproj revert
leonMSFT Jun 28, 2021
6baf215
merge from main
leonMSFT Jul 16, 2021
462fa74
spellers
leonMSFT Jul 16, 2021
09370d1
adding events to Peasant
leonMSFT Jul 16, 2021
59310fa
adding events to Monarch, WindowManager, AppHost
leonMSFT Jul 16, 2021
7fd9902
make the peasants let the monarch know what's up
leonMSFT Jul 18, 2021
add9aa0
now make the new monarch check for quakes
leonMSFT Jul 19, 2021
67e017c
formatting
leonMSFT Jul 19, 2021
570955b
test oopsies
leonMSFT Jul 19, 2021
5e5d0e4
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
leonMSFT Jul 20, 2021
d827e6b
cleaning up so eyes don't bleed
leonMSFT Jul 21, 2021
bc62fef
a bit of cleanup
leonMSFT Jul 22, 2021
af2ee79
smalls
leonMSFT Aug 5, 2021
a90d2ec
other smalls
leonMSFT Aug 6, 2021
50ffa27
PR comments, merge from main
leonMSFT Aug 6, 2021
ac8513e
rename from destroy tray icon to remove, put the if statement in defa…
leonMSFT Aug 9, 2021
1c731a1
move the windows to whence they came
leonMSFT Aug 10, 2021
df559c1
Merge branch 'main' into dev/lelian/notifyicon/yougetoneyougetone
leonMSFT Aug 11, 2021
cbf08aa
use constexpr for feature flag, copyright header, narrow_cast
leonMSFT Aug 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/spelling/allow/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ ACCEPTFILES
ACCESSDENIED
alignas
alignof
APPLYTOSUBMENUS
bitfield
bitfields
BUILDBRANCH
BUILDMSG
BUILDNUMBER
BYPOSITION
charconv
CLASSNOTAVAILABLE
cmdletbinding
Expand Down Expand Up @@ -77,6 +79,9 @@ llu
localtime
lround
LSHIFT
MENUCOMMAND
MENUDATA
MENUINFO
memicmp
mov
msappx
Expand All @@ -92,6 +97,7 @@ NOCHANGEDIR
NOPROGRESS
NOREDIRECTIONBITMAP
NOREPEAT
NOTIFYBYPOS
NOTIFYICON
NOTIFYICONDATA
ntprivapi
Expand Down Expand Up @@ -137,6 +143,7 @@ Stubless
Subheader
Subpage
syscall
TASKBARCREATED
TBPF
THEMECHANGED
tlg
Expand Down
2 changes: 2 additions & 0 deletions .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,7 @@ xes
xff
XFile
XFORM
xIcon
XManifest
XMath
XMFLOAT
Expand Down Expand Up @@ -2806,6 +2807,7 @@ YCast
YCENTER
YCount
YDPI
yIcon
yml
YOffset
YPosition
Expand Down
11 changes: 11 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@
"globalSummon",
"identifyWindow",
"identifyWindows",
"minimizeToTray",
leonMSFT marked this conversation as resolved.
Show resolved Hide resolved
"moveFocus",
"moveTab",
"newTab",
Expand Down Expand Up @@ -1162,6 +1163,16 @@
"minimum": 0,
"type": [ "integer", "string" ],
"deprecated": true
},
"minimizeToTray": {
"default": "false",
"description": "When set to true, minimizing a Terminal window will no longer appear in the taskbar. Instead, a Terminal icon will appear in the system tray through which the user can access their windows.",
"type": "boolean"
},
"alwaysShowTrayIcon": {
"default": "false",
"description": "When set to true, the Terminal's tray icon will always be shown in the system tray.",
"type": "boolean"
},
"actions": {
"description": "Properties are specific to each custom action.",
Expand Down
87 changes: 77 additions & 10 deletions src/cascadia/Remoting/Monarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
CATCH_LOG();
}

// This is a private constructor to be used in unit tests, where we don't
// want each Monarch to necessarily use the current PID.
// This constructor is intended to be used in unit tests,
// but we need to make it public in order to use make_self
// in the tests. It's not exposed through the idl though
// so it's not _truly_ fully public which should be acceptable.
Monarch::Monarch(const uint64_t testPID) :
_ourPID{ testPID }
{
Expand Down Expand Up @@ -78,6 +80,9 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
peasant.IdentifyWindowsRequested({ this, &Monarch::_identifyWindows });
peasant.RenameRequested({ this, &Monarch::_renameRequested });

peasant.ShowTrayIconRequested([this](auto&&, auto&&) { _ShowTrayIconRequestedHandlers(*this, nullptr); });
peasant.HideTrayIconRequested([this](auto&&, auto&&) { _HideTrayIconRequestedHandlers(*this, nullptr); });

_peasants[newPeasantsId] = peasant;

TraceLoggingWrite(g_hRemotingProvider,
Expand Down Expand Up @@ -732,20 +737,30 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
try
{
args.FoundMatch(false);

// If a WindowID is provided from the args, use that first.
uint64_t windowId = 0;
// If no name was provided, then just summon the MRU window.
if (searchedForName.empty())
if (args.WindowID())
{
// 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(), false);
windowId = args.WindowID().Value();
}
else
{
// Try to find a peasant that currently has this name
windowId = _lookupPeasantIdForName(searchedForName);
// If no name was provided, then just summon the MRU window.
if (searchedForName.empty())
{
// 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(), false);
}
else
{
// Try to find a peasant that currently has this name
windowId = _lookupPeasantIdForName(searchedForName);
}
}

if (auto targetPeasant{ _getPeasant(windowId) })
{
targetPeasant.Summon(args.SummonBehavior());
Expand All @@ -762,4 +777,56 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
}

// Method Description:
// - This method creates a map of peasant IDs to peasant names
// while removing dead peasants.
// Arguments:
// - <none>
// Return Value:
// - A map of peasant IDs to their names.
Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> Monarch::GetPeasantNames()
{
auto names = winrt::single_threaded_map<uint64_t, winrt::hstring>();

std::vector<uint64_t> peasantsToErase{};
for (const auto& [id, p] : _peasants)
{
try
{
names.Insert(id, p.WindowName());
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
peasantsToErase.push_back(id);
}
}

// Remove the dead peasants we came across while iterating.
for (const auto& id : peasantsToErase)
{
_peasants.erase(id);
_clearOldMruEntries(id);
}
leonMSFT marked this conversation as resolved.
Show resolved Hide resolved

return names.GetView();
}

void Monarch::SummonAllWindows()
{
auto callback = [](auto&& p, auto&& /*id*/) {
SummonWindowBehavior args{};
args.ToggleVisibility(false);
p.Summon(args);
};
auto onError = [](auto&& id) {
TraceLoggingWrite(g_hRemotingProvider,
"Monarch_SummonAll_Failed",
TraceLoggingInt64(id, "peasantID", "The ID of the peasant which we could not summon"),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
};
_forAllPeasantsIgnoringTheDead(callback, onError);
}
}
7 changes: 6 additions & 1 deletion src/cascadia/Remoting/Monarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
struct Monarch : public MonarchT<Monarch>
{
Monarch();
Monarch(const uint64_t testPID);
~Monarch();

uint64_t GetPID();
Expand All @@ -51,10 +52,14 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void HandleActivatePeasant(const winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs& args);
void SummonWindow(const Remoting::SummonWindowSelectionArgs& args);

void SummonAllWindows();
Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> GetPeasantNames();

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

private:
Monarch(const uint64_t testPID);
uint64_t _ourPID;

uint64_t _nextPeasantID{ 1 };
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/Remoting/Monarch.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Microsoft.Terminal.Remoting

Boolean FoundMatch;
SummonWindowBehavior SummonBehavior;
Windows.Foundation.IReference<UInt64> WindowID;
}


Expand All @@ -40,6 +41,11 @@ namespace Microsoft.Terminal.Remoting
void HandleActivatePeasant(WindowActivatedArgs args);
void SummonWindow(SummonWindowSelectionArgs args);

void SummonAllWindows();
Windows.Foundation.Collections.IMapView<UInt64, String> GetPeasantNames { get; };

event Windows.Foundation.TypedEventHandler<Object, FindTargetWindowArgs> FindTargetWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowTrayIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideTrayIconRequested;
};
}
39 changes: 37 additions & 2 deletions src/cascadia/Remoting/Peasant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
}

// This is a private constructor to be used in unit tests, where we don't
// want each Peasant to necessarily use the current PID.
// This constructor is intended to be used in unit tests,
// but we need to make it public in order to use make_self
// in the tests. It's not exposed through the idl though
// so it's not _truly_ fully public which should be acceptable.
Peasant::Peasant(const uint64_t testPID) :
_ourPID{ testPID }
{
Expand All @@ -31,6 +33,7 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
{
_id = id;
}

leonMSFT marked this conversation as resolved.
Show resolved Hide resolved
uint64_t Peasant::GetID()
{
return _id;
Expand Down Expand Up @@ -222,4 +225,36 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}

void Peasant::RequestShowTrayIcon()
{
try
{
_ShowTrayIconRequestedHandlers(*this, nullptr);
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
}
TraceLoggingWrite(g_hRemotingProvider,
"Peasant_RequestShowTrayIcon",
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}

void Peasant::RequestHideTrayIcon()
{
try
{
_HideTrayIconRequestedHandlers(*this, nullptr);
}
catch (...)
{
LOG_CAUGHT_EXCEPTION();
}
TraceLoggingWrite(g_hRemotingProvider,
"Peasant_RequestHideTrayIcon",
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE),
TraceLoggingKeyword(TIL_KEYWORD_TRACE));
}
}
4 changes: 4 additions & 0 deletions src/cascadia/Remoting/Peasant.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
void RequestIdentifyWindows();
void DisplayWindowId();
void RequestRename(const winrt::Microsoft::Terminal::Remoting::RenameRequestArgs& args);
void RequestShowTrayIcon();
void RequestHideTrayIcon();

winrt::Microsoft::Terminal::Remoting::WindowActivatedArgs GetLastActivatedArgs();

Expand All @@ -40,6 +42,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
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::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);

private:
Peasant(const uint64_t testPID);
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/Remoting/Peasant.idl
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,17 @@ namespace Microsoft.Terminal.Remoting
void RequestIdentifyWindows(); // Tells us to raise a IdentifyWindowsRequested
void RequestRename(RenameRequestArgs args); // Tells us to raise a RenameRequested
void Summon(SummonWindowBehavior behavior);
void RequestShowTrayIcon();
void RequestHideTrayIcon();

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, SummonWindowBehavior> SummonRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> ShowTrayIconRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> HideTrayIconRequested;
};

[default_interface] runtimeclass Peasant : IPeasant
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/Remoting/SummonWindowSelectionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace winrt::Microsoft::Terminal::Remoting::implementation
WINRT_PROPERTY(bool, FoundMatch, false);
WINRT_PROPERTY(bool, OnCurrentDesktop, false);
WINRT_PROPERTY(SummonWindowBehavior, SummonBehavior);

WINRT_PROPERTY(Windows::Foundation::IReference<uint64_t>, WindowID);
};
}

Expand Down
Loading