Skip to content

Commit

Permalink
Start: Better way to determine the monitor on which the Start menu wi…
Browse files Browse the repository at this point in the history
…ll open
  • Loading branch information
valinet committed Nov 17, 2022
1 parent 4212e35 commit 53fad19
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
23 changes: 0 additions & 23 deletions ExplorerPatcher/StartMenu.c
Expand Up @@ -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,
Expand Down
39 changes: 37 additions & 2 deletions ExplorerPatcher/dllmain.c
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions ExplorerPatcher/utility.c
Expand Up @@ -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;
}
9 changes: 9 additions & 0 deletions ExplorerPatcher/utility.h
Expand Up @@ -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

0 comments on commit 53fad19

Please sign in to comment.