monitor.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if defined(Hiro_Monitor)
  2. namespace hiro {
  3. auto pMonitor::count() -> uint {
  4. @autoreleasepool {
  5. return [[NSScreen screens] count];
  6. }
  7. }
  8. auto pMonitor::dpi(uint monitor) -> Position {
  9. //macOS includes built-in HiDPI scaling support.
  10. //it may be better to rely on per-application scaling,
  11. //but for now we'll let macOS handle it so it works in all hiro applications.
  12. #if 0
  13. @autoreleasepool {
  14. NSScreen* screen = [[NSScreen screens] objectAtIndex:monitor];
  15. NSDictionary* dictionary = [screen deviceDescription];
  16. NSSize dpi = [[dictionary objectForKey:NSDeviceSize] sizeValue];
  17. return {dpi.width, dpi.height};
  18. }
  19. #endif
  20. return {96.0, 96.0};
  21. }
  22. auto pMonitor::geometry(uint monitor) -> Geometry {
  23. @autoreleasepool {
  24. NSRect rectangle = [[[NSScreen screens] objectAtIndex:monitor] frame];
  25. return {
  26. (int)rectangle.origin.x,
  27. (int)rectangle.origin.y,
  28. (int)rectangle.size.width,
  29. (int)rectangle.size.height
  30. };
  31. }
  32. }
  33. auto pMonitor::primary() -> uint {
  34. //on macOS, the primary monitor is always the first monitor.
  35. return 0;
  36. }
  37. auto pMonitor::workspace(uint monitor) -> Geometry {
  38. @autoreleasepool {
  39. NSRect size = [[[NSScreen screens] objectAtIndex:monitor] frame];
  40. NSRect area = [[[NSScreen screens] objectAtIndex:monitor] visibleFrame];
  41. return {
  42. (int)area.origin.x,
  43. (int)area.origin.y,
  44. (int)area.size.width,
  45. (int)area.size.height
  46. };
  47. }
  48. }
  49. }
  50. #endif