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

ExplorerPatcher compatibility #2107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 27 additions & 1 deletion Src/StartMenu/StartMenuDLL/StartMenuDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static SIZE g_TaskbarTextureSize;
static TTaskbarTile g_TaskbarTileH, g_TaskbarTileV;
static RECT g_TaskbarMargins;
int g_CurrentCSMTaskbar=-1, g_CurrentWSMTaskbar=-1;
// ExplorerPatcher taskbar
static bool g_epTaskbar = false;

static void FindWindowsMenu( void );
static void RecreateStartButton( size_t taskbarId );
Expand Down Expand Up @@ -1342,7 +1344,7 @@ static void UpdateStartButtonPosition(const TaskbarInfo* taskBar, const WINDOWPO

// Start button on Win11 is a bit shifted to the right
// We will shift our Aero button to cover original button
if (IsWin11() && (x == info.rcMonitor.left) && (GetStartButtonType() == START_BUTTON_AERO))
if (IsWin11() && (x == info.rcMonitor.left) && (GetStartButtonType() == START_BUTTON_AERO) && !g_epTaskbar)
x += ScaleForDpi(taskBar->taskBar, 6);
}

Expand Down Expand Up @@ -2772,6 +2774,17 @@ static void WINAPI SHFillRectClr2( HDC hdc, const RECT *pRect, COLORREF color )
g_SHFillRectClr(hdc,pRect,color);
}

static IatHookData* g_ExtTextOutWHook = nullptr;

// used by ExplorerPatcher's custom implementation of `SHFillRectClr`
static BOOL WINAPI ExtTextOutW2(HDC hdc, int X, int Y, UINT fuOptions, const RECT* lprc, LPCWSTR lpString, UINT cbCount, const INT* lpDx)
{
if (!g_CurrentTaskList || !g_TaskbarTexture || GetCurrentThreadId() != g_TaskbarThreadId)
return ExtTextOutW(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);

return FALSE;
}

static HRESULT STDAPICALLTYPE DrawThemeBackground2( HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCRECT pRect, LPCRECT pClipRect )
{
if (g_CurrentTaskList && g_TaskbarTexture && iPartId==1 && iStateId==0 && GetCurrentThreadId()==g_TaskbarThreadId)
Expand Down Expand Up @@ -2956,6 +2969,12 @@ static void InitStartMenuDLL( void )
if (GetSettingBool(L"CustomTaskbar"))
{
auto module=GetModuleHandle(L"taskbar.dll");
if (!module)
{
module = GetModuleHandle(L"ep_taskbar.5.dll");

Choose a reason for hiding this comment

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

Perhaps I should come a up with a way so that any program can read which ep_taskbar is active... hardcoding the module name is not a good idea.

There are currently 6 variants of the taskbar, of which variants 0 (10 VB), 2 (11 NI), and 5 (11 GE) are under active use. Hardcoding this to 5 would make it only target the taskbar if it's running under 11 GE/24H2.

https://github.com/valinet/ExplorerPatcher/wiki/ExplorerPatcher's-taskbar-implementation#supported-windows-versions

if (module)
g_epTaskbar = true;
}
if (!module)
module=GetModuleHandle(NULL);

Expand All @@ -2975,6 +2994,10 @@ static void InitStartMenuDLL( void )
g_StretchDIBitsHook=SetIatHook(module,"gdi32.dll","StretchDIBits",StretchDIBits2);
if (!g_StretchDIBitsHook)
g_StretchDIBitsHook=SetIatHook(module,"ext-ms-win-gdi-draw-l1-1-0.dll","StretchDIBits",StretchDIBits2);

// ExplorerPatcher compatibility
if (g_epTaskbar)
g_ExtTextOutWHook = SetIatHook(module, "gdi32.dll", "ExtTextOutW", ExtTextOutW2);
}

{
Expand Down Expand Up @@ -3204,6 +3227,7 @@ static void RecreateStartButton( size_t taskbarId )
{
RECT rc;
GetWindowRect(btn,&rc);
MapWindowPoints(NULL,taskBar.taskBar,(POINT*)&rc,2); // convert to taskbar coordinates
SetWindowPos(btn,HWND_TOP,rc.left,rc.top,0,0,SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER);
}
}
Expand All @@ -3230,6 +3254,8 @@ static void CleanStartMenuDLL( void )
g_SHFillRectClrHook=NULL;
ClearIatHook(g_StretchDIBitsHook);
g_StretchDIBitsHook=NULL;
ClearIatHook(g_ExtTextOutWHook);
g_ExtTextOutWHook = NULL;

ClearIatHook(g_DrawThemeBackgroundHook);
g_DrawThemeBackgroundHook=NULL;
Expand Down