From 44b84e9666e382737b940a83e7c4e7f67ffa11a2 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Sat, 2 Oct 2021 22:11:26 +0300 Subject: [PATCH] Win+X positioning improvements; fixes #31 --- CHANGELOG.md | 15 ++++- ExplorerPatcher/ExplorerPatcher.rc | 8 +-- ExplorerPatcher/dllmain.c | 92 +++++++++++++++++++----------- ExplorerPatcher/utility.c | 26 ++++++++- ExplorerPatcher/utility.h | 2 +- README.md | 33 +++++++---- 6 files changed, 125 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11b9b0a..c6cd477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub. +## 22000.194.0.23 + +Tested on build: 22000.194. + +* Fixed a bug that showed`Win`+`X` on the wrong monitor in certain scenarios +* `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)) +* Fixed the bug that prevented the application from loading in`StartMenuExperienceHost.exe` (thanks to @BraINstinct0 for the report) +* Fixed padding and element sizes in GUI so it better fits on smaller screens (thanks to @Gaurav-Original-ClassicShellTester for the report) +* GUI shows application title when run outside of File Explorer +* GUI stays on screen and just reloads the settings when restoring defaults (instead of closing) +* 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 +* 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 + ## 22000.194.0.22 Tested on build: 22000.194. @@ -12,7 +25,7 @@ Tested on build: 22000.194. Tested on build: 22000.194. -* Implemented configuration GUI; to access it, right click the Start button (or press `Win`+`X`) and choose "Properties" +* Implemented configuration GUI; to access it, right click the Start button (or press `Win`+`X`) and choose "Properties" (thanks to @BraINstinct0 for the suggestion) ## 22000.194.0.20 diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 0821bb5..359f44e 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,194,0,22 - PRODUCTVERSION 22000,194,0,22 + FILEVERSION 22000,194,0,23 + PRODUCTVERSION 22000,194,0,23 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher" - VALUE "FileVersion", "22000.194.0.22" + VALUE "FileVersion", "22000.194.0.23" VALUE "InternalName", "ExplorerPatcher.dll" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcher.dll" VALUE "ProductName", "ExplorerPatcher" - VALUE "ProductVersion", "22000.194.0.22" + VALUE "ProductVersion", "22000.194.0.23" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 5014a5b..b76fbde 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -208,6 +208,7 @@ typedef struct void* _this; POINT point; IUnknown* iunk; + BOOL bShouldCenterWinXHorizontally; } ShowLauncherTipContextMenuParameters; HWND hWinXWnd; DWORD ShowLauncherTipContextMenu( @@ -287,7 +288,7 @@ DWORD ShowLauncherTipContextMenu( BOOL res = TrackPopupMenu( *((HMENU*)((char*)params->_this + 0xe8)), - TPM_RETURNCMD | TPM_RIGHTBUTTON, + TPM_RETURNCMD | TPM_RIGHTBUTTON | (params->bShouldCenterWinXHorizontally ? TPM_CENTERALIGN : 0), params->point.x, params->point.y, 0, @@ -355,59 +356,83 @@ INT64 CLauncherTipContextMenu_ShowLauncherTipContextMenuHook( goto finalize; } + BOOL bShouldCenterWinXHorizontally = FALSE; POINT point; if (pt) { point = *pt; BOOL bBottom, bRight; - POINT dPt = GetDefaultWinXPosition(FALSE, &bBottom, &bRight); + POINT dPt = GetDefaultWinXPosition(FALSE, &bBottom, &bRight, FALSE); if (bBottom) { HMONITOR hMonitor = MonitorFromPoint(point, MONITOR_DEFAULTTOPRIMARY); MONITORINFO mi; mi.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, &mi); - UINT dpiX, dpiY; - HRESULT hr = GetDpiForMonitor( - hMonitor, - MDT_DEFAULT, - &dpiX, - &dpiY - ); - double dx = dpiX / 96.0, dy = dpiY / 96.0; - BOOL xo = FALSE, yo = FALSE; - if (point.x - WINX_ADJUST_X * dx < mi.rcMonitor.left) - { - xo = TRUE; - } - if (point.y + WINX_ADJUST_Y * dy > mi.rcMonitor.bottom) + HWND hWndUnder = WindowFromPoint(*pt); + TCHAR wszClassName[100]; + GetClassNameW(hWndUnder, wszClassName, 100); + if (!wcscmp(wszClassName, L"Shell_TrayWnd") || !wcscmp(wszClassName, L"Shell_SecondaryTrayWnd")) { - yo = TRUE; - } - POINT ptCursor; - GetCursorPos(&ptCursor); - if (xo) - { - ptCursor.x += (WINX_ADJUST_X * 2) * dx; - } - else - { - point.x -= WINX_ADJUST_X * dx; + hWndUnder = FindWindowEx( + hWndUnder, + NULL, + L"Start", + NULL + ); } - if (yo) + RECT rcUnder; + GetWindowRect(hWndUnder, &rcUnder); + if (mi.rcMonitor.left != rcUnder.left) { - ptCursor.y -= (WINX_ADJUST_Y * 2) * dy; + bShouldCenterWinXHorizontally = TRUE; + point.x = rcUnder.left + (rcUnder.right - rcUnder.left) / 2; + point.y = rcUnder.top; } else { - point.y += WINX_ADJUST_Y * dy; + UINT dpiX, dpiY; + HRESULT hr = GetDpiForMonitor( + hMonitor, + MDT_DEFAULT, + &dpiX, + &dpiY + ); + double dx = dpiX / 96.0, dy = dpiY / 96.0; + BOOL xo = FALSE, yo = FALSE; + if (point.x - WINX_ADJUST_X * dx < mi.rcMonitor.left) + { + xo = TRUE; + } + if (point.y + WINX_ADJUST_Y * dy > mi.rcMonitor.bottom) + { + yo = TRUE; + } + POINT ptCursor; + GetCursorPos(&ptCursor); + if (xo) + { + ptCursor.x += (WINX_ADJUST_X * 2) * dx; + } + else + { + point.x -= WINX_ADJUST_X * dx; + } + if (yo) + { + ptCursor.y -= (WINX_ADJUST_Y * 2) * dy; + } + else + { + point.y += WINX_ADJUST_Y * dy; + } + SetCursorPos(ptCursor.x, ptCursor.y); } - SetCursorPos(ptCursor.x, ptCursor.y); } } else { - point = GetDefaultWinXPosition(FALSE, NULL, NULL); + point = GetDefaultWinXPosition(FALSE, NULL, NULL, TRUE); } IUnknown* iunk; @@ -424,6 +449,7 @@ INT64 CLauncherTipContextMenu_ShowLauncherTipContextMenuHook( params->_this = _this; params->point = point; params->iunk = iunk; + params->bShouldCenterWinXHorizontally = bShouldCenterWinXHorizontally; hIsWinXShown = CreateThread( 0, 0, @@ -1004,7 +1030,7 @@ LRESULT explorer_SendMessageW(HWND hWndx, UINT uMsg, WPARAM wParam, LPARAM lPara ); if (hWnd) { - POINT pt = GetDefaultWinXPosition(FALSE, NULL, NULL); + POINT pt = GetDefaultWinXPosition(FALSE, NULL, NULL, TRUE); PostMessage( hWnd, WM_CONTEXTMENU, diff --git a/ExplorerPatcher/utility.c b/ExplorerPatcher/utility.c index 72a48e6..8923019 100644 --- a/ExplorerPatcher/utility.c +++ b/ExplorerPatcher/utility.c @@ -264,7 +264,7 @@ __declspec(dllexport) CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hIns ZZLaunchExplorer(hWnd, hInstance, lpszCmdLine, nCmdShow); } -POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) +POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOOL bAdjust) { if (lpBottom) *lpBottom = FALSE; if (lpRight) *lpRight = FALSE; @@ -294,6 +294,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.x = mi.rcMonitor.left; } + if (bAdjust) + { + point.x++; + } if (rc.top - mi.rcMonitor.top == 0) { if (bUseRcWork) @@ -304,6 +308,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.y = mi.rcMonitor.top; } + if (bAdjust) + { + point.y++; + } } else { @@ -316,6 +324,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.y = mi.rcMonitor.bottom; } + if (bAdjust) + { + point.y--; + } } } else @@ -329,6 +341,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.x = mi.rcMonitor.right; } + if (bAdjust) + { + point.x--; + } if (rc.top - mi.rcMonitor.top == 0) { if (bUseRcWork) @@ -339,6 +355,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.y = mi.rcMonitor.top; } + if (bAdjust) + { + point.y++; + } } else { @@ -351,6 +371,10 @@ POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight) { point.y = mi.rcMonitor.bottom; } + if (bAdjust) + { + point.y--; + } } } } diff --git a/ExplorerPatcher/utility.h b/ExplorerPatcher/utility.h index fea4f3b..9fd0411 100644 --- a/ExplorerPatcher/utility.h +++ b/ExplorerPatcher/utility.h @@ -44,7 +44,7 @@ __declspec(dllexport) CALLBACK ZZLaunchExplorer(HWND hWnd, HINSTANCE hInstance, __declspec(dllexport) CALLBACK ZZLaunchExplorerDelayed(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow); -POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight); +POINT GetDefaultWinXPosition(BOOL bUseRcWork, BOOL* lpBottom, BOOL* lpRight, BOOL bAdjust); void QueryVersionInfo(HMODULE hModule, WORD Resource, DWORD*, DWORD*, DWORD*, DWORD*); #endif \ No newline at end of file diff --git a/README.md b/README.md index 3222198..cca9b12 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ Now, the classic taskbar should be enabled. Still, there is some more setup to d ## Configuration interface -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". +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`. - + The icon near an option signifies its current state: @@ -51,6 +51,26 @@ The icon near an option signifies its current state: The links at the bottom allow you to perform the most frequent actions. +## Recommended tools + +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: + +### Fix the battery applet + +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. + +### Disable blue highlight in menus + +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). + +### Center taskbar icons + +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). + +### Disable window rounded corners + +You can try one of my other utilities available [here](https://github.com/valinet/Win11DisableRoundedCorners). + ## Manual configuration 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 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. -### Fix the battery applet -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. - -### Disable blue highlight in menus -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). - -### Disable window rounded corners -You can try one of my other utilities available [here](https://github.com/valinet/Win11DisableRoundedCorners). - ### Patcher settings 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: