Properly handle automatically hiding taskbar on multi-monitor setup

When taskbar is hidden its window is moved off the screen (except for
few pixels at border). It may happen that the taskbar window actually
spans to another monitor (though still not visible).

MonitorFromWindow API may thus return different monitor handle than the
one visible taskbar is on.

We will use GetTaskbarPosition function that correctly identifies taskbar's
monitor by checking rectangle of visible taskbar.

Fixes #908
This commit is contained in:
ge0rdi
2022-12-01 20:57:24 +01:00
parent 04770c403d
commit 704459225b
2 changed files with 5 additions and 2 deletions

View File

@@ -7652,6 +7652,9 @@ HWND CMenuContainer::ToggleStartMenu( int taskbarId, bool bKeyboard, bool bAllPr
// initialize all settings // initialize all settings
bool bErr=false; bool bErr=false;
HMONITOR initialMonitor=MonitorFromWindow(s_TaskBar,MONITOR_DEFAULTTONEAREST); HMONITOR initialMonitor=MonitorFromWindow(s_TaskBar,MONITOR_DEFAULTTONEAREST);
// note: GetTaskbarPosition properly identifies monitor in case of multi-monitor setup and automatic taskbar hiding
GetTaskbarPosition(s_TaskBar,NULL,&initialMonitor,NULL);
int dpi=CItemManager::GetDPI(true); int dpi=CItemManager::GetDPI(true);
if (!CItemManager::GetDPIOverride() && GetWinVersion()>=WIN_VER_WIN81) if (!CItemManager::GetDPIOverride() && GetWinVersion()>=WIN_VER_WIN81)
{ {

View File

@@ -617,12 +617,12 @@ UINT GetTaskbarPosition( HWND taskBar, MONITORINFO *pInfo, HMONITOR *pMonitor, R
if (pRc->right>rc.right) pRc->right=rc.right; if (pRc->right>rc.right) pRc->right=rc.right;
} }
} }
HMONITOR monitor=MonitorFromRect(&appbar.rc,MONITOR_DEFAULTTONEAREST);
if (pMonitor) *pMonitor=monitor;
if (pInfo) if (pInfo)
{ {
pInfo->cbSize=sizeof(MONITORINFO); pInfo->cbSize=sizeof(MONITORINFO);
HMONITOR monitor=MonitorFromRect(&appbar.rc,MONITOR_DEFAULTTONEAREST);
GetMonitorInfo(monitor,pInfo); GetMonitorInfo(monitor,pInfo);
if (pMonitor) *pMonitor=monitor;
} }
return appbar.uEdge; return appbar.uEdge;
} }