Skip to content

Commit

Permalink
PhReInitializeTheme: runtime theme switching on ImmersiveColorSet mes…
Browse files Browse the repository at this point in the history
…sage

- Theme can be changed at runtime w/o restart by EnableThemeSupport and EnableThemeUseWindowsTheme. All PH/PV windows and dialogs will be redrawed automatically.
- If EnableThemeUseWindowsTheme enabled theme will be switched automatically when Windows theme is changing.
- Streamer mode, acrylic, theme custom colors settings are applied immediately on all windows w/o restart.
- TreeNew: fix custom ForeColor for dark mode.
  • Loading branch information
DartVanya committed Nov 22, 2024
1 parent b297c03 commit 505b71b
Show file tree
Hide file tree
Showing 31 changed files with 2,026 additions and 1,775 deletions.
3 changes: 2 additions & 1 deletion SystemInformer/SystemInformer.def
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ EXPORTS
PhRegisterWindowCallback @1831 NONAME
PhUnregisterWindowCallback @1832 NONAME
PhInitializeWindowTheme @1833 NONAME
PhReInitializeWindowTheme @1834 NONAME
PhReInitializeTheme @1834 NONAME
PhImageListCreate @1835 NONAME
PhImageListDestroy @1836 NONAME
PhImageListSetIconSize @1837 NONAME
Expand All @@ -904,6 +904,7 @@ EXPORTS
PhThemeWindowDrawRebar @1847 NONAME
PhThemeWindowDrawToolbar @1848 NONAME
PhWindowThemeControlColor @1849 NONAME
PhReInitializeStreamerMode @2062 NONAME

; hndlinfo
PhEnumObjectTypes @1850 NONAME
Expand Down
4 changes: 1 addition & 3 deletions SystemInformer/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3840,8 +3840,6 @@ HRESULT CALLBACK PhpUiServiceInitializeDialogCallbackProc(
PhSetWindowProcedure(WindowHandle, PhpUiServiceProgressDialogWndProc);

PhShowServiceProgressDialogConfirmMessage(context);

PhInitializeWindowTheme(WindowHandle, PhEnableThemeSupport);
}
break;
}
Expand Down Expand Up @@ -5855,7 +5853,7 @@ BOOLEAN PhUiFreeMemory(
static BOOLEAN PhpShowErrorHandle(
_In_ HWND WindowHandle,
_In_ PCWSTR Verb,
_In_ PCWSTR Verb2,
_In_opt_ PCWSTR Verb2,
_In_ PPH_HANDLE_ITEM Handle,
_In_ NTSTATUS Status,
_In_opt_ ULONG Win32Result
Expand Down
25 changes: 24 additions & 1 deletion SystemInformer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ VOID PhpInitializeSettings(
for (ULONG i = 0; i < PhMaxPrecisionUnit; i++)
PhMaxPrecisionLimit /= 10;
PhEnableWindowText = !!PhGetIntegerSetting(L"EnableWindowText");
PhEnableThemeSupport = PhIsThemeSupportEnabled();
PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode");
PhThemeWindowForegroundColor = PhGetIntegerSetting(L"ThemeWindowForegroundColor");
PhThemeWindowBackgroundColor = PhGetIntegerSetting(L"ThemeWindowBackgroundColor");
PhThemeWindowBackground2Color = PhGetIntegerSetting(L"ThemeWindowBackground2Color");
Expand All @@ -1203,7 +1203,9 @@ VOID PhpInitializeSettings(
PhThemeWindowTextColor = PhGetIntegerSetting(L"ThemeWindowTextColor");
PhEnableThemeAcrylicSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicSupport");
PhEnableThemeAcrylicWindowSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport");
PhEnableThemeAnimation = !!PhGetIntegerSetting(L"EnableThemeAnimation");
PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons");
PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders");
PhEnableThemeListviewBorder = !!PhGetIntegerSetting(L"TreeListBorderEnable");
PhEnableDeferredLayout = !!PhGetIntegerSetting(L"EnableDeferredLayout");
PhEnableServiceNonPoll = !!PhGetIntegerSetting(L"EnableServiceNonPoll");
Expand All @@ -1212,6 +1214,27 @@ VOID PhpInitializeSettings(
PhEnableKsiSupport = !!PhGetIntegerSetting(L"KsiEnable") && !PhStartupParameters.NoKph && !PhIsExecutingInWow64();
PhEnableKsiWarnings = !!PhGetIntegerSetting(L"KsiEnableWarnings");

if (!PhThemeWindowBackgroundBrush)
PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor);

// If AppMode is set to PreferredAppModeDarkOnDark, PhShouldAppsUseDarkMode should return current Windows app color mode.
// It's weird that sometimes it can return incorrect inverted value (idk why).
// In this case use PhGetAppsUseLightTheme() to retrieve raw value from registry.
//
// When app mode set to always dark/light all subsequent calls to PhShouldAppsUseDarkMode always ignore
// the current Windows app color mode. Possible return values are:
//
// ---PreferredAppMode--- | ---PhShouldAppsUseDarkMode()---
// -------------------------------|----------------------------------
// PreferredAppModeDisabled | Windows app color mode ?
// PreferredAppModeDarkOnDark | Windows app color mode
// PreferredAppModeDarkAlways | always return TRUE
// PreferredAppModeLightAlways | always return FALSE

PH_THEME_SET_PREFFEREDAPPMODE(L"EnableThemeSupport", L"EnableThemeUseWindowsTheme");

PhEnableThemeSupport = PH_THEME_GET_GENERAL_SWITCH(L"EnableThemeSupport");

if (PhGetIntegerSetting(L"SampleCountAutomatic"))
{
ULONG sampleCount;
Expand Down
39 changes: 31 additions & 8 deletions SystemInformer/mainwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ BOOLEAN PhMainWndInitialization(
// Initialize window settings.
PhMwpLoadSettings(PhMainWndHandle);

// Initialize window theme.
PhInitializeWindowTheme(PhMainWndHandle, PhEnableThemeSupport);

// Initialize window menu.
PhMwpInitializeMainMenu(PhMainWndHandle);

// Initialize window theme.
PhInitializeWindowTheme(PhMainWndHandle, PhEnableThemeSupport);

// Initialize providers.
PhMwpInitializeProviders();

Expand Down Expand Up @@ -634,6 +634,29 @@ VOID PhMwpOnEndSession(
PhExitApplication(STATUS_SUCCESS);
}

static NTSTATUS PhMwpReInitializeThemeThread(
_In_ PVOID Context
)
{
BOOLEAN currentTheme;

//currentTheme = PhShouldAppsUseDarkMode();
currentTheme = PhGetAppsUseLightTheme();

dprintf("PhMwpPhReInitializeThemeThread: currentTheme = %d, PhEnableThemeSupport = %d\r\n", currentTheme, PhEnableThemeSupport);

if (PhEnableThemeSupport != currentTheme)
{
PhEnableThemeSupport = currentTheme;

PhReInitializeTheme(PhEnableThemeSupport);

PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSettingsUpdated), NULL);
};

return STATUS_SUCCESS;
}

VOID PhMwpOnSettingChange(
_In_ HWND WindowHandle,
_In_opt_ ULONG Action,
Expand Down Expand Up @@ -661,10 +684,11 @@ VOID PhMwpOnSettingChange(

// Reload dark theme metrics

//if (PhEqualStringZ(Metric, L"ImmersiveColorSet", TRUE))
//{
// NOTHING;
//}
// Implemented (Dart Vanya)
if (HANDLE_COLORSCHEMECHANGE_MESSAGE(Action, Metric, L"EnableThemeSupport", L"EnableThemeUseWindowsTheme"))
{
PhCreateThread2(PhMwpReInitializeThemeThread, NULL);
}
}

//if (Action == SPI_SETNONCLIENTMETRICS && Metric && PhEqualStringZ(Metric, L"WindowMetrics", TRUE))
Expand Down Expand Up @@ -2986,7 +3010,6 @@ VOID PhMwpInitializeMainMenu(
return;

PhEMenuToHMenu2(menuHandle, PhpCreateMainMenu(ULONG_MAX), 0, NULL);
PhInitializeWindowThemeMainMenu(menuHandle);
PhSetHMenuNotify(menuHandle);
SetMenu(WindowHandle, menuHandle);

Expand Down
47 changes: 43 additions & 4 deletions SystemInformer/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,46 @@ static VOID PhpOptionsNotifyChangeCallback(
PhReloadSettingsProcessTreeList();
PhSiNotifyChangeSettings();

//PhReInitializeWindowTheme(PhMainWndHandle);
PhThemeWindowForegroundColor = PhGetIntegerSetting(L"ThemeWindowForegroundColor");
COLORREF oldPhThemeWindowBackgroundColor = PhThemeWindowBackgroundColor;
PhThemeWindowBackgroundColor = PhGetIntegerSetting(L"ThemeWindowBackgroundColor");
PhThemeWindowBackground2Color = PhGetIntegerSetting(L"ThemeWindowBackground2Color");
PhThemeWindowHighlightColor = PhGetIntegerSetting(L"ThemeWindowHighlightColor");
PhThemeWindowHighlight2Color = PhGetIntegerSetting(L"ThemeWindowHighlight2Color");
PhThemeWindowTextColor = PhGetIntegerSetting(L"ThemeWindowTextColor");
PhEnableThemeNativeButtons = !!PhGetIntegerSetting(L"EnableThemeNativeButtons");
PhEnableThemeTabBorders = !!PhGetIntegerSetting(L"EnableThemeTabBorders");
PhEnableThemeAcrylicSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicSupport");
BOOLEAN oldAcrylicWindowSupport = PhEnableThemeAcrylicWindowSupport;
PhEnableThemeAcrylicWindowSupport = WindowsVersion >= WINDOWS_11 && !!PhGetIntegerSetting(L"EnableThemeAcrylicWindowSupport");
BOOLEAN oldStreamerMode = PhEnableStreamerMode;
PhEnableStreamerMode = !!PhGetIntegerSetting(L"EnableStreamerMode");

PH_THEME_SET_PREFFEREDAPPMODE(L"EnableThemeSupport", L"EnableThemeUseWindowsTheme");

BOOLEAN oldTheme = PhEnableThemeSupport;
PhEnableThemeSupport = PH_THEME_GET_GENERAL_SWITCH(L"EnableThemeSupport");

if (oldPhThemeWindowBackgroundColor != PhThemeWindowBackgroundColor && PhThemeWindowBackgroundBrush)
{
DeleteBrush(PhThemeWindowBackgroundBrush);
PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor);

if (PhEnableThemeSupport) // replace old destroyed menu brush with the new one
{
PhInitializeWindowThemeMenu(PhMainWndHandle, TRUE);
}
}

if (PhEnableThemeSupport != oldTheme || PhEnableThemeAcrylicWindowSupport != oldAcrylicWindowSupport)
{
PhReInitializeTheme(PhEnableThemeSupport);
}

if (PhEnableStreamerMode != oldStreamerMode)
{
PhReInitializeStreamerMode(PhEnableStreamerMode);
}

PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackSettingsUpdated), NULL);

Expand Down Expand Up @@ -1677,10 +1716,10 @@ static VOID PhpAdvancedPageSave(
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_COLUMN_HEADER_TOTALS, L"TreeListEnableHeaderTotals");
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_GRAPH_SCALING, L"EnableGraphMaxScale");
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_CYCLE_CPU_USAGE, L"EnableCycleCpuUsage");
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport");
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_SUPPORT, L"EnableThemeSupport");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_THEME_WINDOWS_THEME, L"EnableThemeUseWindowsTheme");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_START_ASADMIN, L"EnableStartAsAdmin");
SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_STREAM_MODE, L"EnableStreamerMode");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_SILENT_CRASH_NOTIFY, L"EnableSilentCrashNotify");
SetSettingForLvItemCheck(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_MONOSPACE, L"EnableMonospaceFont");
//SetSettingForLvItemCheckRestartRequired(listViewHandle, PHP_OPTIONS_INDEX_ENABLE_LINUX_SUPPORT, L"EnableLinuxSubsystemSupport");
Expand Down
12 changes: 8 additions & 4 deletions SystemInformer/searchbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ VOID PhCreateSearchControl(
ParentWindowHandle,
WindowHandle,
BannerText,
PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK),
PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK),
PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK),
PhEnableThemeSupport ? MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT) : MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK),
MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_LIGHT),
MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_LIGHT),
MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_LIGHT),
MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_LIGHT),
MAKEINTRESOURCE(IDB_SEARCH_INACTIVE_MODERN_DARK),
MAKEINTRESOURCE(IDB_SEARCH_ACTIVE_MODERN_DARK),
MAKEINTRESOURCE(IDB_SEARCH_REGEX_MODERN_DARK),
MAKEINTRESOURCE(IDB_SEARCH_CASE_MODERN_DARK),
L"SearchControlRegex",
L"SearchControlCaseSensitive",
Callback,
Expand Down
Loading

0 comments on commit 505b71b

Please sign in to comment.