From 150efbb01f2ad9c089c6e7064f90b5148c5fadc5 Mon Sep 17 00:00:00 2001 From: Leon Liang Date: Thu, 20 May 2021 00:02:43 -0700 Subject: [PATCH] initial --- src/cascadia/TerminalApp/TerminalPage.cpp | 23 +++++++++++++++++++ src/cascadia/TerminalApp/TerminalPage.h | 2 ++ src/cascadia/WindowsTerminal/AppHost.cpp | 20 ++++++++++++++++ src/cascadia/WindowsTerminal/AppHost.h | 2 ++ src/cascadia/WindowsTerminal/IslandWindow.cpp | 20 ++++++++++++++++ src/cascadia/WindowsTerminal/IslandWindow.h | 1 + 6 files changed, 68 insertions(+) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 7f728e5ad94..144579bfd16 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -59,9 +59,32 @@ namespace winrt::TerminalApp::implementation HRESULT TerminalPage::Initialize(HWND hwnd) { _hostingHwnd = hwnd; + + TestNotifyIconFunction(); + return S_OK; } + void TerminalPage::TestNotifyIconFunction() + { + if (_hostingHwnd) + { + NOTIFYICONDATA nid{}; + + nid.hWnd = _hostingHwnd.value(); + 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; + + // Add the icon to the tray + Shell_NotifyIcon(NIM_ADD, &nid); + + nid.uVersion = NOTIFYICON_VERSION_4; + Shell_NotifyIcon(NIM_SETVERSION, &nid); + } + } + // Function Description: // - Recursively check our commands to see if there's a keybinding for // exactly their action. If there is, label that command with the text diff --git a/src/cascadia/TerminalApp/TerminalPage.h b/src/cascadia/TerminalApp/TerminalPage.h index 794fd0e1568..7a32e4217fd 100644 --- a/src/cascadia/TerminalApp/TerminalPage.h +++ b/src/cascadia/TerminalApp/TerminalPage.h @@ -341,6 +341,8 @@ namespace winrt::TerminalApp::implementation void _SetFocusMode(const bool inFocusMode); + void TestNotifyIconFunction(); + #pragma region ActionHandlers // These are all defined in AppActionHandlers.cpp #define ON_ALL_ACTIONS(action) DECLARE_ACTION_HANDLER(action); diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 6e4e24bdaa8..7b665325d03 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -77,6 +77,7 @@ AppHost::AppHost() noexcept : _window->MouseScrolled({ this, &AppHost::_WindowMouseWheeled }); _window->WindowActivated({ this, &AppHost::_WindowActivated }); _window->HotkeyPressed({ this, &AppHost::_GlobalHotkeyPressed }); + _window->NotifyIconPressed({ this, &AppHost::_NotifyIconPressed }); _window->SetAlwaysOnTop(_logic.GetInitialAlwaysOnTop()); _window->MakeWindow(); @@ -917,3 +918,22 @@ void AppHost::_IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectab { _window->IsQuakeWindow(_logic.IsQuakeWindow()); } + +void AppHost::_NotifyIconPressed() +{ + // 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); + if (args.FoundMatch()) + { + // Excellent, the window was found. We have nothing else to do here. + } +} diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index 712b757ef52..b3423267570 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -81,4 +81,6 @@ class AppHost void _IsQuakeWindowChanged(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args); + + void _NotifyIconPressed(); }; diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index ee2271e99cc..f2c609d73d5 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -506,6 +506,26 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize case WM_THEMECHANGED: 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. + case WM_APP + 1: + { + switch (LOWORD(lparam)) + { + case NIN_SELECT: + { + _NotifyIconPressedHandlers(); + break; + } + case WM_CONTEXTMENU: + { + // TODO: show the context menu + // Build it with ways to open specific windows + break; + } + } + break; + } } // TODO: handle messages here... diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index 470e8ecac79..43abcfebe02 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -51,6 +51,7 @@ class IslandWindow : WINRT_CALLBACK(MouseScrolled, winrt::delegate); WINRT_CALLBACK(WindowActivated, winrt::delegate); WINRT_CALLBACK(HotkeyPressed, winrt::delegate); + WINRT_CALLBACK(NotifyIconPressed, winrt::delegate); protected: void ForceResize()