Skip to content

Commit 2610fbe

Browse files
committed
Start button always on the left v1.3.1
* Improve search menu handling when the "Start menu on the left" option is enabled - search menu is no longer affected when opened outside of the start menu (Win+S or taskbar search button).
1 parent 9124167 commit 2610fbe

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

mods/taskbar-start-button-position.wh.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @id taskbar-start-button-position
33
// @name Start button always on the left
44
// @description Forces the Start button to be on the left of the taskbar, even when taskbar icons are centered, with an option to also move the search and task view buttons (Windows 11 only)
5-
// @version 1.3
5+
// @version 1.3.1
66
// @author m417z
77
// @github https://github.com/m417z
88
// @twitter https://twitter.com/m417z
@@ -33,10 +33,10 @@ keeping only the app icons centered.
3333
3434
Only Windows 11 is supported.
3535
36-
![Screenshot](https://i.imgur.com/MSKYKbE.png)
36+
![Screenshot](https://i.imgur.com/MSKYKbE.png) \
3737
_Start button on the left_
3838
39-
![Screenshot](https://i.imgur.com/SOdWH1P.png)
39+
![Screenshot](https://i.imgur.com/SOdWH1P.png) \
4040
_Start button, search and task view buttons on the left_
4141
*/
4242
// ==/WindhawkModReadme==
@@ -104,6 +104,7 @@ thread_local bool g_inShowStartButtonContextMenu;
104104

105105
HWND g_searchMenuWnd;
106106
int g_searchMenuOriginalX;
107+
HMONITOR g_searchMenuMonitor;
107108

108109
HWND FindCurrentProcessTaskbarWnd() {
109110
HWND hTaskbarWnd = nullptr;
@@ -1089,11 +1090,8 @@ HRESULT WINAPI DwmSetWindowAttribute_Hook(HWND hwnd,
10891090
}
10901091

10911092
BOOL cloak = *(BOOL*)pvAttribute;
1092-
if (cloak) {
1093-
return original();
1094-
}
10951093

1096-
Wh_Log(L"> %08X", (DWORD)(DWORD_PTR)hwnd);
1094+
Wh_Log(L"> %08X %s", (DWORD)(DWORD_PTR)hwnd, cloak ? L"cloak" : L"uncloak");
10971095

10981096
DWORD processId = 0;
10991097
if (!hwnd || !GetWindowThreadProcessId(hwnd, &processId)) {
@@ -1131,19 +1129,10 @@ HRESULT WINAPI DwmSetWindowAttribute_Hook(HWND hwnd,
11311129
int cy = targetRect.bottom - targetRect.top;
11321130

11331131
if (target == DwmTarget::SearchHost) {
1134-
if (!IsStartMenuOpen()) {
1135-
// Win+S or the search bar on the taskbar cause the search menu to
1136-
// be repositioned. Don't customize it and restore the original
1137-
// position.
1138-
g_searchMenuWnd = nullptr;
1139-
g_searchMenuOriginalX = 0;
1140-
return original();
1141-
}
1142-
11431132
// Only change x.
11441133
int xNew;
11451134

1146-
if (g_settings.startMenuOnTheLeft) {
1135+
if (g_settings.startMenuOnTheLeft && !cloak && IsStartMenuOpen()) {
11471136
// Not centered or already changed.
11481137
if (x == monitorInfo.rcWork.left) {
11491138
return original();
@@ -1152,20 +1141,30 @@ HRESULT WINAPI DwmSetWindowAttribute_Hook(HWND hwnd,
11521141
xNew = monitorInfo.rcWork.left;
11531142
g_searchMenuWnd = hwnd;
11541143
g_searchMenuOriginalX = x;
1144+
g_searchMenuMonitor = monitor;
11551145
} else {
11561146
if (!g_searchMenuOriginalX) {
11571147
return original();
11581148
}
11591149

11601150
xNew = g_searchMenuOriginalX;
1151+
bool monitorMatches = monitor == g_searchMenuMonitor;
1152+
11611153
g_searchMenuWnd = nullptr;
11621154
g_searchMenuOriginalX = 0;
1155+
g_searchMenuMonitor = nullptr;
1156+
1157+
if (!monitorMatches) {
1158+
return original();
1159+
}
11631160
}
11641161

11651162
if (xNew == x) {
11661163
return original();
11671164
}
11681165

1166+
Wh_Log(L"Adjusting search menu: %d -> %d", x, xNew);
1167+
11691168
x = xNew;
11701169
}
11711170

@@ -1462,8 +1461,14 @@ HRESULT WINAPI RoGetActivationFactory_Hook(HSTRING activatableClassId,
14621461

14631462
void RestoreMenuPositions() {
14641463
if (g_searchMenuWnd && g_searchMenuOriginalX) {
1464+
HMONITOR monitor =
1465+
MonitorFromWindow(g_searchMenuWnd, MONITOR_DEFAULTTONEAREST);
1466+
14651467
RECT rect;
1466-
if (GetWindowRect(g_searchMenuWnd, &rect)) {
1468+
// The saved position is an absolute coordinate, valid only on the
1469+
// monitor where it was recorded.
1470+
if (monitor == g_searchMenuMonitor &&
1471+
GetWindowRect(g_searchMenuWnd, &rect)) {
14671472
int x = rect.left;
14681473
int y = rect.top;
14691474
int cx = rect.right - rect.left;
@@ -1478,6 +1483,7 @@ void RestoreMenuPositions() {
14781483

14791484
g_searchMenuWnd = nullptr;
14801485
g_searchMenuOriginalX = 0;
1486+
g_searchMenuMonitor = nullptr;
14811487
}
14821488
}
14831489

0 commit comments

Comments
 (0)