소스 검색

wayland: Roundtrip when receiving data offers

Otherwise, the receive operation might not have completed, resulting in there being no data to read.
Frank Praznik 1 개월 전
부모
커밋
9c7c11f259
2개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 14 8
      src/video/wayland/SDL_waylanddatamanager.c
  2. 1 0
      src/video/wayland/SDL_waylandsym.h

+ 14 - 8
src/video/wayland/SDL_waylanddatamanager.c

@@ -370,13 +370,16 @@ void *Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
     } else if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1) {
         SDL_SetError("Could not read pipe");
     } else {
-        wl_data_offer_receive(offer->offer, mime_type, pipefd[1]);
-
-        // TODO: Needs pump and flush?
-        WAYLAND_wl_display_flush(data_device->video_data->display);
+        struct wl_event_queue *queue = WAYLAND_wl_display_create_queue(data_device->video_data->display);
+        WAYLAND_wl_proxy_set_queue((struct wl_proxy *)offer->offer, queue);
 
+        wl_data_offer_receive(offer->offer, mime_type, pipefd[1]);
         close(pipefd[1]);
 
+        WAYLAND_wl_display_roundtrip_queue(data_device->video_data->display, queue);
+        WAYLAND_wl_proxy_set_queue((struct wl_proxy *)offer->offer, NULL);
+        WAYLAND_wl_event_queue_destroy(queue);
+
         while (read_pipe(pipefd[0], &buffer, length) > 0) {
         }
         close(pipefd[0]);
@@ -406,13 +409,16 @@ void *Wayland_primary_selection_offer_receive(SDL_WaylandPrimarySelectionOffer *
     } else if (pipe2(pipefd, O_CLOEXEC | O_NONBLOCK) == -1) {
         SDL_SetError("Could not read pipe");
     } else {
-        zwp_primary_selection_offer_v1_receive(offer->offer, mime_type, pipefd[1]);
-
-        // TODO: Needs pump and flush?
-        WAYLAND_wl_display_flush(primary_selection_device->video_data->display);
+        struct wl_event_queue *queue = WAYLAND_wl_display_create_queue(primary_selection_device->video_data->display);
+        WAYLAND_wl_proxy_set_queue((struct wl_proxy *)offer->offer, queue);
 
+        zwp_primary_selection_offer_v1_receive(offer->offer, mime_type, pipefd[1]);
         close(pipefd[1]);
 
+        WAYLAND_wl_display_roundtrip_queue(primary_selection_device->video_data->display, queue);
+        WAYLAND_wl_proxy_set_queue((struct wl_proxy *)offer->offer, NULL);
+        WAYLAND_wl_event_queue_destroy(queue);
+
         while (read_pipe(pipefd[0], &buffer, length) > 0) {
         }
         close(pipefd[0]);

+ 1 - 0
src/video/wayland/SDL_waylandsym.h

@@ -65,6 +65,7 @@ SDL_WAYLAND_SYM(void, wl_display_cancel_read, (struct wl_display *))
 SDL_WAYLAND_SYM(int, wl_display_get_error, (struct wl_display *))
 SDL_WAYLAND_SYM(int, wl_display_flush, (struct wl_display *))
 SDL_WAYLAND_SYM(int, wl_display_roundtrip, (struct wl_display *))
+SDL_WAYLAND_SYM(int, wl_display_roundtrip_queue, (struct wl_display *, struct wl_event_queue *))
 SDL_WAYLAND_SYM(struct wl_event_queue *, wl_display_create_queue, (struct wl_display *))
 SDL_WAYLAND_SYM(void, wl_event_queue_destroy, (struct wl_event_queue *))
 SDL_WAYLAND_SYM(void, wl_log_set_handler_client, (wl_log_func_t))