我正在玩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);

一切顺利。这是一个已知的问题?

最佳答案

是的,XCheckWindowEvent的手册页明确指出

07-24 13:56