Skip to content

Commit

Permalink
fix PhIsThemeTransparencyEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
DartVanya committed Nov 20, 2024
1 parent 1b8c82a commit 0a6c9bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 10 additions & 9 deletions phlib/delayhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ typedef struct _PHP_THEME_WINDOW_HEADER_CONTEXT
HTHEME ThemeHandle;
BOOLEAN MouseActive;
POINT CursorPos;
HWND ParentWindow;
} PHP_THEME_WINDOW_HEADER_CONTEXT, *PPHP_THEME_WINDOW_HEADER_CONTEXT;

VOID ThemeWindowRenderHeaderControl(
Expand Down Expand Up @@ -955,7 +956,7 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure(
if (!GetClassName(createStruct->hwndParent, windowClassName, RTL_NUMBER_OF(windowClassName)))
windowClassName[0] = UNICODE_NULL;

if (PhEqualStringZ(windowClassName, L"PhTreeNew", FALSE))
if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE))
{
LONG_PTR windowStyle = PhGetWindowStyle(createStruct->hwndParent);

Expand All @@ -972,6 +973,7 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure(
context->ThemeHandle = PhOpenThemeData(WindowHandle, VSCLASS_HEADER, PhGetWindowDpi(WindowHandle));
context->CursorPos.x = LONG_MIN;
context->CursorPos.y = LONG_MIN;
context->ParentWindow = createStruct->hwndParent;
PhSetWindowContext(WindowHandle, LONG_MAX, context);

PhSetControlTheme(WindowHandle, L"DarkMode_ItemsView");
Expand Down Expand Up @@ -1062,7 +1064,7 @@ LRESULT CALLBACK PhHeaderWindowHookProcedure(
case WM_PAINT:
{
// Don't apply header theme for unsupported dialogs: Advanced Security, Digital Signature Details, etc. (Dart Vanya)
if (!PhIsDarkModeAllowedForWindow(GetParent(WindowHandle)))
if (!PhIsDarkModeAllowedForWindow(context->ParentWindow))
{
PhRemoveWindowContext(WindowHandle, LONG_MAX);
if (context->ThemeHandle)
Expand Down Expand Up @@ -2055,12 +2057,6 @@ VOID PhRegisterDetoursHooks(
NTSTATUS status;
PVOID baseAddress;

// For early TaskDialog with PhStartupParameters.ShowOptions
if (!PhThemeWindowBackgroundBrush)
{
PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor);
}

if (baseAddress = PhGetLoaderEntryDllBaseZ(L"user32.dll"))
{
DefaultCreateWindowEx = PhGetDllBaseProcedureAddress(baseAddress, "CreateWindowExW", 0);
Expand Down Expand Up @@ -2140,7 +2136,8 @@ BOOLEAN PhIsThemeTransparencyEnabled(
0
)))
{
themesEnableTransparency = !!PhQueryRegistryUlongZ(keyHandle, L"EnableTransparency");
ULONG enableTransparency = PhQueryRegistryUlongZ(keyHandle, L"EnableTransparency");
themesEnableTransparency = enableTransparency != ULONG_MAX ? !!enableTransparency : FALSE;
NtClose(keyHandle);
}

Expand All @@ -2158,6 +2155,10 @@ VOID PhInitializeSuperclassControls(
if (PhEnableThemeAcrylicSupport)
PhEnableThemeAcrylicSupport = PhIsThemeTransparencyEnabled();

// For early TaskDialog with PhStartupParameters.ShowOptions
if (!PhThemeWindowBackgroundBrush)
PhThemeWindowBackgroundBrush = CreateSolidBrush(PhThemeWindowBackgroundColor);

// If PreferredAppMode is not set, PhShouldAppsUseDarkMode returns current Windows app color mode.
// When app mode set to always dark/light all subsequent calls to PhShouldAppsUseDarkMode always ignore
// the current Windows app color mode and return:
Expand Down
4 changes: 2 additions & 2 deletions phlib/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ VOID PhInitializeWindowTheme(
WCHAR windowClassName[MAX_PATH];
if (!GetClassName(WindowHandle, windowClassName, RTL_NUMBER_OF(windowClassName)))
windowClassName[0] = UNICODE_NULL;
if (PhEqualStringZ(windowClassName, L"PhTreeNew", FALSE) || PhEqualStringZ(windowClassName, WC_LISTVIEW, FALSE))
if (PhEqualStringZ(windowClassName, PH_TREENEW_CLASSNAME, FALSE) || PhEqualStringZ(windowClassName, WC_LISTVIEW, FALSE))
PhAllowDarkModeForWindow(WindowHandle, TRUE); // HACK for dynamically generated plugin tabs
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ VOID PhWindowThemeSetDarkMode(
_In_ BOOLEAN EnableDarkMode
)
{
if (EnableDarkMode && PhEnableThemeSupport) // ShouldAppsUseDarkMode_I()
if (EnableDarkMode && PhEnableThemeSupport) // PhShouldAppsUseDarkMode()
{
PhSetControlTheme(WindowHandle, L"DarkMode_Explorer");
//PhSetControlTheme(WindowHandle, L"DarkMode_ItemsView");
Expand Down

0 comments on commit 0a6c9bc

Please sign in to comment.