Skip to content

Commit

Permalink
scaffolding for MinimizeToTray action
Browse files Browse the repository at this point in the history
  • Loading branch information
leonMSFT committed May 20, 2021
1 parent 87238e1 commit b3ae922
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,4 +790,11 @@ namespace winrt::TerminalApp::implementation
// if it wasn't bound at all.
args.Handled(false);
}

void TerminalPage::_HandleMinimizeToTray(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
_MinimizeToTrayRequestedHandlers(*this, nullptr);
args.Handled(true);
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ namespace winrt::TerminalApp::implementation
FORWARDED_TYPED_EVENT(IdentifyWindowsRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, IdentifyWindowsRequested);
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(MinimizeToTrayRequested, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable, _root, MinimizeToTrayRequested);

#ifdef UNIT_TESTING
friend class TerminalAppLocalTests::CommandlineTest;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, RenameWindowRequestedArgs> RenameWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> SettingsChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> MinimizeToTrayRequested;
}
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(IdentifyWindowsRequested, IInspectable, IInspectable);
TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs);
TYPED_EVENT(IsQuakeWindowChanged, IInspectable, IInspectable);
TYPED_EVENT(MinimizeToTrayRequested, IInspectable, IInspectable);

private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ namespace TerminalApp
event Windows.Foundation.TypedEventHandler<Object, Object> IdentifyWindowsRequested;
event Windows.Foundation.TypedEventHandler<Object, RenameWindowRequestedArgs> RenameWindowRequested;
event Windows.Foundation.TypedEventHandler<Object, Object> IsQuakeWindowChanged;
event Windows.Foundation.TypedEventHandler<Object, Object> MinimizeToTrayRequested;
}
}
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static constexpr std::string_view RenameWindowKey{ "renameWindow" };
static constexpr std::string_view OpenWindowRenamerKey{ "openWindowRenamer" };
static constexpr std::string_view GlobalSummonKey{ "globalSummon" };
static constexpr std::string_view QuakeModeKey{ "quakeMode" };
static constexpr std::string_view MinimizeToTrayKey{ "minimizeToTray" };

static constexpr std::string_view ActionKey{ "action" };

Expand Down Expand Up @@ -131,6 +132,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ OpenWindowRenamerKey, ShortcutAction::OpenWindowRenamer },
{ GlobalSummonKey, ShortcutAction::GlobalSummon },
{ QuakeModeKey, ShortcutAction::QuakeMode },
{ MinimizeToTrayKey, ShortcutAction::MinimizeToTray },
};

using ParseResult = std::tuple<IActionArgs, std::vector<SettingsLoadWarnings>>;
Expand Down Expand Up @@ -337,6 +339,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::OpenWindowRenamer, RS_(L"OpenWindowRenamerCommandKey") },
{ ShortcutAction::GlobalSummon, L"" }, // Intentionally omitted, must be generated by GenerateName
{ ShortcutAction::QuakeMode, RS_(L"QuakeModeCommandKey") },
{ ShortcutAction::MinimizeToTray, L"" }
};
}();

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,5 @@
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode)
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(MinimizeToTray)
11 changes: 9 additions & 2 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ AppHost::AppHost() noexcept :
_window->MouseScrolled({ this, &AppHost::_WindowMouseWheeled });
_window->WindowActivated({ this, &AppHost::_WindowActivated });
_window->HotkeyPressed({ this, &AppHost::_GlobalHotkeyPressed });
_window->NotifyIconPressed({ this, &AppHost::_TrayIconPressed });
_window->NotifyTrayIconPressed({ this, &AppHost::_HandleTrayIconPressed });
_window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop());
_window->MakeWindow();

Expand Down Expand Up @@ -267,6 +267,7 @@ void AppHost::Initialize()
_logic.RenameWindowRequested({ this, &AppHost::_RenameWindowRequested });
_logic.SettingsChanged({ this, &AppHost::_HandleSettingsChanged });
_logic.IsQuakeWindowChanged({ this, &AppHost::_IsQuakeWindowChanged });
_logic.MinimizeToTrayRequested({ this, &AppHost::_MinimizeToTrayRequested });

_window->UpdateTitle(_logic.Title());

Expand Down Expand Up @@ -957,7 +958,7 @@ void AppHost::_UpdateTrayIcon()
}
}

void AppHost::_TrayIconPressed()
void AppHost::_HandleTrayIconPressed()
{
// No name provided means show the MRU window.
Remoting::SummonWindowSelectionArgs args{};
Expand All @@ -971,3 +972,9 @@ void AppHost::_TrayIconPressed()

_windowManager.SummonWindow(args);
}

void AppHost::_MinimizeToTrayRequested(const winrt::Windows::Foundation::IInspectable sender,
const winrt::Windows::Foundation::IInspectable args)
{

}
4 changes: 3 additions & 1 deletion src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class AppHost
const winrt::Windows::Foundation::IInspectable& args);

void _UpdateTrayIcon();
void _TrayIconPressed();
void _HandleTrayIconPressed();
void _MinimizeToTrayRequested(const winrt::Windows::Foundation::IInspectable sender,
const winrt::Windows::Foundation::IInspectable args);
std::optional<NOTIFYICONDATA> _TrayIconData;
};
8 changes: 4 additions & 4 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,20 +507,20 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
UpdateWindowIconForActiveMetrics(_window.get());
return 0;
// TODO: Give this a better name, something like WT_NOTIFYICON
// WM_APP to 0xBFFF is available for use for apps.
// WM_APP to 0xBFFF is available for use for apps apparently.
case WM_APP + 1:
{
switch (LOWORD(lparam))
{
case NIN_SELECT:
case NIN_KEYSELECT:
{
_NotifyIconPressedHandlers();
_NotifyTrayIconPressedHandlers();
break;
}
case WM_CONTEXTMENU:
{
// TODO: show the context menu
// Build it with ways to open specific windows
// TODO: show the context menu - buncho options to open specific windows?
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class IslandWindow :
WINRT_CALLBACK(MouseScrolled, winrt::delegate<void(til::point, int32_t)>);
WINRT_CALLBACK(WindowActivated, winrt::delegate<void()>);
WINRT_CALLBACK(HotkeyPressed, winrt::delegate<void(long)>);
WINRT_CALLBACK(NotifyIconPressed, winrt::delegate<void()>);
WINRT_CALLBACK(NotifyTrayIconPressed, winrt::delegate<void()>);

protected:
void ForceResize()
Expand Down

1 comment on commit b3ae922

@github-actions

This comment was marked as resolved.

Please sign in to comment.