close-window.c 680 B

12345678910111213141516171819202122232425262728293031
  1. #include <X11/Xutil.h>
  2. #include <X11/Xlib.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. int close_window(Display *d, XID window) {
  6. XClientMessageEvent ev;
  7. memset(&ev, 0, sizeof(ev));
  8. ev.type = ClientMessage;
  9. ev.display = d;
  10. ev.window = window;
  11. ev.format = 32;
  12. ev.message_type = XInternAtom(d, "WM_PROTOCOLS", False);
  13. ev.data.l[0] = XInternAtom(d, "WM_DELETE_WINDOW", False);;
  14. return XSendEvent(ev.display, ev.window, True, 0, (XEvent *) & ev);
  15. }
  16. int main(int argc, char **argv) {
  17. int i;
  18. Display *d;
  19. d = XOpenDisplay(NULL);
  20. if (!d)
  21. exit(1);
  22. for (i=1; i<argc; i++) {
  23. close_window(d, strtoul(argv[i], NULL, 0));
  24. }
  25. XSync(d, False);
  26. XCloseDisplay(d);
  27. return 0;
  28. }