Skip to content

Commit 44b84e9

Browse files
committed
Win+X positioning improvements; fixes #31
1 parent a94c034 commit 44b84e9

File tree

6 files changed

+125
-51
lines changed

6 files changed

+125
-51
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub.
44

5+
## 22000.194.0.23
6+
7+
Tested on build: 22000.194.
8+
9+
* Fixed a bug that showed`Win`+`X` on the wrong monitor in certain scenarios
10+
* `Win`+`X` shows in Windows 11 fashion (centered, above the Start button) if using a centered taskbar with centered Start button as well (using a program like [TaskbarX](https://github.com/valinet/TaskbarX))
11+
* Fixed the bug that prevented the application from loading in`StartMenuExperienceHost.exe` (thanks to @BraINstinct0 for the report)
12+
* Fixed padding and element sizes in GUI so it better fits on smaller screens (thanks to @Gaurav-Original-ClassicShellTester for the report)
13+
* GUI shows application title when run outside of File Explorer
14+
* GUI stays on screen and just reloads the settings when restoring defaults (instead of closing)
15+
* Keyboard (tab) support for GUI: `Esc` to close the window, `Tab` to select the next option, `Shift`+`Tab` to select the previous option, `Space` to toggle (or activate) the option
16+
* Possibility of running the GUI standalone; run this command: `rundll32.exe C:\Windows\dxgi.dll,ZZGUI`; this has the advantage that it stays on the screen after restarting File Explorer
17+
518
## 22000.194.0.22
619

720
Tested on build: 22000.194.
@@ -12,7 +25,7 @@ Tested on build: 22000.194.
1225

1326
Tested on build: 22000.194.
1427

15-
* Implemented configuration GUI; to access it, right click the Start button (or press `Win`+`X`) and choose "Properties"
28+
* Implemented configuration GUI; to access it, right click the Start button (or press `Win`+`X`) and choose "Properties" (thanks to @BraINstinct0 for the suggestion)
1629

1730
## 22000.194.0.20
1831

ExplorerPatcher/ExplorerPatcher.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ END
5151
//
5252

5353
VS_VERSION_INFO VERSIONINFO
54-
FILEVERSION 22000,194,0,22
55-
PRODUCTVERSION 22000,194,0,22
54+
FILEVERSION 22000,194,0,23
55+
PRODUCTVERSION 22000,194,0,23
5656
FILEFLAGSMASK 0x3fL
5757
#ifdef _DEBUG
5858
FILEFLAGS 0x1L
@@ -69,12 +69,12 @@ BEGIN
6969
BEGIN
7070
VALUE "CompanyName", "VALINET Solutions SRL"
7171
VALUE "FileDescription", "ExplorerPatcher"
72-
VALUE "FileVersion", "22000.194.0.22"
72+
VALUE "FileVersion", "22000.194.0.23"
7373
VALUE "InternalName", "ExplorerPatcher.dll"
7474
VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved."
7575
VALUE "OriginalFilename", "ExplorerPatcher.dll"
7676
VALUE "ProductName", "ExplorerPatcher"
77-
VALUE "ProductVersion", "22000.194.0.22"
77+
VALUE "ProductVersion", "22000.194.0.23"
7878
END
7979
END
8080
BLOCK "VarFileInfo"

ExplorerPatcher/dllmain.c

Lines changed: 59 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ typedef struct
208208
void* _this;
209209
POINT point;
210210
IUnknown* iunk;
211+
BOOL bShouldCenterWinXHorizontally;
211212
} ShowLauncherTipContextMenuParameters;
212213
HWND hWinXWnd;
213214
DWORD ShowLauncherTipContextMenu(
@@ -287,7 +288,7 @@ DWORD ShowLauncherTipContextMenu(
287288

288289
BOOL res = TrackPopupMenu(
289290
*((HMENU*)((char*)params->_this + 0xe8)),
290-
TPM_RETURNCMD | TPM_RIGHTBUTTON,
291+
TPM_RETURNCMD | TPM_RIGHTBUTTON | (params->bShouldCenterWinXHorizontally ? TPM_CENTERALIGN : 0),
291292
params->point.x,
292293
params->point.y,
293294
0,
@@ -355,59 +356,83 @@ INT64 CLauncherTipContextMenu_ShowLauncherTipContextMenuHook(
355356
goto finalize;
356357
}
357358

359+
BOOL bShouldCenterWinXHorizontally = FALSE;
358360
POINT point;
359361
if (pt)
360362
{
361363
point = *pt;
362364
BOOL bBottom, bRight;
363-
POINT dPt = GetDefaultWinXPosition(FALSE, &bBottom, &bRight);
365+
POINT dPt = GetDefaultWinXPosition(FALSE, &bBottom, &bRight, FALSE);
364366
if (bBottom)
365367
{
366368
HMONITOR hMonitor = MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY);
367369
MONITORINFO mi;
368370
mi.cbSize = sizeof(MONITORINFO);
369371
GetMonitorInfo(hMonitor, &mi);
370-
UINT dpiX, dpiY;
371-
HRESULT hr = GetDpiForMonitor(
372-
hMonitor,
373-
MDT_DEFAULT,
374-
&dpiX,
375-
&dpiY
376-
);
377-
double dx = dpiX / 96.0, dy = dpiY / 96.0;
378-
BOOL xo = FALSE, yo = FALSE;
379-
if (point.x - WINX_ADJUST_X * dx < mi.rcMonitor.left)
380-
{
381-
xo = TRUE;
382-
}
383-
if (point.y + WINX_ADJUST_Y * dy > mi.rcMonitor.bottom)
372+
HWND hWndUnder = WindowFromPoint(*pt);
373+
TCHAR wszClassName[100];
374+
GetClassNameW(hWndUnder, wszClassName, 100);
375+
if (!wcscmp(wszClassName, L"Shell_TrayWnd") || !wcscmp(wszClassName, L"Shell_SecondaryTrayWnd"))
384376
{
385-
yo = TRUE;
386-
}
387-
POINT ptCursor;
388-
GetCursorPos(&ptCursor);
389-
if (xo)
390-
{
391-
ptCursor.x += (WINX_ADJUST_X * 2) * dx;
392-
}
393-
else
394-
{
395-
point.x -= WINX_ADJUST_X * dx;
377+
hWndUnder = FindWindowEx(
378+
hWndUnder,
379+
NULL,
380+
L"Start",
381+
NULL
382+
);
396383
}
397-
if (yo)
384+
RECT rcUnder;
385+
GetWindowRect(hWndUnder, &rcUnder);
386+
if (mi.rcMonitor.left != rcUnder.left)
398387
{
399-
ptCursor.y -= (WINX_ADJUST_Y * 2) * dy;
388+
bShouldCenterWinXHorizontally = TRUE;
389+
point.x = rcUnder.left + (rcUnder.right - rcUnder.left) / 2;
390+
point.y = rcUnder.top;
400391
}
401392
else
402393
{
403-
point.y += WINX_ADJUST_Y * dy;
394+
UINT dpiX, dpiY;
395+
HRESULT hr = GetDpiForMonitor(
396+
hMonitor,
397+
MDT_DEFAULT,
398+
&dpiX,
399+
&dpiY
400+
);
401+
double dx = dpiX / 96.0, dy = dpiY / 96.0;
402+
BOOL xo = FALSE, yo = FALSE;
403+
if (point.x - WINX_ADJUST_X * dx < mi.rcMonitor.left)
404+
{
405+
xo = TRUE;
406+
}
407+
if (point.y + WINX_ADJUST_Y * dy > mi.rcMonitor.bottom)
408+
{
409+
yo = TRUE;
410+
}
411+
POINT ptCursor;
412+
GetCursorPos(&ptCursor);
413+
if (xo)
414+
{
415+
ptCursor.x += (WINX_ADJUST_X * 2) * dx;
416+
}
417+
else
418+
{
419+
point.x -= WINX_ADJUST_X * dx;
420+
}
421+
if (yo)
422+
{
423+
ptCursor.y -= (WINX_ADJUST_Y * 2) * dy;
424+
}
425+
else
426+
{
427+
point.y += WINX_ADJUST_Y * dy;
428+
}
429+
SetCursorPos(ptCursor.x, ptCursor.y);
404430
}
405-
SetCursorPos(ptCursor.x, ptCursor.y);
406431
}
407432
}
408433
else
409434
{
410-
point = GetDefaultWinXPosition(FALSE, NULL, NULL);
435+
point = GetDefaultWinXPosition(FALSE, NULL, NULL, TRUE);
411436
}
412437

413438
IUnknown* iunk;
@@ -424,6 +449,7 @@ INT64 CLauncherTipContextMenu_ShowLauncherTipContextMenuHook(
424449
params->_this = _this;
425450
params->point = point;
426451
params->iunk = iunk;
452+
params->bShouldCenterWinXHorizontally = bShouldCenterWinXHorizontally;
427453
hIsWinXShown = CreateThread(
428454
0,
429455
0,
@@ -1004,7 +1030,7 @@ LRESULT explorer_SendMessageW(HWND hWndx, UINT uMsg, WPARAM wParam, LPARAM lPara
10041030
);
10051031
if (hWnd)
10061032
{
1007-
POINT pt = GetDefaultWinXPosition(FALSE, NULL, NULL);
1033+
POINT pt = GetDefaultWinXPosition(FALSE, NULL, NULL, TRUE);
10081034
PostMessage(
10091035
hWnd,
10101036
WM_CONTEXTMENU,

ExplorerPatcher/utility.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ __declspec(dllexport) CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hIns
264264
ZZLaunchExplorer(hWnd, hInstance, lpszCmdLine, nCmdShow);
265265
}
266266

267-
POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
267+
POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOOL bAdjust)
268268
{
269269
if (lpBottom) *lpBottom = FALSE;
270270
if (lpRight) *lpRight = FALSE;
@@ -294,6 +294,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
294294
{
295295
point.x = mi.rcMonitor.left;
296296
}
297+
if (bAdjust)
298+
{
299+
point.x++;
300+
}
297301
if (rc.top - mi.rcMonitor.top == 0)
298302
{
299303
if (bUseRcWork)
@@ -304,6 +308,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
304308
{
305309
point.y = mi.rcMonitor.top;
306310
}
311+
if (bAdjust)
312+
{
313+
point.y++;
314+
}
307315
}
308316
else
309317
{
@@ -316,6 +324,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
316324
{
317325
point.y = mi.rcMonitor.bottom;
318326
}
327+
if (bAdjust)
328+
{
329+
point.y--;
330+
}
319331
}
320332
}
321333
else
@@ -329,6 +341,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
329341
{
330342
point.x = mi.rcMonitor.right;
331343
}
344+
if (bAdjust)
345+
{
346+
point.x--;
347+
}
332348
if (rc.top - mi.rcMonitor.top == 0)
333349
{
334350
if (bUseRcWork)
@@ -339,6 +355,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
339355
{
340356
point.y = mi.rcMonitor.top;
341357
}
358+
if (bAdjust)
359+
{
360+
point.y++;
361+
}
342362
}
343363
else
344364
{
@@ -351,6 +371,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight)
351371
{
352372
point.y = mi.rcMonitor.bottom;
353373
}
374+
if (bAdjust)
375+
{
376+
point.y--;
377+
}
354378
}
355379
}
356380
}

ExplorerPatcher/utility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ __declspec(dllexport) CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance,
4444

4545
__declspec(dllexport) CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow);
4646

47-
POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight);
47+
POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOOL bAdjust);
4848

4949
void QueryVersionInfo(HMODULE hModule, WORD Resource, DWORD*, DWORD*, DWORD*, DWORD*);
5050
#endif

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Now, the classic taskbar should be enabled. Still, there is some more setup to d
3939

4040
## Configuration interface
4141

42-
To configure the most common options, the application now comes with a configuration user interface. To open it, right click the Start button (or press `Win`+`X`) and choose "Properties".
42+
To configure the most common options, the application now comes with a configuration user interface. To open it, right click the Start button (or press `Win`+`X`) and choose "Properties". Alternatively, to open the GUI standalone, run the following command: `rundll32.exe C:\Windows\dxgi.dll,ZZGUI`.
4343

44-
<img src="https://user-images.githubusercontent.com/6503598/135698816-b97b7305-f425-4320-b5e6-69843677e510.png" width=70% height=70%>
44+
<img src="https://user-images.githubusercontent.com/6503598/135729021-6befba47-84ae-4c65-8133-e380f1d36fe1.png" width=60% height=60%>
4545

4646
The icon near an option signifies its current state:
4747

@@ -51,6 +51,26 @@ The icon near an option signifies its current state:
5151

5252
The links at the bottom allow you to perform the most frequent actions.
5353

54+
## Recommended tools
55+
56+
Here is a list of things you may want to try to fix/enhance a few of the aspects which are not addressed by this patcher directly:
57+
58+
### Fix the battery applet
59+
60+
As you will notice, the battery flyout in the taskbar is broken in Windows 11. You can replace it with a much better alternative called [Battery Mode](https://en.bmode.tarcode.ru/) which has all the stock options and more.
61+
62+
### Disable blue highlight in menus
63+
64+
To disable the blue highlight in the context menu and return to the classic gray highlight from early Windows 11 builds, read [here](https://github.com/valinet/ExplorerPatcher/issues/18).
65+
66+
### Center taskbar icons
67+
68+
If you want the same behavior as the default one in Windows 11, which is to have the icons centered along with the Start button, but would like to use this proper classic taskbar which has features like button labels, toolbars and more, you can use my fork of the popular [TaskbarX](https://github.com/ChrisAnd1998/TaskbarX) program which fixes compatibility with Windows 11 and adds this behavior; a guide about how to set it up is available [here](https://github.com/valinet/ExplorerPatcher/issues/33).
69+
70+
### Disable window rounded corners
71+
72+
You can try one of my other utilities available [here](https://github.com/valinet/Win11DisableRoundedCorners).
73+
5474
## Manual configuration
5575

5676
To learn how to configure all the options manually, read on:
@@ -131,15 +151,6 @@ reg.exe delete "HKCU\Software\Classes\CLSID\{1d64637d-31e9-4b06-9124-e83fb178ac6
131151

132152
Also, in the next section, which desribes the configuration options for the software, you will learn about how to disable the search box altogether, should you want to.
133153

134-
### Fix the battery applet
135-
As you will notice, the battery flyout in the taskbar is broken in Windows 11. You can replace it with a much better alternative called [Battery Mode](https://en.bmode.tarcode.ru/) which has all the stock options and more.
136-
137-
### Disable blue highlight in menus
138-
To disable the blue highlight in the context menu and return to the classic gray highlight from early Windows 11 builds, read [here](https://github.com/valinet/ExplorerPatcher/issues/18).
139-
140-
### Disable window rounded corners
141-
You can try one of my other utilities available [here](https://github.com/valinet/Win11DisableRoundedCorners).
142-
143154
### Patcher settings
144155
Now that you have set up the basic stuff, you can choose to enable additional settings to enhance the experience even more. For this, customize the following commands by changing the number acording to your needs:
145156

0 commit comments

Comments
 (0)