Implement monitor enumeration
This commit is contained in:
parent
35eb12c542
commit
7afbc443c9
@ -1,8 +1,40 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <physicalmonitorenumerationapi.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
extern BOOL enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
class Monitor {
|
class Monitor {
|
||||||
|
public:
|
||||||
|
Monitor() = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend BOOL detail::enumMonitorsCallback(HMONITOR, HDC, LPRECT, LPARAM);
|
||||||
|
|
||||||
|
Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR hPhysicalMonitor);
|
||||||
|
|
||||||
|
const HMONITOR m_hMonitor;
|
||||||
|
const PHYSICAL_MONITOR m_physicalMonitor;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__clang__) || defined(__GNUC__)
|
||||||
|
|
||||||
|
class Monitor {
|
||||||
|
public:
|
||||||
Monitor();
|
Monitor();
|
||||||
|
|
||||||
public:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -2,9 +2,56 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
std::vector<Monitor> enumerateMonitors()
|
#include <QString>
|
||||||
|
#include <QtDebug>
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "log_tr.hpp"
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
static QString getLastErrorString()
|
||||||
{
|
{
|
||||||
|
DWORD lastErrorId = GetLastError();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL enumMonitorsCallback(HMONITOR hMonitor, [[maybe_unused]] HDC hDC, [[maybe_unused]] LPRECT lpRect, LPARAM lParam)
|
||||||
|
{
|
||||||
|
std::vector<Monitor>& monitors = *reinterpret_cast<std::vector<Monitor>*>(lParam);
|
||||||
|
DWORD numMonitors;
|
||||||
|
|
||||||
|
if(!GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, &numMonitors)) {
|
||||||
|
qCritical(ltr("Unable to get number of physical monitors from handle, error: %1").arg(detail::getLastErrorString()));
|
||||||
|
return true; // Continue enumerating
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<PHYSICAL_MONITOR> physicalMonitors(numMonitors);
|
||||||
|
|
||||||
|
if(!GetPhysicalMonitorsFromHMONITOR(hMonitor, numMonitors, physicalMonitors.data())) {
|
||||||
|
qCritical(ltr("Unable to get physical monitors from handle, error: %1").arg(detail::getLastErrorString()));
|
||||||
|
return true; // Continue enumerating
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const auto& physicalMonitor: physicalMonitors) {
|
||||||
|
monitors.push_back(Monitor(hMonitor, physicalMonitor));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
std::vector<Monitor> enumerateMonitors()
|
||||||
|
{
|
||||||
|
std::vector<Monitor> monitors;
|
||||||
|
|
||||||
|
if(!EnumDisplayMonitors(nullptr, nullptr, detail::enumMonitorsCallback, reinterpret_cast<LPARAM>(&monitors))) {
|
||||||
|
qCritical(ltr("Unable to enumerate display monitors, error: %1").arg(detail::getLastErrorString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return monitors;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
Monitor::Monitor() {}
|
Monitor::Monitor(HMONITOR hMonitor, PHYSICAL_MONITOR hPhysicalMonitor) : m_hMonitor(hMonitor), m_physicalMonitor(m_physicalMonitor) {}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,6 +71,12 @@ target_link_libraries(AdaptiveBrightness
|
|||||||
Qt5::SerialPort
|
Qt5::SerialPort
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_link_libraries(AdaptiveBrightness
|
||||||
|
Dxva2.lib
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
|
get_target_property(QT5_QMAKE_EXECUTABLE Qt5::qmake IMPORTED_LOCATION)
|
||||||
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
|
get_filename_component(QT5_WINDEPLOYQT_EXECUTABLE ${QT5_QMAKE_EXECUTABLE} PATH)
|
||||||
|
Loading…
Reference in New Issue
Block a user