net_frame_extents.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Create window, retrieve frame extents via xprop command,
  2. * close window.
  3. *
  4. * Usage:
  5. * gcc -o xlib_hello xlib_hello.c -lX11
  6. * ./xlib_hello
  7. */
  8. #include <X11/Xlib.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. int main(int argc, char** argv) {
  12. Display* disp = XOpenDisplay(NULL);
  13. if (disp == NULL) {
  14. return 1;
  15. }
  16. int screen = DefaultScreen(disp);
  17. char name[24] = "x_get_net_frame_extents";
  18. GC gc = DefaultGC(disp, screen);
  19. Window parent_window = DefaultRootWindow(disp);
  20. int x = -0;
  21. int y = -0;
  22. unsigned int width = 1;
  23. unsigned int height = 1;
  24. unsigned int border_width = 0;
  25. unsigned int border_color = BlackPixel(disp, screen);
  26. unsigned int background_color = BlackPixel(disp, screen);
  27. // Create window
  28. Window win = XCreateSimpleWindow(disp, parent_window,
  29. x,
  30. y,
  31. width,
  32. height,
  33. border_width,
  34. border_color,
  35. background_color);
  36. // Make window visible
  37. XMapWindow(disp, win);
  38. // Set window name
  39. XStoreName(disp,win,name);
  40. // Get WM_DELETE_WINDOW atom
  41. Atom wm_delete = XInternAtom(disp, "WM_DELETE_WINDOW", True);
  42. ///////////////////////////////////////////////////////////////////////////
  43. char command[70] = "xprop -notype -name ";
  44. strcat(command,name);
  45. strcat(command," _NET_FRAME_EXTENTS");
  46. system(command);
  47. ///////////////////////////////////////////////////////////////////////////
  48. // Subscribe WM_DELETE_WINDOW message
  49. XSetWMProtocols(disp, win, &wm_delete, 1);
  50. XCloseDisplay(disp);
  51. return 0;
  52. }