Skip to content

Commit

Permalink
feature flags woohoo 2
Browse files Browse the repository at this point in the history
  • Loading branch information
leonMSFT committed Jun 25, 2021
1 parent 3e6e5f5 commit 4f58b42
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,16 +816,16 @@ namespace winrt::TerminalApp::implementation
}
}

#if TIL_FEATURE_TRAYICON_ENABLED
void TerminalPage::_HandleMinimizeToTray(const IInspectable& /*sender*/,
const ActionEventArgs& args)
{
#if TIL_FEATURE_TRAYICON_ENABLED
if (_settings.GlobalSettings().MinimizeToTray() || _settings.GlobalSettings().AlwaysShowTrayIcon())
{
_MinimizeToTrayRequestedHandlers(*this, nullptr);
}
#endif

args.Handled(true);
}
#endif
}
3 changes: 0 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,7 @@ namespace winrt::TerminalApp::implementation
TYPED_EVENT(RenameWindowRequested, Windows::Foundation::IInspectable, winrt::TerminalApp::RenameWindowRequestedArgs);
TYPED_EVENT(IsQuakeWindowChanged, IInspectable, IInspectable);
TYPED_EVENT(SummonWindowRequested, IInspectable, IInspectable);

#if TIL_FEATURE_TRAYICON_ENABLED
TYPED_EVENT(MinimizeToTrayRequested, IInspectable, IInspectable);
#endif

private:
friend struct TerminalPageT<TerminalPage>; // for Xaml to bind events
Expand Down
5 changes: 2 additions & 3 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "VirtualDesktopUtils.h"
#include "icon.h"

#include <ScopedResourceLoader.h>
#include <LibraryResources.h>

using namespace winrt::Windows::UI;
Expand Down Expand Up @@ -1002,10 +1001,10 @@ void AppHost::_CreateTrayIcon()
_trayIcon = std::make_unique<TrayIcon>(_window->GetHandle());

// Hookup the handlers, save the tokens for revoking if settings change.
_ReAddTrayIconToken = _window->NotifyReAddTrayIcon({ this, &AppHost::_CreateTrayIcon });
_ReAddTrayIconToken = _window->NotifyReAddTrayIcon([this]() { _trayIcon->ReAddTrayIcon(); });
_TrayIconPressedToken = _window->NotifyTrayIconPressed([this]() { _trayIcon->TrayIconPressed(); });
_ShowTrayContextMenuToken = _window->NotifyShowTrayContextMenu([this](til::point coord) { _trayIcon->ShowTrayContextMenu(coord, _windowManager.GetPeasantNames()); });
_TrayMenuItemSelectedToken = _window->NotifyTrayMenuItemSelected([this](HMENU menuHandle, UINT menuItemIndex) { _trayIcon->TrayMenuItemSelected(menuHandle, menuItemIndex); });
_TrayMenuItemSelectedToken = _window->NotifyTrayMenuItemSelected([this](HMENU hm, UINT idx) { _trayIcon->TrayMenuItemSelected(hm, idx); });
_trayIcon->SummonWindowRequested([this](auto& args) { _windowManager.SummonWindow(args); });
}

Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "pch.h"

#include "NonClientIslandWindow.h"

#if TIL_FEATURE_TRAYICON_ENABLED
#include "TrayIcon.h"
#endif

class AppHost
{
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,10 +572,12 @@ void IslandWindow::OnResize(const UINT width, const UINT height)
void IslandWindow::OnMinimize()
{
// TODO GH#1989 Stop rendering island content when the app is minimized.
#if TIL_FEATURE_TRAYICON_ENABLED
if (_minimizeToTray)
{
HideWindow();
}
#endif
}

// Method Description:
Expand Down Expand Up @@ -1510,10 +1512,12 @@ void IslandWindow::HideWindow()
ShowWindow(GetHandle(), SW_HIDE);
}

#if TIL_FEATURE_TRAYICON_ENABLED
void IslandWindow::SetMinimizeToTrayBehavior(bool minimizeToTray) noexcept
{
_minimizeToTray = minimizeToTray;
}
#endif

DEFINE_EVENT(IslandWindow, DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
DEFINE_EVENT(IslandWindow, WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
5 changes: 5 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class IslandWindow :
void IsQuakeWindow(bool isQuakeWindow) noexcept;

void HideWindow();

#if TIL_FEATURE_TRAYICON_ENABLED
void SetMinimizeToTrayBehavior(bool minimizeToTray) noexcept;
#endif

DECLARE_EVENT(DragRegionClicked, _DragRegionClickedHandlers, winrt::delegate<>);
DECLARE_EVENT(WindowCloseButtonClicked, _windowCloseButtonClickedHandler, winrt::delegate<>);
Expand Down Expand Up @@ -123,7 +126,9 @@ class IslandWindow :

void _summonWindowRoutineBody(winrt::Microsoft::Terminal::Remoting::SummonWindowBehavior args);

#if TIL_FEATURE_TRAYICON_ENABLED
bool _minimizeToTray{ false };
#endif

private:
// This minimum width allows for width the tabs fit
Expand Down
86 changes: 45 additions & 41 deletions src/cascadia/WindowsTerminal/TrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,15 @@ void TrayIcon::CreateTrayIcon()
// - This creates our context menu and displays it at the given
// screen coordinates.
// Arguments:
// - The coordinates where we should be showing the context menu.
// - coord: The coordinates where we should be showing the context menu.
// - peasants: The map of all peasants that should be available in the context menu.
// Return Value:
// - <none>
void TrayIcon::ShowTrayContextMenu(const til::point coord,
IMapView<uint64_t, winrt::hstring> peasants)
{
if (auto hmenu = _CreateTrayContextMenu())
if (auto hmenu = _CreateTrayContextMenu(peasants))
{
// Submenu for Windows
if (auto windowSubmenu = _CreateWindowSubmenu(peasants))
{
MENUINFO submenuInfo{};
submenuInfo.cbSize = sizeof(MENUINFO);
submenuInfo.fMask = MIM_MENUDATA;
submenuInfo.dwStyle = MNS_NOTIFYBYPOS;
submenuInfo.dwMenuData = gsl::narrow<UINT_PTR>(TrayMenuItemAction::SummonWindow);
SetMenuInfo(windowSubmenu, &submenuInfo);

AppendMenu(hmenu, MF_POPUP, reinterpret_cast<UINT_PTR>(windowSubmenu), RS_(L"TrayIconWindowSubmenu").c_str());
}

// We'll need to set our window to the foreground before calling
// TrackPopupMenuEx or else the menu won't dismiss when clicking away.
SetForegroundWindow(_owningHwnd);
Expand All @@ -107,10 +95,10 @@ void TrayIcon::ShowTrayContextMenu(const til::point coord,
// Method Description:
// - This creates the context menu for our tray icon.
// Arguments:
// - <none>
// - peasants: A map of all peasants' ID to their window name.
// Return Value:
// - The handle to the newly created context menu.
HMENU TrayIcon::_CreateTrayContextMenu()
HMENU TrayIcon::_CreateTrayContextMenu(IMapView<uint64_t, winrt::hstring> peasants)
{
auto hmenu = CreatePopupMenu();
if (hmenu)
Expand All @@ -125,36 +113,34 @@ HMENU TrayIcon::_CreateTrayContextMenu()
// Focus Current Terminal Window
AppendMenu(hmenu, MF_STRING, gsl::narrow<UINT_PTR>(TrayMenuItemAction::FocusTerminal), RS_(L"TrayIconFocusTerminal").c_str());
AppendMenu(hmenu, MF_SEPARATOR, 0, L"");
}
return hmenu;
}

// Method Description:
// - Create a menu with a menu item for each window available to summon.
// If a window is unnamed, we'll use its ID but still mention that it's unnamed.
// Arguments:
// - <none>
// Return Value:
// - The handle to the newly created window submenu.
HMENU TrayIcon::_CreateWindowSubmenu(IMapView<uint64_t, winrt::hstring> peasants)
{
if (auto hmenu = CreatePopupMenu())
{
const auto locWindow = RS_(L"WindowIdLabel");
const auto locUnnamed = RS_(L"UnnamedWindowName");
for (const auto [id, name] : peasants)
// Submenu for Windows
if (auto submenu = CreatePopupMenu())
{
winrt::hstring displayText = name;
if (name.empty())
const auto locWindow = RS_(L"WindowIdLabel");
const auto locUnnamed = RS_(L"UnnamedWindowName");
for (const auto [id, name] : peasants)
{
displayText = fmt::format(L"{} {} - <{}>", locWindow, id, locUnnamed);
winrt::hstring displayText = name;
if (name.empty())
{
displayText = fmt::format(L"{} {} - <{}>", locWindow, id, locUnnamed);
}

AppendMenu(submenu, MF_STRING, gsl::narrow<UINT_PTR>(id), displayText.c_str());
}

AppendMenu(hmenu, MF_STRING, gsl::narrow<UINT_PTR>(id), displayText.c_str());
MENUINFO submenuInfo{};
submenuInfo.cbSize = sizeof(MENUINFO);
submenuInfo.fMask = MIM_MENUDATA;
submenuInfo.dwStyle = MNS_NOTIFYBYPOS;
submenuInfo.dwMenuData = (UINT_PTR)TrayMenuItemAction::SummonWindow;
SetMenuInfo(submenu, &submenuInfo);

AppendMenu(hmenu, MF_POPUP, (UINT_PTR)submenu, RS_(L"TrayIconWindowSubmenu").c_str());
}
return hmenu;
}
return nullptr;
return hmenu;
}

// Method Description:
Expand Down Expand Up @@ -198,6 +184,12 @@ void TrayIcon::TrayMenuItemSelected(const HMENU menu, const UINT menuItemIndex)
}
}

// Method Description:
// - This is the handler for when the tray icon itself is left-clicked.
// Arguments:
// - <none>
// Return Value:
// - <none>
void TrayIcon::TrayIconPressed()
{
// No name in the args means summon the mru window.
Expand All @@ -207,7 +199,19 @@ void TrayIcon::TrayIconPressed()
}

// Method Description:
// - Deletes our tray icon if we have one.
// - Re-add a tray icon using our currently saved tray icon data.
// Arguments:
// - <none>
// Return Value:
// - <none>
void TrayIcon::ReAddTrayIcon()
{
Shell_NotifyIcon(NIM_ADD, &_trayIconData);
Shell_NotifyIcon(NIM_SETVERSION, &_trayIconData);
}

// Method Description:
// - Deletes our tray icon.
// Arguments:
// - <none>
// Return Value:
Expand Down
7 changes: 4 additions & 3 deletions src/cascadia/WindowsTerminal/TrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ class TrayIcon
~TrayIcon();

void CreateTrayIcon();
void DestroyTrayIcon();
void ReAddTrayIcon();

void TrayIconPressed();
void ShowTrayContextMenu(const til::point coord, winrt::Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> peasants);
void TrayMenuItemSelected(const HMENU menu, const UINT menuItemIndex);
void DestroyTrayIcon();

WINRT_CALLBACK(SummonWindowRequested, winrt::delegate<void(winrt::Microsoft::Terminal::Remoting::SummonWindowSelectionArgs)>);

private:
HMENU _CreateTrayContextMenu();
HMENU _CreateWindowSubmenu(winrt::Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> peasants);
HMENU _CreateTrayContextMenu(winrt::Windows::Foundation::Collections::IMapView<uint64_t, winrt::hstring> peasants);

HWND _owningHwnd;
NOTIFYICONDATA _trayIconData;
Expand Down
1 change: 1 addition & 0 deletions src/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<description>Controls whether the Tray Icon and related settings (aka. MinimizeToTray and AlwaysShowTrayIcon) are enabled</description>
<stage>AlwaysDisabled</stage>
<alwaysEnabledBrandingTokens>
<brandingToken>Dev</brandingToken>

This comment has been minimized.

Copy link
@DHowett

DHowett Jun 25, 2021

Member

I'd suggest... and maybe i need to write better guidance on this!... the following:

<stage>AlwaysEnabled</stage>
<alwaysDisabledReleaseTokens/>

it'll be enabled in pre/dev, disabled in Release

</alwaysEnabledBrandingTokens>
</feature>
</featureStaging>

0 comments on commit 4f58b42

Please sign in to comment.