我正在玩 xlib,我有这样的东西可以在窗口/子窗口的基础上检查事件:
// Dispatch X11 events in a more friendly format
static inline bool xwin_event(xwin_t *xwin, event_t *evt) {
    XEvent event;
    if (!XCheckWindowEvent(xwin->xconn->dpy, xwin->window, 0xFFFFFFFF, &event)) {
        return false;
    }
    if (event.type == ClientMessage) {
        printf("Got event, wid: %i\n", event.xany.window);
    }
}
我循环调用。我正在建造我的窗户:
// Define events we want
XSelectInput(xconn->dpy, xwin->window,
             KeyPressMask        | 
             ButtonPressMask     | ButtonReleaseMask |
             EnterWindowMask     | LeaveWindowMask   |
             PointerMotionMask   | ExposureMask      |
             StructureNotifyMask | SubstructureNotifyMask);
// Grab some window manager events
xwin->proto = XInternAtom(xconn->dpy, "WM_PROTOCOLS",     1);
xwin->close = XInternAtom(xconn->dpy, "WM_DELETE_WINDOW", 0);
XSetWMProtocols(xconn->dpy, xwin->window, &xwin->close, 1);
出于某种原因,我从来没有看到任何 ClientMessage 事件从队列中出来。如果我检查这样的事情(这不允许我按窗口过滤):
if (!XPending(xwin->xconn->dpy)) {
    return false;
}
XNextEvent(xwin->xconn->dpy, &event);
它通过就好了。这是一个已知的问题?