別のアプリケーション (私のコードではありません) によって画面上にウィンドウが作成されたことを検出するために、次のコードを作成しました。
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
コードは基本的に機能しますが、アプリケーション (ターミナルなど) を起動すると、イベントが複数回発生するように見えることに気付きました。誰でも理由を説明できますか?起動されたアプリケーション/ウィンドウごとに1回CreateNotify
だけ起動されると予想していました。これを実現するには、コードをどのように変更する必要がありますか?