2014-07-04 18:49:49 +02:00
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int close_window(Display *d, XID window) {
|
|
|
|
XClientMessageEvent ev;
|
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
ev.type = ClientMessage;
|
|
|
|
ev.display = d;
|
|
|
|
ev.window = window;
|
|
|
|
ev.format = 32;
|
|
|
|
ev.message_type = XInternAtom(d, "WM_PROTOCOLS", False);
|
|
|
|
ev.data.l[0] = XInternAtom(d, "WM_DELETE_WINDOW", False);;
|
|
|
|
return XSendEvent(ev.display, ev.window, True, 0, (XEvent *) & ev);
|
|
|
|
}
|
|
|
|
|
2015-03-04 01:48:11 +01:00
|
|
|
int is_window_visible(Display *d, XID window) {
|
|
|
|
XWindowAttributes xwa;
|
|
|
|
|
|
|
|
if (!XGetWindowAttributes(d, window, &xwa))
|
|
|
|
return 0;
|
|
|
|
return xwa.map_state == IsViewable;
|
|
|
|
}
|
|
|
|
|
2014-07-04 18:49:49 +02:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int i;
|
|
|
|
Display *d;
|
2015-03-04 01:48:11 +01:00
|
|
|
XID w;
|
2014-07-04 18:49:49 +02:00
|
|
|
|
|
|
|
d = XOpenDisplay(NULL);
|
|
|
|
if (!d)
|
|
|
|
exit(1);
|
|
|
|
for (i=1; i<argc; i++) {
|
2015-03-04 01:48:11 +01:00
|
|
|
w = strtoul(argv[i], NULL, 0);
|
|
|
|
if (is_window_visible(d, w))
|
|
|
|
close_window(d, w);
|
2014-07-04 18:49:49 +02:00
|
|
|
}
|
|
|
|
XSync(d, False);
|
|
|
|
XCloseDisplay(d);
|
|
|
|
return 0;
|
|
|
|
}
|