2019-09-05 00:26:26 +08:00
|
|
|
#include "pch.h"
|
2019-12-17 16:21:46 +08:00
|
|
|
|
2019-09-05 00:26:26 +08:00
|
|
|
#include "monitors.h"
|
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-03-05 18:07:06 +08:00
|
|
|
bool operator==(const ScreenSize& lhs, const ScreenSize& rhs)
|
|
|
|
{
|
|
|
|
auto lhs_tuple = std::make_tuple(lhs.rect.left, lhs.rect.right, lhs.rect.top, lhs.rect.bottom);
|
|
|
|
auto rhs_tuple = std::make_tuple(rhs.rect.left, rhs.rect.right, rhs.rect.top, rhs.rect.bottom);
|
|
|
|
return lhs_tuple == rhs_tuple;
|
2019-09-05 00:26:26 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
static BOOL CALLBACK GetDisplaysEnumCb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
|
2020-03-05 18:07:06 +08:00
|
|
|
{
|
2020-04-21 00:09:10 +08:00
|
|
|
MONITORINFOEX monitorInfo;
|
|
|
|
monitorInfo.cbSize = sizeof(MONITORINFOEX);
|
|
|
|
if (GetMonitorInfo(monitor, &monitorInfo))
|
|
|
|
{
|
|
|
|
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitorInfo.rcWork);
|
|
|
|
}
|
2020-03-05 18:07:06 +08:00
|
|
|
return true;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
static BOOL CALLBACK GetDisplaysEnumCbWithNonWorkingArea(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
|
2020-03-05 18:07:06 +08:00
|
|
|
{
|
2020-04-21 00:09:10 +08:00
|
|
|
MONITORINFOEX monitorInfo;
|
|
|
|
monitorInfo.cbSize = sizeof(MONITORINFOEX);
|
|
|
|
if (GetMonitorInfo(monitor, &monitorInfo))
|
|
|
|
{
|
|
|
|
reinterpret_cast<std::vector<MonitorInfo>*>(data)->emplace_back(monitor, monitorInfo.rcMonitor);
|
|
|
|
}
|
2020-03-05 18:07:06 +08:00
|
|
|
return true;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool includeNonWorkingArea)
|
2020-03-05 18:07:06 +08:00
|
|
|
{
|
|
|
|
std::vector<MonitorInfo> monitors;
|
2020-04-21 00:09:10 +08:00
|
|
|
EnumDisplayMonitors(NULL, NULL, includeNonWorkingArea ? GetDisplaysEnumCbWithNonWorkingArea : GetDisplaysEnumCb, reinterpret_cast<LPARAM>(&monitors));
|
2020-03-05 18:07:06 +08:00
|
|
|
std::sort(begin(monitors), end(monitors), [](const MonitorInfo& lhs, const MonitorInfo& rhs) {
|
|
|
|
return lhs.rect < rhs.rect;
|
2019-09-05 00:26:26 +08:00
|
|
|
});
|
2020-03-05 18:07:06 +08:00
|
|
|
return monitors;
|
2019-09-05 00:26:26 +08:00
|
|
|
}
|
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
static BOOL CALLBACK GetPrimaryDisplayEnumCb(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM data)
|
2020-04-15 18:34:11 +08:00
|
|
|
{
|
2020-04-21 00:09:10 +08:00
|
|
|
MONITORINFOEX monitorInfo;
|
|
|
|
monitorInfo.cbSize = sizeof(MONITORINFOEX);
|
2020-04-15 18:34:11 +08:00
|
|
|
|
2020-04-21 00:09:10 +08:00
|
|
|
if (GetMonitorInfo(monitor, &monitorInfo) && (monitorInfo.dwFlags & MONITORINFOF_PRIMARY))
|
2020-03-05 18:07:06 +08:00
|
|
|
{
|
|
|
|
reinterpret_cast<MonitorInfo*>(data)->handle = monitor;
|
2020-04-21 00:09:10 +08:00
|
|
|
reinterpret_cast<MonitorInfo*>(data)->rect = monitorInfo.rcWork;
|
2020-03-05 18:07:06 +08:00
|
|
|
}
|
|
|
|
return true;
|
2019-09-05 00:26:26 +08:00
|
|
|
};
|
|
|
|
|
2020-03-05 18:07:06 +08:00
|
|
|
MonitorInfo MonitorInfo::GetPrimaryMonitor()
|
|
|
|
{
|
|
|
|
MonitorInfo primary({}, {});
|
2020-04-21 00:09:10 +08:00
|
|
|
EnumDisplayMonitors(NULL, NULL, GetPrimaryDisplayEnumCb, reinterpret_cast<LPARAM>(&primary));
|
2020-03-05 18:07:06 +08:00
|
|
|
return primary;
|
2019-09-05 00:26:26 +08:00
|
|
|
}
|