c++cx11

XCheckWindowEvent doesn't return ClientMessage events


I'm playing around with xlib, and I've got something like this to check for events on a window/sub-window basis:

// 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);
    }
}

Which I call in a loop. I'm building my window thusly:

// 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);

And for some reason, I'm never seeing any ClientMessage events come out of the queue. If I check with something like this (which doesn't let me filter by window):

if (!XPending(xwin->xconn->dpy)) {
    return false;
}

XNextEvent(xwin->xconn->dpy, &event);

It comes through just fine. Is this a known issue?


Solution

  • Yes, the man page for XCheckWindowEvent explicitly says that

    XCheckWindowEvent() cannot return ClientMessage, MappingNotify, SelectionClear, SelectionNotify, or SelectionRequest events because these event types are by definition unmaskable.