mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
* Analyzers CPP Changing the warning level from 3 to 4. change some project files to make them use the warning config in cpp props file. * Analyzers C++ turn on warning 4706 Change Cpp.Build.props file to enable 4706 fix BugReportTool code to get rid of 4706 * Turn on warning 4100 and fix the code * Follow c++ core guidelines * Adapting to PR comments
55 lines
1.5 KiB
C++
55 lines
1.5 KiB
C++
#include "monitors.h"
|
|
|
|
#include <algorithm>
|
|
|
|
Box MonitorInfo::GetScreenSize(const bool includeNonWorkingArea) const
|
|
{
|
|
return includeNonWorkingArea ? Box{ info.rcMonitor } : Box{ info.rcWork };
|
|
}
|
|
|
|
bool MonitorInfo::IsPrimary() const
|
|
{
|
|
return static_cast<bool>(info.dwFlags & MONITORINFOF_PRIMARY);
|
|
}
|
|
|
|
MonitorInfo::MonitorInfo(HMONITOR h) :
|
|
handle{ h }
|
|
{
|
|
info.cbSize = sizeof(MONITORINFOEX);
|
|
GetMonitorInfoW(handle, &info);
|
|
}
|
|
|
|
static BOOL CALLBACK GetDisplaysEnumCb(HMONITOR monitor, HDC /*hdc*/, LPRECT /*rect*/, LPARAM data)
|
|
{
|
|
auto* monitors = reinterpret_cast<std::vector<MonitorInfo>*>(data);
|
|
monitors->emplace_back(monitor);
|
|
return true;
|
|
};
|
|
|
|
std::vector<MonitorInfo> MonitorInfo::GetMonitors(bool includeNonWorkingArea)
|
|
{
|
|
std::vector<MonitorInfo> monitors;
|
|
EnumDisplayMonitors(nullptr, nullptr, GetDisplaysEnumCb, reinterpret_cast<LPARAM>(&monitors));
|
|
std::sort(begin(monitors), end(monitors), [=](const MonitorInfo& lhs, const MonitorInfo& rhs) {
|
|
const auto lhsSize = lhs.GetScreenSize(includeNonWorkingArea);
|
|
const auto rhsSize = rhs.GetScreenSize(includeNonWorkingArea);
|
|
|
|
return lhsSize < rhsSize;
|
|
});
|
|
return monitors;
|
|
}
|
|
|
|
MonitorInfo MonitorInfo::GetPrimaryMonitor()
|
|
{
|
|
auto monitors = MonitorInfo::GetMonitors(false);
|
|
if (monitors.size() > 1)
|
|
{
|
|
for (auto monitor : monitors)
|
|
{
|
|
if (monitor.IsPrimary())
|
|
return monitor;
|
|
}
|
|
}
|
|
return monitors[0];
|
|
}
|