1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2025-01-26 16:13:43 +01:00

Start: Better way to determine the monitor on which the Start menu will open

This commit is contained in:
Valentin Radu 2022-11-17 02:52:31 +02:00
parent 4212e357b7
commit 53fad19901
4 changed files with 62 additions and 25 deletions

View File

@ -66,29 +66,6 @@ void OpenStartOnMonitor(HMONITOR monitor)
}
}
typedef struct _MonitorOverrideData
{
DWORD cbIndex;
DWORD dwIndex;
HMONITOR hMonitor;
} MonitorOverrideData;
BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod)
{
POINT pt; pt.x = 0; pt.y = 0;
if (MonitorFromPoint(pt, MONITOR_DEFAULTTONULL) == hMonitor)
{
return TRUE;
}
if (mod->cbIndex == mod->dwIndex)
{
mod->hMonitor = hMonitor;
return FALSE;
}
mod->cbIndex++;
return TRUE;
}
LRESULT CALLBACK OpenStartOnCurentMonitorThreadHook(
int code,
WPARAM wParam,

View File

@ -10861,6 +10861,15 @@ void StartMenu_LoadSettings(BOOL bRestartIfChanged)
&StartMenu_ShowAllApps,
&dwSize
);
dwSize = sizeof(DWORD);
RegQueryValueExW(
hKey,
TEXT("MonitorOverride"),
0,
NULL,
&bMonitorOverride,
&dwSize
);
RegCloseKey(hKey);
}
RegCreateKeyExW(
@ -11274,10 +11283,36 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
HWND hWndTaskbar = NULL;
if (TaskbarAl)
{
HMONITOR hMonitorOfStartMenu = NULL;
if (bMonitorOverride == 1 || !bMonitorOverride) {
POINT pt;
if (!bMonitorOverride) GetCursorPos(&pt);
else {
pt.x = 0; pt.y = 0;
}
hMonitorOfStartMenu = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
}
else {
MonitorOverrideData mod;
mod.cbIndex = 2;
mod.dwIndex = bMonitorOverride;
mod.hMonitor = NULL;
EnumDisplayMonitors(NULL, NULL, ExtractMonitorByIndex, &mod);
if (mod.hMonitor == NULL)
{
POINT pt; pt.x = 0; pt.y = 0;
hMonitorOfStartMenu = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
}
else
{
hMonitorOfStartMenu = mod.hMonitor;
}
}
HWND hWndTemp = NULL;
HWND hShellTray_Wnd = FindWindowExW(NULL, NULL, L"Shell_TrayWnd", NULL);
if (hShellTray_Wnd && !hWndTaskbar && MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == MonitorFromWindow(hShellTray_Wnd, MONITOR_DEFAULTTOPRIMARY) && dwOldTaskbarAl)
if (hShellTray_Wnd && !hWndTaskbar && hMonitorOfStartMenu == MonitorFromWindow(hShellTray_Wnd, MONITOR_DEFAULTTOPRIMARY) && dwOldTaskbarAl)
{
hWndTaskbar = hShellTray_Wnd;
}
@ -11292,7 +11327,7 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
L"Shell_SecondaryTrayWnd",
NULL
);
if (hWndTemp && !hWndTaskbar && MonitorFromWindow(hWnd, MONITOR_DEFAULTTOPRIMARY) == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl)
if (hWndTemp && !hWndTaskbar && hMonitorOfStartMenu == MonitorFromWindow(hWndTemp, MONITOR_DEFAULTTOPRIMARY) && dwMMOldTaskbarAl)
{
hWndTaskbar = hWndTemp;
break;

View File

@ -1625,3 +1625,19 @@ void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt)
CoTaskMemFree(pidl);
}
}
BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod)
{
POINT pt; pt.x = 0; pt.y = 0;
if (MonitorFromPoint(pt, MONITOR_DEFAULTTONULL) == hMonitor)
{
return TRUE;
}
if (mod->cbIndex == mod->dwIndex)
{
mod->hMonitor = hMonitor;
return FALSE;
}
mod->cbIndex++;
return TRUE;
}

View File

@ -584,4 +584,13 @@ BOOL DoesOSBuildSupportSpotlight();
BOOL IsSpotlightEnabled();
void SpotlightHelper(DWORD dwOp, HWND hWnd, HMENU hMenu, LPPOINT pPt);
typedef struct _MonitorOverrideData
{
DWORD cbIndex;
DWORD dwIndex;
HMONITOR hMonitor;
} MonitorOverrideData;
BOOL ExtractMonitorByIndex(HMONITOR hMonitor, HDC hDC, LPRECT lpRect, MonitorOverrideData* mod);
#endif