1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Windows: Retrieve work area rectangle for all connected monitors

This commit is contained in:
ed 2021-01-04 18:31:25 +00:00
parent b614f9e01e
commit 09c25fedfd

View file

@ -4511,15 +4511,20 @@ static const Displays::Display* getCurrentDisplayFromScaleFactor (HWND hwnd)
//==============================================================================
struct MonitorInfo
{
MonitorInfo (bool main, RECT rect, double d) noexcept
: isMain (main), bounds (rect), dpi (d) {}
MonitorInfo (bool main, RECT totalArea, RECT workArea, double d) noexcept
: isMain (main),
totalAreaRect (totalArea),
workAreaRect (workArea),
dpi (d)
{
}
bool isMain;
RECT bounds;
RECT totalAreaRect, workAreaRect;
double dpi;
};
static BOOL CALLBACK enumMonitorsProc (HMONITOR hm, HDC, LPRECT r, LPARAM userInfo)
static BOOL CALLBACK enumMonitorsProc (HMONITOR hm, HDC, LPRECT, LPARAM userInfo)
{
MONITORINFO info = {};
info.cbSize = sizeof (info);
@ -4536,7 +4541,7 @@ static BOOL CALLBACK enumMonitorsProc (HMONITOR hm, HDC, LPRECT r, LPARAM userIn
dpi = (dpiX + dpiY) / 2.0;
}
((Array<MonitorInfo>*) userInfo)->add ({ isMain, *r, dpi });
((Array<MonitorInfo>*) userInfo)->add ({ isMain, info.rcMonitor, info.rcWork, dpi });
return TRUE;
}
@ -4550,7 +4555,10 @@ void Displays::findDisplays (float masterScale)
auto globalDPI = getGlobalDPI();
if (monitors.size() == 0)
monitors.add ({ true, getWindowRect (GetDesktopWindow()), globalDPI });
{
auto windowRect = getWindowRect (GetDesktopWindow());
monitors.add ({ true, windowRect, windowRect, globalDPI });
}
// make sure the first in the list is the main monitor
for (int i = 1; i < monitors.size(); ++i)
@ -4574,17 +4582,8 @@ void Displays::findDisplays (float masterScale)
d.scale = (d.dpi / USER_DEFAULT_SCREEN_DPI) * (masterScale / Desktop::getDefaultMasterScale());
}
d.userArea = d.totalArea = Rectangle<int>::leftTopRightBottom (monitor.bounds.left, monitor.bounds.top,
monitor.bounds.right, monitor.bounds.bottom);
if (d.isMain)
{
RECT workArea;
SystemParametersInfo (SPI_GETWORKAREA, 0, &workArea, 0);
d.userArea = d.userArea.getIntersection (Rectangle<int>::leftTopRightBottom (workArea.left, workArea.top,
workArea.right, workArea.bottom));
}
d.totalArea = rectangleFromRECT (monitor.totalAreaRect);
d.userArea = rectangleFromRECT (monitor.workAreaRect);
displays.add (d);
}