Skip to content
Closed
Show file tree
Hide file tree
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
55 changes: 48 additions & 7 deletions Src/StartMenu/StartMenuDLL/StartMenuDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ResourceHelper.h"
#include "LogManager.h"
#include "TouchHelper.h"
#include "Win11StartButton.h"
#include "IatHookHelper.h"
#include "dllmain.h"
#include <uxtheme.h>
Expand Down Expand Up @@ -1315,7 +1316,11 @@ static void UpdateStartButtonPosition(const TaskbarInfo* taskBar, const WINDOWPO
}
}

RECT rcOldButton;
RECT rcNativeStart = {};
const bool hasNativeStartRect = IsWin11() &&
GetWin11StartButtonRect(taskBar->taskBar, &rcNativeStart);

RECT rcOldButton = {};
if (taskBar->oldButton)
GetWindowRect(taskBar->oldButton, &rcOldButton);

Expand All @@ -1328,25 +1333,44 @@ static void UpdateStartButtonPosition(const TaskbarInfo* taskBar, const WINDOWPO
x = rcTask.left;
else
x = rcTask.right - taskBar->startButtonSize.cx;
y = taskBar->oldButton ? rcOldButton.top : rcTask.top;

if (hasNativeStartRect)
y = (rcNativeStart.top + rcNativeStart.bottom - taskBar->startButtonSize.cy) / 2;
else
y = taskBar->oldButton ? rcOldButton.top : rcTask.top;
}
else
{
if (GetWindowLongPtr(taskBar->rebar, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
// Windows 11's Start button is a XAML control. Its old "Start" HWND is
// not a reliable layout anchor on centered taskbars, high DPI, or newer
// taskbar implementations. Center the replacement over the verified
// AutomationId=StartButton rectangle instead.
if (hasNativeStartRect)
x = (rcNativeStart.left + rcNativeStart.right - taskBar->startButtonSize.cx) / 2;
else if (GetWindowLongPtr(taskBar->rebar, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
x = (taskBar->oldButton ? rcOldButton.right : rcTask.right) - taskBar->startButtonSize.cx;
else
x = taskBar->oldButton ? rcOldButton.left : rcTask.left;

if (GetSettingInt(L"StartButtonType") != START_BUTTON_CUSTOM || !GetSettingBool(L"StartButtonAlign"))
y = (rcTask.top + rcTask.bottom - taskBar->startButtonSize.cy) / 2;
{
if (hasNativeStartRect)
y = (rcNativeStart.top + rcNativeStart.bottom - taskBar->startButtonSize.cy) / 2;
else
y = (rcTask.top + rcTask.bottom - taskBar->startButtonSize.cy) / 2;
}
else if (uEdge == ABE_TOP)
y = rcTask.top;
else
y = rcTask.bottom - taskBar->startButtonSize.cy;

// 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) && !g_epTaskbar)
// Keep the legacy Win11 offset only when the actual XAML Start rectangle
// is unavailable. Applying both would double-correct the position.
if (!hasNativeStartRect && IsWin11() && (x == info.rcMonitor.left) &&
(GetStartButtonType() == START_BUTTON_AERO) && !g_epTaskbar)
{
x += ScaleForDpi(taskBar->taskBar, 6);
}

if (GetStartButtonType() == START_BUTTON_CUSTOM)
x += ScaleForDpi(taskBar->taskBar, GetSettingInt(L"StartButtonOffset"));
Expand Down Expand Up @@ -1845,8 +1869,21 @@ static LRESULT CALLBACK SubclassTaskBarProc( HWND hWnd, UINT uMsg, WPARAM wParam
pPos->hwndInsertAfter=taskBar->startButton;
}
}
if (uMsg==WM_OS_STARTBUTTON_RECT_READY && taskBar)
{
if (taskBar->bReplaceButton)
{
WINDOWPOS pos = {};
pos.flags = SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE;
UpdateStartButtonPosition(taskBar, &pos);
}
return 0;
}
if (uMsg==WM_WINDOWPOSCHANGED && taskBar)
{
if (IsWin11())
RefreshWin11StartButtonRects();

if (taskBar->bReplaceButton)
{
UpdateStartButtonPosition(taskBar,(WINDOWPOS*)lParam);
Expand Down Expand Up @@ -2643,6 +2680,7 @@ void UpdateTaskBars( TUpdateTaskbar update )
InvalidateRect(taskBar.taskBar,NULL,TRUE);
PostMessage(taskBar.taskBar,WM_THEMECHANGED,0,0);
}
UpdateWin11StartButtonMonitor();
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3227,6 +3265,7 @@ if (!g_bTrimHooks)

UpdateTaskBars(TASKBAR_RECREATE_BUTTONS);
UpdateTaskBars(TASKBAR_UPDATE_TEXTURE);
StartWin11StartButtonMonitor();
}

static void RecreateStartButton( size_t taskbarId )
Expand Down Expand Up @@ -3288,6 +3327,8 @@ static DWORD WINAPI ExitThreadProc( void *param )

static void CleanStartMenuDLL( void )
{
StopWin11StartButtonMonitor();

ClearIatHook(g_DwmpBTRHook);
g_DwmpBTRHook=NULL;
ClearIatHook(g_DwmpTWWRHook);
Expand Down
2 changes: 2 additions & 0 deletions Src/StartMenu/StartMenuDLL/StartMenuDLL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TouchHelper.cpp" />
<ClCompile Include="Win11StartButton.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Accessibility.h" />
Expand All @@ -110,6 +111,7 @@
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="TouchHelper.h" />
<ClInclude Include="Win11StartButton.h" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\Setup\OpenShell.ico" />
Expand Down
6 changes: 6 additions & 0 deletions Src/StartMenu/StartMenuDLL/StartMenuDLL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<ClCompile Include="TouchHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Win11StartButton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Accessibility.h">
Expand Down Expand Up @@ -128,6 +131,9 @@
<ClInclude Include="TouchHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Win11StartButton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Resource Files</Filter>
</ClInclude>
Expand Down
Loading