diff options
author | Michel Dänzer <michel.daenzer@amd.com> | 2018-09-28 17:24:17 +0200 |
---|---|---|
committer | Michel Dänzer <michel@daenzer.net> | 2018-09-28 17:24:17 +0200 |
commit | 823a0f8a820247b6c1e092f679b49cbdc2ea5c95 (patch) | |
tree | cc04b0b135d13fa46ea33fc31663136ec673c567 /src/xcb_io.c | |
parent | 406afe4b0f1b655c0db19bbc9a0c48da9a46acf5 (diff) | |
download | xorg-lib-libX11-823a0f8a820247b6c1e092f679b49cbdc2ea5c95.tar.gz |
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 <psychon@znc.in>
Reviewed-by: Uli Schlachter <psychon@znc.in>
Diffstat (limited to 'src/xcb_io.c')
-rw-r--r-- | src/xcb_io.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/xcb_io.c b/src/xcb_io.c index a32b7d75..6a12d150 100644 --- a/src/xcb_io.c +++ b/src/xcb_io.c @@ -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); } |