I read the documentation on xcb_poll_for_event and it says that the function
returns the next event or error from the server...
Here is a prototype that is used on my system:
xcb_generic_event_t* xcb_poll_for_event(xcb_connection_t* c)
The question is simple, how to determine if the return was an error and get some error code subsequently?
I ask because, as I understand, it is not a habit of XCB to "just cast" a return pointer to some other pointer. The xcb_generic_event_t struct does have a response_type field, but no documentation avaible on that field. Can someone share an example?
Update
The x.org web has few examples about handling erros in the event loop. On of the examples state:
For requests which have no reply (for example xcb_map_window), errors will be delivered to the event loop (you will receive an X11 event of type 0 when calling xcb_poll_for_event)
The code of the example with the error handling:
if (event->response_type == 0) {
fprintf("Received X11 error %d\n", error->error_code);
free(event);
continue;
}
But again, where did this error variable came from? It is not declared/defined in any place of the example.
Relevant link to the documentation: xcb-requests
I ask because, as I understand, it is not a habit of XCB to "just cast" a return pointer to some other pointer.
Yes, it is. For errors and events, you get a pointer to some generic struct and you then have to figure out the right type yourself and cast the pointer. Error have response_type == 0 and events have a number that says exactly which kind of event it is (except for some extensions where all events from that extension have the same response_type and another field then contains the "subtype" of event).
So, when you get an event with response_type == 0, cast the pointer to xcb_generic_error_t*.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With