diff --git a/src/wayland-client.c b/src/wayland-client.c index 8ced6cc..9077338 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -552,9 +552,9 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue) } -WL_EXPORT int -wl_display_dispatch_queue(struct wl_display *display, - struct wl_event_queue *queue) +static int +dispatch_queue(struct wl_display *display, + struct wl_event_queue *queue, int block) { int len, size; @@ -563,7 +563,7 @@ wl_display_dispatch_queue(struct wl_display *display, /* FIXME: Handle flush errors, EAGAIN... */ wl_connection_flush(display->connection); - if (wl_list_empty(&queue->event_list) && + if (block && wl_list_empty(&queue->event_list) && pthread_equal(display->display_thread, pthread_self())) { len = wl_connection_read(display->connection); if (len == -1) { @@ -576,7 +576,7 @@ wl_display_dispatch_queue(struct wl_display *display, break; len -= size; } - } else if (wl_list_empty(&queue->event_list)) { + } else if (block && wl_list_empty(&queue->event_list)) { pthread_cond_wait(&queue->cond, &display->mutex); } @@ -588,12 +588,27 @@ wl_display_dispatch_queue(struct wl_display *display, return 0; } +WL_EXPORT int +wl_display_dispatch_queue(struct wl_display *display, + struct wl_event_queue *queue) +{ + return dispatch_queue(display, queue, 1); +} + WL_EXPORT int wl_display_dispatch(struct wl_display *display) { display->display_thread = pthread_self(); - return wl_display_dispatch_queue(display, &display->queue); + return dispatch_queue(display, &display->queue, 1); +} + +WL_EXPORT int +wl_display_dispatch_pending(struct wl_display *display) +{ + display->display_thread = pthread_self(); + + return dispatch_queue(display, &display->queue, 0); } WL_EXPORT int diff --git a/src/wayland-client.h b/src/wayland-client.h index cb1be9c..a73566e 100644 --- a/src/wayland-client.h +++ b/src/wayland-client.h @@ -60,6 +60,7 @@ int wl_display_get_fd(struct wl_display *display); int wl_display_dispatch(struct wl_display *display); int wl_display_dispatch_queue(struct wl_display *display, struct wl_event_queue *queue); +int wl_display_dispatch_pending(struct wl_display *display); int wl_display_flush(struct wl_display *display); void wl_display_roundtrip(struct wl_display *display);