Skip to content

Commit 012d7bc

Browse files
committed
Feat: New tray-icon that adapts to theme change
1 parent e3f5fba commit 012d7bc

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

src/runner/runner.vcxproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@
123123
<ItemGroup>
124124
<EmbeddedResource Include="Resources.resx" />
125125
</ItemGroup>
126+
<ItemGroup>
127+
<CopyFileToFolders Include="svgs\PowerToysDark.ico">
128+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</DeploymentContent>
129+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</DeploymentContent>
130+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
131+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
132+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(OutDir)\svgs</DestinationFolders>
133+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(OutDir)\svgs</DestinationFolders>
134+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\svgs</DestinationFolders>
135+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\svgs</DestinationFolders>
136+
</CopyFileToFolders>
137+
<CopyFileToFolders Include="svgs\PowerToysWhite.ico">
138+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</DeploymentContent>
139+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</DeploymentContent>
140+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
141+
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
142+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">$(OutDir)\svgs</DestinationFolders>
143+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">$(OutDir)\svgs</DestinationFolders>
144+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)\svgs</DestinationFolders>
145+
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)\svgs</DestinationFolders>
146+
</CopyFileToFolders>
147+
</ItemGroup>
126148
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
127149
<Import Project="..\..\deps\spdlog.props" />
128150
<ImportGroup Label="ExtensionTargets">

src/runner/runner.vcxproj.filters

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
</ItemGroup>
108108
<ItemGroup>
109109
<CopyFileToFolders Include="svgs\icon.ico" />
110+
<CopyFileToFolders Include="svgs\PowerToysDark.ico" />
111+
<CopyFileToFolders Include="svgs\PowerToysWhite.ico" />
110112
</ItemGroup>
111113
<ItemGroup>
112114
<None Include="packages.config" />

src/runner/svgs/PowerToysDark.ico

37 KB
Binary file not shown.

src/runner/svgs/PowerToysWhite.ico

36.9 KB
Binary file not shown.

src/runner/tray_icon.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <common/version/version.h>
1111
#include <common/logger/logger.h>
1212
#include <common/utils/elevation.h>
13+
#include <common/Themes/theme_listener.h>
1314
#include "bug_report.h"
1415

1516
namespace
@@ -36,6 +37,7 @@ namespace
3637
bool double_clicked = false;
3738
POINT tray_icon_click_point;
3839

40+
static ThemeListener theme_listener;
3941
}
4042

4143
// Struct to fill with callback and the data. The window_proc is responsible for cleaning it.
@@ -259,10 +261,29 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam
259261
return DefWindowProc(window, message, wparam, lparam);
260262
}
261263

264+
static HICON get_icon(AppTheme theme)
265+
{
266+
return static_cast<HICON>(LoadImage(NULL,
267+
theme == AppTheme::Dark ?
268+
L"svgs/PowerToysWhite.ico" :
269+
L"svgs/PowerToysDark.ico",
270+
IMAGE_ICON,
271+
0,
272+
0,
273+
LR_LOADFROMFILE | LR_DEFAULTSIZE | LR_SHARED));
274+
}
275+
276+
277+
static void handle_theme_change()
278+
{
279+
tray_icon_data.hIcon = get_icon(theme_listener.AppTheme);
280+
Shell_NotifyIcon(NIM_MODIFY, &tray_icon_data);
281+
}
282+
262283
void start_tray_icon(bool isProcessElevated)
263284
{
264285
auto h_instance = reinterpret_cast<HINSTANCE>(&__ImageBase);
265-
auto icon = LoadIcon(h_instance, MAKEINTRESOURCE(APPICON));
286+
HICON const icon = get_icon(theme_listener.AppTheme);
266287
if (icon)
267288
{
268289
UINT id_tray_icon = 1;
@@ -309,6 +330,7 @@ void start_tray_icon(bool isProcessElevated)
309330
ChangeWindowMessageFilterEx(hwnd, WM_COMMAND, MSGFLT_ALLOW, nullptr);
310331

311332
tray_icon_created = Shell_NotifyIcon(NIM_ADD, &tray_icon_data) == TRUE;
333+
theme_listener.AddChangedHandler(&handle_theme_change);
312334
}
313335
}
314336

0 commit comments

Comments
 (0)