desktop.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #if defined(Hiro_Desktop)
  2. namespace hiro {
  3. auto pDesktop::size() -> Size {
  4. return {
  5. gdk_screen_get_width(gdk_screen_get_default()),
  6. gdk_screen_get_height(gdk_screen_get_default())
  7. };
  8. }
  9. auto pDesktop::workspace() -> Geometry {
  10. #if defined(DISPLAY_WINDOWS)
  11. RECT rc;
  12. SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
  13. return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
  14. #endif
  15. #if defined(DISPLAY_XORG)
  16. auto display = XOpenDisplay(nullptr);
  17. int screen = DefaultScreen(display);
  18. int format;
  19. unsigned char* data = nullptr;
  20. unsigned long items, after;
  21. XlibAtom returnAtom;
  22. XlibAtom netWorkarea = XInternAtom(display, "_NET_WORKAREA", XlibFalse);
  23. XlibAtom cardinal = XInternAtom(display, "CARDINAL", XlibFalse);
  24. int result = XGetWindowProperty(
  25. display, RootWindow(display, screen), netWorkarea, 0, 4, XlibFalse,
  26. cardinal, &returnAtom, &format, &items, &after, &data
  27. );
  28. if(result == Success && returnAtom == cardinal && format == 32 && items == 4) {
  29. unsigned long* workarea = (unsigned long*)data;
  30. XCloseDisplay(display);
  31. return {(int)workarea[0], (int)workarea[1], (int)workarea[2], (int)workarea[3]};
  32. }
  33. XCloseDisplay(display);
  34. return {
  35. 0, 0,
  36. gdk_screen_get_width(gdk_screen_get_default()),
  37. gdk_screen_get_height(gdk_screen_get_default())
  38. };
  39. #endif
  40. return {};
  41. }
  42. }
  43. #endif