monitor.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #if defined(Hiro_Monitor)
  2. //GTK 3.22 adds new monitor functions
  3. //using GTK 2.x functions as FreeBSD 10.1 uses GTK 3.8
  4. namespace hiro {
  5. auto pMonitor::count() -> uint {
  6. #if HIRO_GTK==2 || 1
  7. return gdk_screen_get_n_monitors(gdk_screen_get_default());
  8. #elif HIRO_GTK==3
  9. return gdk_display_get_n_monitors(gdk_display_get_default());
  10. #endif
  11. }
  12. auto pMonitor::dpi(uint monitor) -> Position {
  13. #if HIRO_GTK==2 || 1
  14. //GTK2 does not support either per-monitor or per-axis DPI reporting
  15. float dpi = round(gdk_screen_get_resolution(gdk_screen_get_default()));
  16. return {dpi, dpi};
  17. #elif HIRO_GTK==3
  18. auto gdkMonitor = gdk_display_get_monitor(gdk_display_get_default(), monitor);
  19. return {
  20. round(gdk_monitor_get_width(gdkMonitor) / (gdk_monitor_get_width_mm(gdkMonitor) / 25.4)),
  21. round(gdk_monitor_get_height(gdkMonitor) / (gdk_monitor_get_height_mm(gdkMonitor) / 25.4))
  22. };
  23. #endif
  24. }
  25. auto pMonitor::geometry(uint monitor) -> Geometry {
  26. GdkRectangle rectangle = {};
  27. #if HIRO_GTK==2 || 1
  28. gdk_screen_get_monitor_geometry(gdk_screen_get_default(), monitor, &rectangle);
  29. #elif HIRO_GTK==3
  30. auto gdkMonitor = gdk_display_get_monitor(gdk_display_get_default(), monitor);
  31. gdk_monitor_get_geometry(monitor, &rectangle);
  32. #endif
  33. return {rectangle.x, rectangle.y, rectangle.width, rectangle.height};
  34. }
  35. auto pMonitor::primary() -> uint {
  36. #if HIRO_GTK==2 || 1
  37. return gdk_screen_get_primary_monitor(gdk_screen_get_default());
  38. #elif HIRO_GTK==3
  39. return gdk_display_get_primary_monitor(gdk_display_get_default());
  40. #endif
  41. }
  42. auto pMonitor::workspace(uint monitor) -> Geometry {
  43. #if HIRO_GTK==2 || 1
  44. if(Monitor::count() == 1) {
  45. return Desktop::workspace();
  46. } else {
  47. //it is currently unknown how to get per-monitor workspace areas, use geometry instead
  48. return Monitor::geometry(monitor);
  49. }
  50. #elif HIRO_GTK==3
  51. auto gdkMonitor = gdk_display_get_monitor(gdk_display_get_default(), monitor);
  52. GdkRectangle rectangle = {};
  53. gdk_monitor_get_workarea(monitor, &rectangle);
  54. return {rectangle.x, rectangle.y, rectangle.width, rectangle.height};
  55. #endif
  56. }
  57. }
  58. #endif