3

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

1 Answer 1

3

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*.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you. care to look my on another XCB question here stackoverflow.com/questions/65540910/…?
I saw that question, but I think it is unanswerable, sorry. If you get only zero values, that means that the property must have been set with zero values. From your code template, it looks like you handle all other cases. My best debugging idea would be: Try running your program under xtrace and check if the property really has zero values: xtrace.sourceforge.net
I managed to solve the another's question problem. I got tied to the linked SO answer. And the answer seems a little off the rails. The solution is to wait for XCB_PROPERTY_NOTIFY event and compare the recieved atom with a _NET_FRAME_EXTENTS atom. In case of that specific event is recieved, the WM has set the desired properties. My original solution may get the property value earlier before WM sets the property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.