I wrote the following code to detect when a window is created on the screen by another application (not by my code):
Display* display = XOpenDisplay(":0");
XSetWindowAttributes attributes;
attributes.event_mask = SubstructureNotifyMask | StructureNotifyMask;
Window win = XDefaultRootWindow(display);
XChangeWindowAttributes(display, win, CWEventMask, &attributes);
while (1) {
XEvent event;
XNextEvent(display, &event);
if (event.type == CreateNotify)
puts("create Notify event occured\n");
}
The code basically works, however, I noticed that, when I start an application (e.g. terminal) the CreateNotify
event seems to be fired multiple times. Can anybody explain why? I would have expected that CreateNotify
will only be fired once for every started application/window. How do I have to modify the code to achieve this?