Need for XEventsQueued(display, QueuedAfterReading) in XCB

柔情痞子 提交于 2019-12-06 15:48:17

Are you looking for xcb_poll_for_queued_event(xcb_connection_t *c) which returns the next event without reading from the connection?

First, thanks to Julien for his reply.

I have studied the XCB 1.9 sources and found out that the "xcb_poll_for_queued_event" function is not what I need.

The functions "xcb_poll_for_event" and "xcb_poll_for_queued_event" both call "poll_for_next_event". The functions "poll_for_next_event" and "xcb_wait_for_event" both call "get_event".

If "get_event" finds an event, it changes the internal linked list to point to the next event. However, I would prefer NOT to change the event queue AT ALL, independent from whether or not events are available.

I therefore propose to add a function like the following to XCB:

void* NULL_POINTER = (void*) 0;

int xcb_test_for_event(xcb_connection_t* c) {

    int r = 0;

    if (c != NULL_POINTER) {

        struct _xcb_in in = c->in;
        struct event_list* l = in.events;

        if (l != NULL_POINTER) {

            xcb_generic_event_t* e = l->event;

            if (e != NULL_POINTER) {

                r = 1;
            }
        }
    }

    return r;
}

This would allow me to write an endless loop like:

while (!xcb_test_for_event(connection)) {

    sleep(t);
}

This is comparable to the old Xlib function:

int n = XEventsQueued(d, QueuedAfterReading);

which just checked the number of events in the event queue. The "XEventsQueued" function always returns immediately WITHOUT input/output, if there are events already in the queue.

Thanks Christian

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!