File: monitor.cpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (54 lines) | stat: -rw-r--r-- 1,487 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#if defined(Hiro_Monitor)

namespace hiro {

struct MonitorInfo {
  uint monitor = 0;
  uint primary = 0;
  Geometry geometry;
  uint index = 0;
};

static auto CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) -> BOOL {
  MonitorInfo& info = *(MonitorInfo*)dwData;
  MONITORINFOEX mi{};
  mi.cbSize = sizeof(MONITORINFOEX);
  GetMonitorInfo(hMonitor, &mi);
  string displayName = (const char*)utf8_t(mi.szDevice);
  if(displayName.beginsWith(R"(\\.\DISPLAYV)")) return true;  //ignore pseudo-monitors
  if(mi.dwFlags & MONITORINFOF_PRIMARY) info.primary = info.index;
  if(info.monitor == info.index) {
    info.geometry = {lprcMonitor->left, lprcMonitor->top, lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top};
  }
  info.index++;
  return true;
}

auto pMonitor::count() -> uint {
  return GetSystemMetrics(SM_CMONITORS);
}

auto pMonitor::dpi(uint monitor) -> Position {
  HDC hdc = GetDC(0);
  auto dpiX = (float)GetDeviceCaps(hdc, LOGPIXELSX);
  auto dpiY = (float)GetDeviceCaps(hdc, LOGPIXELSY);
  ReleaseDC(0, hdc);
  return {dpiX, dpiY};
}

auto pMonitor::geometry(uint monitor) -> Geometry {
  MonitorInfo info;
  info.monitor = monitor;
  EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, (LPARAM)&info);
  return info.geometry;
}

auto pMonitor::primary() -> uint {
  MonitorInfo info;
  EnumDisplayMonitors(nullptr, nullptr, MonitorEnumProc, (LPARAM)&info);
  return info.primary;
}

}

#endif