我编写了以下代码来检测另一个应用程序(不是我的代码)在屏幕上创建窗口的时间:
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");
}
该代码基本上可以工作,但是,我注意到,当我启动一个应用程序(例如终端)时,该CreateNotify
事件似乎被触发了多次。谁能解释为什么?我原以为每个启动的应用程序/窗口CreateNotify
只会触发一次。我如何修改代码来实现这一点?