Skip to content

Commit

Permalink
scoping to quek only
Browse files Browse the repository at this point in the history
  • Loading branch information
leonMSFT committed May 24, 2021
1 parent b3ae922 commit 7964b5a
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 73 deletions.
7 changes: 0 additions & 7 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,4 @@ 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);
}
}
2 changes: 0 additions & 2 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ 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;
#endif
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,5 @@ 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: 0 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ 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: 0 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ 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: 0 additions & 3 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ 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 @@ -132,7 +131,6 @@ 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 @@ -339,7 +337,6 @@ 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: 1 addition & 2 deletions src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@
ON_ALL_ACTIONS(RenameWindow) \
ON_ALL_ACTIONS(OpenWindowRenamer) \
ON_ALL_ACTIONS(GlobalSummon) \
ON_ALL_ACTIONS(QuakeMode) \
ON_ALL_ACTIONS(MinimizeToTray)
ON_ALL_ACTIONS(QuakeMode)
69 changes: 23 additions & 46 deletions src/cascadia/WindowsTerminal/AppHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../WinRTUtils/inc/WtExeUtils.h"
#include "resource.h"
#include "VirtualDesktopUtils.h"
#include "icon.h"

using namespace winrt::Windows::UI;
using namespace winrt::Windows::UI::Composition;
Expand Down Expand Up @@ -78,6 +79,7 @@ AppHost::AppHost() noexcept :
_window->WindowActivated({ this, &AppHost::_WindowActivated });
_window->HotkeyPressed({ this, &AppHost::_GlobalHotkeyPressed });
_window->NotifyTrayIconPressed({ this, &AppHost::_HandleTrayIconPressed });
_window->NotifyWindowMinimized({ this, &AppHost::_HandleWindowMinimized });
_window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop());
_window->MakeWindow();

Expand Down Expand Up @@ -267,7 +269,6 @@ 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 @@ -641,9 +642,6 @@ winrt::fire_and_forget AppHost::_WindowActivated()
void AppHost::_BecomeMonarch(const winrt::Windows::Foundation::IInspectable& /*sender*/,
const winrt::Windows::Foundation::IInspectable& /*args*/)
{
// Look at me, I'm the captain now.
_UpdateTrayIcon();

_setupGlobalHotkeys();
}

Expand Down Expand Up @@ -925,56 +923,35 @@ void AppHost::_IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectab

void AppHost::_UpdateTrayIcon()
{
if (_TrayIconData)
{
auto nid = _TrayIconData.value();
nid.hWnd = _window->GetHandle();
Shell_NotifyIcon(NIM_MODIFY, &nid);
}
else
{
NOTIFYICONDATA nid{};

if (HMODULE hModule = GetModuleHandleW(nullptr))
{
nid.hIcon = static_cast<HICON>(LoadImageW(hModule, MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
}
NOTIFYICONDATA nid{};

nid.hWnd = _window->GetHandle();
nid.uID = 1;
nid.uCallbackMessage = WM_APP + 1;
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), L"Windows Terminal");
nid.uFlags = NIF_MESSAGE | NIF_SHOWTIP | NIF_TIP | NIF_ICON;
// This HWND will receive the callbacks sent by the tray icon.
nid.hWnd = _window->GetHandle();

// Add the icon to the tray
// TODO: Only if there isn't already an Icon.
// If there is, we only need to update the HWND.
Shell_NotifyIcon(NIM_ADD, &nid);
nid.hIcon = static_cast<HICON>(GetActiveAppIconHandle(ICON_SMALL));
nid.uID = 1;
nid.uCallbackMessage = WM_APP + 1;
StringCchCopy(nid.szTip, ARRAYSIZE(nid.szTip), L"Windows Terminal");
nid.uFlags = NIF_MESSAGE | NIF_SHOWTIP | NIF_TIP | NIF_ICON;
Shell_NotifyIcon(NIM_ADD, &nid);

nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid);

_TrayIconData = nid;
}
// NIM_ADD won't set the version even if uVersion is set in the nid.
// We have to perform a NIM_SETVERSION call separately.
nid.uVersion = NOTIFYICON_VERSION_4;
Shell_NotifyIcon(NIM_SETVERSION, &nid);
}

void AppHost::_HandleTrayIconPressed()
{
// No name provided means show the MRU window.
Remoting::SummonWindowSelectionArgs args{};

// For now, just show the window where it originally was.
args.OnCurrentDesktop(true);
args.SummonBehavior().MoveToCurrentDesktop(false);
args.SummonBehavior().ToggleVisibility(false);
args.SummonBehavior().DropdownDuration(0);
args.SummonBehavior().ToMonitor(Remoting::MonitorBehavior::ToCurrent);

_windowManager.SummonWindow(args);
_window->SummonWindow({});
}

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

// Scoping "minimize to tray" to just the quake window.
// Broader support will come in later.
if (_logic.IsQuakeWindow())
{
_UpdateTrayIcon();
}
}
4 changes: 1 addition & 3 deletions src/cascadia/WindowsTerminal/AppHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,5 @@ class AppHost

void _UpdateTrayIcon();
void _HandleTrayIconPressed();
void _MinimizeToTrayRequested(const winrt::Windows::Foundation::IInspectable sender,
const winrt::Windows::Foundation::IInspectable args);
std::optional<NOTIFYICONDATA> _TrayIconData;
void _HandleWindowMinimized();
};
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize
{
if (wparam == SIZE_MINIMIZED && _isQuakeWindow)
{
_NotifyWindowMinimizedHandlers();
ShowWindow(GetHandle(), SW_HIDE);
return 0;
}
Expand Down Expand Up @@ -1295,6 +1296,8 @@ void IslandWindow::_globalDismissWindow(const uint32_t dropdownDuration)
{
ShowWindow(_window.get(), SW_MINIMIZE);
}

_NotifyWindowMinimizedHandlers();
}

// Method Description:
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class IslandWindow :
WINRT_CALLBACK(WindowActivated, winrt::delegate<void()>);
WINRT_CALLBACK(HotkeyPressed, winrt::delegate<void(long)>);
WINRT_CALLBACK(NotifyTrayIconPressed, winrt::delegate<void()>);
WINRT_CALLBACK(NotifyWindowMinimized, winrt::delegate<void()>);

protected:
void ForceResize()
Expand Down
19 changes: 12 additions & 7 deletions src/cascadia/WindowsTerminal/icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,27 @@ static int _GetActiveAppIconResource()
return iconResource;
}

void UpdateWindowIconForActiveMetrics(HWND window)
HANDLE GetActiveAppIconHandle(int size)
{
auto iconResource{ MAKEINTRESOURCEW(_GetActiveAppIconResource()) };

auto smXIcon = size == ICON_SMALL ? SM_CXSMICON : SM_CXICON;
auto smYIcon = size == ICON_SMALL ? SM_CYSMICON : SM_CYICON;

// These handles are loaded with LR_SHARED, so they are safe to "leak".
HANDLE smallIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(smallIcon);
HANDLE hIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(smXIcon), GetSystemMetrics(smYIcon), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(hIcon);

HANDLE largeIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(largeIcon);
return hIcon;
}

if (smallIcon)
void UpdateWindowIconForActiveMetrics(HWND window)
{
if (auto smallIcon = GetActiveAppIconHandle(ICON_SMALL))
{
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
}
if (largeIcon)
else if (auto largeIcon = GetActiveAppIconHandle(ICON_BIG))
{
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

#pragma once

HANDLE GetActiveAppIconHandle(const int size);
void UpdateWindowIconForActiveMetrics(HWND window);

1 comment on commit 7964b5a

@github-actions

This comment was marked as resolved.

Please sign in to comment.