A brief summary of the behavior of the tray icon: - There will only ever be one tray icon representing all windows. - Left-Click on a Tray Icon brings up the MRU window. - Right-Click on a Tray Icon brings up a Context Menu: ``` Focus Terminal ---------------- Windows --> Window ID 1 - <unnamed window> Named Window Named Window Again ``` - Focus Terminal will bring up the MRU window. - Clicking on any of the Window "names" in the submenu will summon the window. ## Settings Changes Two new global settings are introduced: `alwaysShowTrayIcon` and `minimizeToTray`. Here's a chart explaining the behavior with the two settings. | | `alwaysShowTrayIcon:true` | `alwaysShowTrayIcon:false` | |----------------------|------------------------------------------------------------------|------------------------------------------------------------------| | `minimizeToTray:true` | tray icon is always shown. minimize button will hide the window. | tray icon is always shown. minimize button will hide the window. | | `minimizeToTray:false` | tray icon is always shown. | tray icon is not shown ever. | Closes #5727 ## References [Spec for Minimize to Tray](https://github.com/microsoft/terminal/blob/main/doc/specs/%23653%20-%20Quake%20Mode/%23653%20-%20Quake%20Mode.md#minimize-to-tray) Docs PR - MicrosoftDocs/terminal#352 #10448 - My list of TODOs
57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#include "pch.h"
|
|
#include "resource.h"
|
|
|
|
static int _GetActiveAppIconResource()
|
|
{
|
|
auto iconResource{ IDI_APPICON };
|
|
|
|
HIGHCONTRASTW hcInfo{};
|
|
hcInfo.cbSize = sizeof(hcInfo);
|
|
|
|
if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(hcInfo), &hcInfo, 0))
|
|
{
|
|
if (WI_IsFlagSet(hcInfo.dwFlags, HCF_HIGHCONTRASTON))
|
|
{
|
|
iconResource = IDI_APPICON_HC_BLACK;
|
|
|
|
if (0x00FFFFFF == GetSysColor(COLOR_WINDOW)) // white window color == white high contrast
|
|
{
|
|
iconResource = IDI_APPICON_HC_WHITE;
|
|
}
|
|
}
|
|
}
|
|
|
|
return iconResource;
|
|
}
|
|
|
|
// There's only two possible sizes - ICON_SMALL and ICON_BIG.
|
|
// So, use true for smallIcon if you want small and false for big.
|
|
HANDLE GetActiveAppIconHandle(bool smallIcon)
|
|
{
|
|
auto iconResource{ MAKEINTRESOURCEW(_GetActiveAppIconResource()) };
|
|
|
|
const auto smXIcon = smallIcon ? SM_CXSMICON : SM_CXICON;
|
|
const auto smYIcon = smallIcon ? SM_CYSMICON : SM_CYICON;
|
|
|
|
// These handles are loaded with LR_SHARED, so they are safe to "leak".
|
|
HANDLE hIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(smXIcon), GetSystemMetrics(smYIcon), LR_SHARED) };
|
|
LOG_LAST_ERROR_IF_NULL(hIcon);
|
|
|
|
return hIcon;
|
|
}
|
|
|
|
void UpdateWindowIconForActiveMetrics(HWND window)
|
|
{
|
|
if (auto smallIcon = GetActiveAppIconHandle(true))
|
|
{
|
|
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
|
|
}
|
|
if (auto largeIcon = GetActiveAppIconHandle(false))
|
|
{
|
|
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
|
|
}
|
|
}
|