Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WT's icon at runtime to match high-contrast as applicable #7971

Merged
10 commits merged into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/actions/spell-check/dictionary/apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ ACCESSDENIED
alignof
bitfield
bitfields
COLORPROPERTY
CLASSNOTAVAILABLE
COLORPROPERTY
CXICON
CYICON
environstrings
EXPCMDFLAGS
EXPCMDSTATE
fullkbd
futex
GETDESKWALLPAPER
GETHIGHCONTRAST
Hashtable
HIGHCONTRASTON
HIGHCONTRASTW
href
IAsync
IBind
Expand All @@ -25,8 +31,8 @@ IInheritable
IMap
IObject
IStorage
llabs
LCID
llabs
lround
LSHIFT
NCHITTEST
Expand All @@ -46,14 +52,14 @@ RSHIFT
rx
serializer
SIZENS
GETDESKWALLPAPER
UPDATEINIFILE
spsc
STDCPP
strchr
syscall
THEMECHANGED
tmp
tx
UPDATEINIFILE
userenv
wcstoui
XDocument
Expand Down
26 changes: 26 additions & 0 deletions res/terminal/Generate-TerminalAssets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Param(
[string]$Path,
[string]$Destination,
[int[]]$Altforms = (16, 20, 24, 30, 32, 36, 40, 48, 60, 64, 72, 80, 96, 256),
[int[]]$Win32IconSizes = (16, 20, 24, 32, 48, 64, 256),
[switch]$Unplated = $true,
[float[]]$Scales = (1.0, 1.25, 1.5, 2.0, 4.0),
[string]$HighContrastPath = "",
Expand Down Expand Up @@ -115,6 +116,7 @@ If (-Not [string]::IsNullOrEmpty($Destination)) {
$TranslatedOutDir = "."
}

$intermediates = [System.Collections.Concurrent.ConcurrentBag[PSCustomObject]]::new()
$intermediateFiles = [System.Collections.Concurrent.ConcurrentBag[string]]::new()

# Generate the base icons
Expand All @@ -136,6 +138,11 @@ $allSizes | ForEach-Object -Parallel {
}

($using:intermediateFiles).Add($intermediateStandardNt)
($using:intermediates).Add([PSCustomObject]@{
Contrast = "standard"
Size = $sz
PathWSL = $intermediateStandardWsl
})

If ($svgContrastWsl -Ne $null) {
$intermediateBlackNt = "$destinationNt\_intermediate.black.$($sz).png"
Expand All @@ -158,7 +165,26 @@ $allSizes | ForEach-Object -Parallel {

($using:intermediateFiles).Add($intermediateBlackNt)
($using:intermediateFiles).Add($intermediateWhiteNt)
($using:intermediates).Add([PSCustomObject]@{
Contrast = "black"
Size = $sz
PathWSL = $intermediateBlackWsl
})
($using:intermediates).Add([PSCustomObject]@{
Contrast = "white"
Size = $sz
PathWSL = $intermediateWhiteWsl
})
}
}

$intermediates | ? { $_.Size -In $Win32IconSizes } | Group-Object Contrast | ForEach-Object -Parallel {
$assetName = "terminal.ico"
If ($_.Name -Ne "standard") {
$assetName = "terminal_contrast-$($_.Name).ico"
}
Write-Host "Producing win32 .ico for contrast=$($_.Name) as $assetName"
wsl convert $_.Group.PathWSL "$($using:TranslatedOutDir)/$assetName"
}

# Once the base icons are done, splat them into the middles of larger canvases.
Expand Down
Binary file modified res/terminal/images-Dev/LargeTile.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-100_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-100_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-125_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-125_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-150_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-150_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-200_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-200_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-400.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-400_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LargeTile.scale-400_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-100_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-100_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-125.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-125_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-125_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-150_contrast-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-150_contrast-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-200_contrast-black.png
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-200_contrast-white.png
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-400.png
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-400_contrast-black.png
Binary file modified res/terminal/images-Dev/LockScreenLogo.scale-400_contrast-white.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-100.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-100_contrast-black.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-100_contrast-white.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-125.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-125_contrast-black.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-125_contrast-white.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-150.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-150_contrast-black.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-150_contrast-white.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-200.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-200_contrast-black.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-200_contrast-white.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-400.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-400_contrast-black.png
Binary file modified res/terminal/images-Dev/SmallTile.scale-400_contrast-white.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-100.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-100_contrast-black.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-100_contrast-white.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-125.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-125_contrast-black.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-125_contrast-white.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-150.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-150_contrast-black.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-150_contrast-white.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-200.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-200_contrast-black.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-200_contrast-white.png
Binary file modified res/terminal/images-Dev/SplashScreen.scale-400.png
Binary file modified res/terminal/images-Dev/Square150x150Logo.scale-100.png
Binary file modified res/terminal/images-Dev/Square150x150Logo.scale-125.png
Binary file modified res/terminal/images-Dev/Square150x150Logo.scale-150.png
Binary file modified res/terminal/images-Dev/Square150x150Logo.scale-200.png
Binary file modified res/terminal/images-Dev/Square150x150Logo.scale-400.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.scale-100.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.scale-125.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.scale-150.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.scale-200.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.scale-400.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-16.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-20.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-24.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-256.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-30.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-32.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-36.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-40.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-48.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-60.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-64.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-72.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-80.png
Binary file modified res/terminal/images-Dev/Square44x44Logo.targetsize-96.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-100.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-100_contrast-black.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-100_contrast-white.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-125.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-125_contrast-black.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-125_contrast-white.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-150.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-150_contrast-black.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-150_contrast-white.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-200.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-200_contrast-black.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-200_contrast-white.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-400.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-400_contrast-black.png
Binary file modified res/terminal/images-Dev/StoreLogo.scale-400_contrast-white.png
Binary file modified res/terminal/images-Dev/Wide310x150Logo.scale-100.png
Binary file modified res/terminal/images-Dev/Wide310x150Logo.scale-125.png
Binary file modified res/terminal/images-Dev/Wide310x150Logo.scale-150.png
Binary file modified res/terminal/images-Dev/Wide310x150Logo.scale-200.png
Binary file modified res/terminal/images-Dev/Wide310x150Logo.scale-400.png
Binary file added res/terminal/images-Dev/terminal.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added res/terminal/images-Pre/terminal.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added res/terminal/images/terminal_contrast-black.ico
Binary file not shown.
Binary file added res/terminal/images/terminal_contrast-white.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions src/cascadia/WindowsTerminal/IslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "IslandWindow.h"
#include "../types/inc/Viewport.hpp"
#include "resource.h"
#include "icon.h"

extern "C" IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -147,6 +148,8 @@ void IslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) noexce
ShowWindow(_window.get(), nCmdShow);

UpdateWindow(_window.get());

UpdateWindowIconForActiveMetrics(_window.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you also mean to call this from WM_THEMECHANGED ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did, but I chose to defer that until we also get WM_SETTINGSCHANGED.

}

// Method Description:
Expand Down Expand Up @@ -359,6 +362,9 @@ void IslandWindow::OnSize(const UINT width, const UINT height)
return 0;
}
CATCH_LOG();
case WM_THEMECHANGED:
UpdateWindowIconForActiveMetrics(_window.get());
return 0;
}

// TODO: handle messages here...
Expand Down
13 changes: 13 additions & 0 deletions src/cascadia/WindowsTerminal/WindowsTerminal.rc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,20 @@ END

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.

#if defined(WT_BRANDING_RELEASE)
IDI_APPICON ICON "..\\..\\..\\res\\terminal.ico"
IDI_APPICON_HC_BLACK ICON "..\\..\\..\\res\\terminal\\images\\terminal_contrast-black.ico"
IDI_APPICON_HC_WHITE ICON "..\\..\\..\\res\\terminal\\images\\terminal_contrast-white.ico"
#elif defined(WT_BRANDING_PREVIEW)
IDI_APPICON ICON "..\\..\\..\\res\\terminal\\images-Pre\\terminal.ico"
IDI_APPICON_HC_BLACK ICON "..\\..\\..\\res\\terminal\\images-Pre\\terminal_contrast-black.ico"
IDI_APPICON_HC_WHITE ICON "..\\..\\..\\res\\terminal\\images-Pre\\terminal_contrast-white.ico"
#else
IDI_APPICON ICON "..\\..\\..\\res\\terminal\\images-Dev\\terminal.ico"
IDI_APPICON_HC_BLACK ICON "..\\..\\..\\res\\terminal\\images-Dev\\terminal_contrast-black.ico"
IDI_APPICON_HC_WHITE ICON "..\\..\\..\\res\\terminal\\images-Dev\\terminal_contrast-white.ico"
#endif


/////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/WindowsTerminal/WindowsTerminal.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<ClCompile Include="AppHost.cpp" />
<ClCompile Include="IslandWindow.cpp" />
<ClCompile Include="NonClientIslandWindow.cpp" />
<ClCompile Include="icon.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="WindowsTerminal.rc" />
Expand Down
49 changes: 49 additions & 0 deletions src/cascadia/WindowsTerminal/icon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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;
}

void UpdateWindowIconForActiveMetrics(HWND window)
{
auto iconResource{ MAKEINTRESOURCEW(_GetActiveAppIconResource()) };

// 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 largeIcon{ LoadImageW(wil::GetModuleInstanceHandle(), iconResource, IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), LR_SHARED) };
LOG_LAST_ERROR_IF_NULL(largeIcon);

if (smallIcon)
{
SendMessageW(window, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
}
if (largeIcon)
{
SendMessageW(window, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(largeIcon));
}
}
6 changes: 6 additions & 0 deletions src/cascadia/WindowsTerminal/icon.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once

void UpdateWindowIconForActiveMetrics(HWND window);
3 changes: 3 additions & 0 deletions src/cascadia/WindowsTerminal/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// Used by WindowsTerminal.rc
//
#define IDI_APPICON 101
#define IDI_APPICON_HC_BLACK 102
#define IDI_APPICON_HC_WHITE 103

#define IDS_ERROR_DIALOG_TITLE 105
#define IDS_HELP_DIALOG_TITLE 106
#define IDS_ERROR_ARCHITECTURE_FORMAT 110
Expand Down