File: monitor.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (50 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download | duplicates (2)
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
#if defined(Hiro_Monitor)

namespace hiro {

auto pMonitor::count() -> u32 {
  return [[NSScreen screens] count];
}

auto pMonitor::dpi(u32 monitor) -> Position {
  //macOS includes built-in HiDPI scaling support.
  //it may be better to rely on per-application scaling,
  //but for now we'll let macOS handle it so it works in all hiro applications.
  #if 0
  NSScreen* screen = [[NSScreen screens] objectAtIndex:monitor];
  NSDictionary* dictionary = [screen deviceDescription];
  NSSize dpi = [[dictionary objectForKey:NSDeviceSize] sizeValue];
  return {dpi.width, dpi.height};
  #endif
  return {96.0, 96.0};
}

auto pMonitor::geometry(u32 monitor) -> Geometry {
  NSRect rectangle = [[[NSScreen screens] objectAtIndex:monitor] frame];
  return {
    (s32)rectangle.origin.x,
    (s32)rectangle.origin.y,
    (s32)rectangle.size.width,
    (s32)rectangle.size.height
  };
}

auto pMonitor::primary() -> u32 {
  //on macOS, the primary monitor is always the first monitor.
  return 0;
}

auto pMonitor::workspace(u32 monitor) -> Geometry {
  NSRect size = [[[NSScreen screens] objectAtIndex:monitor] frame];
  NSRect area = [[[NSScreen screens] objectAtIndex:monitor] visibleFrame];
  return {
    (s32)area.origin.x,
    (s32)area.origin.y,
    (s32)area.size.width,
    (s32)area.size.height
  };
}

}

#endif