Skip to content

Commit 4295135

Browse files
committed
Set dark color mode for OS-provided context menus
1 parent 02d65b1 commit 4295135

5 files changed

Lines changed: 35 additions & 0 deletions

File tree

LICENSE-3RD-PARTY

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This software is based on the following MIT licensed projects:
1313
- pugixml : Copyright (c) 2006-2023 Arseny Kapoulkine
1414
- ValveFileVDF : Copyright (c) Matthias Moeller 2016 m_moeller@live.de
1515
- HybridDetect : Copyright (c) 2017 Intel
16+
- win32-darkmode : Copyright (c) 2019 Richard Yu
1617

1718
---
1819

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ New versions will probably be distributed through their own packaged installer o
7878
* Uses [HybridDetect](https://github.com/GameTechDev/HybridDetect/), licensed under [MIT](https://github.com/GameTechDev/HybridDetect/blob/main/LICENSE.md).
7979
* Uses [zlib](https://github.com/madler/zlib), licensed under [the zlib license](https://raw.githubusercontent.com/madler/zlib/develop/LICENSE).
8080
* Uses [OpenEXR](https://github.com/AcademySoftwareFoundation/openexr), licensed under [BSD](https://raw.githubusercontent.com/AcademySoftwareFoundation/openexr/main/LICENSE.md).
81+
* Uses code from [win32-darkmode](https://github.com/ysc3839/win32-darkmode/), licensed under [MIT](https://github.com/ysc3839/win32-darkmode/blob/master/LICENSE).
8182
* Optionally uses [libjxl](https://github.com/libjxl/), licensed under [BSD](https://raw.githubusercontent.com/libjxl/libjxl/main/LICENSE).
8283
* Includes various snippets of code from [Stack Overflow](https://stackoverflow.com/), licensed under [Creative Commons Attribution-ShareAlike](https://stackoverflow.com/help/licensing).

include/utility/utility.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ typedef struct _SKIF_MEMORY_PRIORITY_INFORMATION {
179179
ULONG MemoryPriority;
180180
} SKIF_MEMORY_PRIORITY_INFORMATION, *SKIF_PMEMORY_PRIORITY_INFORMATION;
181181

182+
enum class AppColorMode // PreferredAppMode
183+
{
184+
Default,
185+
AllowDark,
186+
ForceDark,
187+
ForceLight,
188+
Max
189+
};
190+
182191
HANDLE SKIF_Util_GetCurrentProcess (void);
183192
HANDLE SKIF_Util_GetCurrentProcessToken (void);
184193
BOOL SKIF_Util_TerminateProcess (DWORD dwProcessId, UINT uExitCode);
@@ -232,6 +241,7 @@ std::wstring SKIF_Util_FileExplorer_BrowseForFolderXP(PCWSTR defaultPath);
232241
std::wstring SKIF_Util_FileExplorer_BrowseForFolder(PCWSTR defaultPath);
233242
bool SKIF_Util_Files_PruneOlderThan (std::wstring path, ULONGLONG secondsSince);
234243
bool SKIF_Util_Files_PruneToLatestN (std::wstring path, size_t filesToRetain);
244+
AppColorMode SKIF_Util_SetAppColorMode (AppColorMode mode);
235245
std::string SKIF_Util_GetWindowMessageAsStr (UINT msg);
236246

237247

src/SKIV.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ wWinMain ( _In_ HINSTANCE hInstance,
12841284
return 0;
12851285
}
12861286

1287+
SKIF_Util_SetAppColorMode (AppColorMode::AllowDark);
1288+
12871289
SKIF_Notify_hWnd =
12881290
CreateWindowExW ( WS_EX_NOACTIVATE,
12891291
wcNotify.lpszClassName, _T("Special K Image Notification Icon"), WS_ICONIC,

src/utility/utility.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,27 @@ SKIF_Util_Files_PruneToLatestN (std::wstring path, size_t filesToRetain)
29762976
return false;
29772977
}
29782978

2979+
// Sets a new app color mode and returns the previous one
2980+
AppColorMode
2981+
SKIF_Util_SetAppColorMode (AppColorMode mode)
2982+
{
2983+
if (! SKIF_Util_IsWindows11orGreater ( ))
2984+
return AppColorMode::Default;
2985+
2986+
using SetAppColorMode_pfn =
2987+
AppColorMode (WINAPI *)(AppColorMode);
2988+
2989+
static SetAppColorMode_pfn
2990+
SetAppColorMode =
2991+
(SetAppColorMode_pfn)GetProcAddress (LoadLibraryEx (L"uxtheme.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32),
2992+
MAKEINTRESOURCEA (135)); // Ordinal 135
2993+
2994+
if (SetAppColorMode == nullptr)
2995+
return AppColorMode::Default;
2996+
2997+
return SetAppColorMode (mode);
2998+
}
2999+
29793000

29803001
#if NTDDI_VERSION < NTDDI_WIN10_RS5
29813002
// Effective Power Mode (Windows 10 1809+)

0 commit comments

Comments
 (0)