Commit 823a0f8a authored by Michel Dänzer's avatar Michel Dänzer Committed by Michel Dänzer

poll_for_event: Allow using xcb_poll_for_queued_event

It avoids reading from the display connection again in cases where that
was already done.
Suggested-by: Uli Schlachter's avatarUli Schlachter <psychon@znc.in>
Reviewed-by: Uli Schlachter's avatarUli Schlachter <psychon@znc.in>
parent 406afe4b
......@@ -230,7 +230,7 @@ static void widen(uint64_t *wide, unsigned int narrow)
* variable for that thread to process the response and wake us up.
*/
static xcb_generic_reply_t *poll_for_event(Display *dpy)
static xcb_generic_reply_t *poll_for_event(Display *dpy, Bool queued_only)
{
/* Make sure the Display's sequence numbers are valid */
require_socket(dpy);
......@@ -238,8 +238,12 @@ static xcb_generic_reply_t *poll_for_event(Display *dpy)
/* Precondition: This thread can safely get events from XCB. */
assert(dpy->xcb->event_owner == XlibOwnsEventQueue && !dpy->xcb->event_waiter);
if(!dpy->xcb->next_event)
dpy->xcb->next_event = xcb_poll_for_event(dpy->xcb->connection);
if(!dpy->xcb->next_event) {
if(queued_only)
dpy->xcb->next_event = xcb_poll_for_queued_event(dpy->xcb->connection);
else
dpy->xcb->next_event = xcb_poll_for_event(dpy->xcb->connection);
}
if(dpy->xcb->next_event)
{
......@@ -271,7 +275,7 @@ static xcb_generic_reply_t *poll_for_response(Display *dpy)
void *response;
xcb_generic_error_t *error;
PendingRequest *req;
while(!(response = poll_for_event(dpy)) &&
while(!(response = poll_for_event(dpy, False)) &&
(req = dpy->xcb->pending_requests) &&
!req->reply_waiter)
{
......@@ -281,7 +285,7 @@ static xcb_generic_reply_t *poll_for_response(Display *dpy)
&response, &error)) {
/* xcb_poll_for_reply64 may have read events even if
* there is no reply. */
response = poll_for_event(dpy);
response = poll_for_event(dpy, True);
break;
}
......@@ -626,7 +630,7 @@ Status _XReply(Display *dpy, xReply *rep, int extra, Bool discard)
{ /* need braces around ConditionWait */
ConditionWait(dpy, dpy->xcb->event_notify);
}
while((event = poll_for_event(dpy)))
while((event = poll_for_event(dpy, True)))
handle_response(dpy, event, True);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment