desktop.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if defined(Hiro_Desktop)
  2. namespace hiro {
  3. auto pDesktop::size() -> Size {
  4. #if defined(DISPLAY_WINDOWS)
  5. return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)};
  6. #elif defined(DISPLAY_XORG)
  7. auto display = XOpenDisplay(nullptr);
  8. int screen = DefaultScreen(display);
  9. XWindowAttributes attributes;
  10. XGetWindowAttributes(display, RootWindow(display, screen), &attributes);
  11. XCloseDisplay(display);
  12. return {attributes.width, attributes.height};
  13. #else
  14. //this only returns the geometry of the primary monitor rather than the entire desktop
  15. QRect rect = QApplication::desktop()->screenGeometry();
  16. return {rect.width(), rect.height()};
  17. #endif
  18. }
  19. auto pDesktop::workspace() -> Geometry {
  20. #if defined(DISPLAY_WINDOWS)
  21. RECT rc;
  22. SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
  23. return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
  24. #elif defined(DISPLAY_XORG)
  25. auto display = XOpenDisplay(nullptr);
  26. int screen = DefaultScreen(display);
  27. int format;
  28. unsigned char* data = nullptr;
  29. unsigned long items, after;
  30. XlibAtom returnAtom;
  31. XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibFalse);
  32. XlibAtom cardinal = XInternAtom(display, "CARDINAL", XlibFalse);
  33. int result = XGetWindowProperty(
  34. display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse,
  35. cardinal, &returnAtom, &format, &items, &after, &data
  36. );
  37. if(result == Success && returnAtom == cardinal && format == 32 && items == 4) {
  38. unsigned long* workarea = (unsigned long*)data;
  39. XCloseDisplay(display);
  40. return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]};
  41. }
  42. XCloseDisplay(display);
  43. auto size = Desktop::size();
  44. return {0, 0, size.width(), size.height()};
  45. #else
  46. //this only returns the workspace of the primary monitor rather than the entire desktop
  47. QRect rect = QApplication::desktop()->availableGeometry();
  48. return {rect.x(), rect.y(), rect.width(), rect.height()};
  49. #endif
  50. }
  51. }
  52. #endif