windowhelper.cpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536
  1. #include "windowhelper.hpp"
  2. glm::vec4 getWindowGeometry( Window win, bool removeDecoration) {
  3. XWindowAttributes attr;
  4. XGetWindowAttributes( x11->display, win, &attr );
  5. unsigned int width = attr.width;
  6. unsigned int height = attr.height;
  7. unsigned int border = attr.border_width;
  8. int x, y;
  9. Window junk;
  10. XTranslateCoordinates( x11->display, win, attr.root, -attr.border_width, -attr.border_width, &x, &y, &junk );
  11. if ( !removeDecoration ) {
  12. width += border*2;
  13. height += border*2;
  14. return glm::vec4( x, y, width, height );
  15. }
  16. // This is required to be defined by the window manager, so we can assume it exists.
  17. Atom actual_type;
  18. int actual_format;
  19. unsigned long nitems, bytes_after;
  20. unsigned char *data;
  21. int result = XGetWindowProperty(x11->display, win,
  22. XInternAtom(x11->display, "_NET_FRAME_EXTENTS", true),
  23. 0, 4, False, AnyPropertyType,
  24. &actual_type, &actual_format, &nitems, &bytes_after, &data);
  25. if ( result == Success ) {
  26. // Make sure we got the data we expect...
  27. if ((nitems == 4) && (bytes_after == 0)) {
  28. x += (int)data[0];
  29. width -= (int)data[1];
  30. y += (int)data[2];
  31. height -= (int)data[3];
  32. }
  33. }
  34. return glm::vec4( x, y, width, height );
  35. }