History

video/out/wayland_common: generalize check_fd

nanahi committed 1 year ago

Commit fa3a1671 parent 23b8fb31 file · +19 −18Browse files

Unified · Split

video/out/wayland_common.c+19−18
@@ -1866,9 +1866,8 @@ static void destroy_offer(struct vo_wayland_data_offer *o) · 1865 unmodified lines
18661866 *o = (struct vo_wayland_data_offer){.fd = -1, .action = -1};
18671867 }
18681868
1869−static void check_dnd_fd(struct vo_wayland_state *wl)
1869+static void check_fd(struct vo_wayland_state *wl, struct vo_wayland_data_offer *o, bool is_dnd)
18701870 {
1871− struct vo_wayland_data_offer *o = wl->dnd_offer;
18721871 if (o->fd == -1)
18731872 return;
18741873
@@ -1879,41 +1878,43 @@ static void check_dnd_fd(struct vo_wayland_state *wl) · 4 unmodified lines
18791878 if (fdp.revents & POLLIN) {
18801879 ssize_t data_read = 0;
18811880 const size_t chunk_size = 256;
1882− bstr file_list = {
1883− .start = talloc_zero_size(NULL, chunk_size),
1881+ bstr content = {
1882+ .start = talloc_zero_size(wl, chunk_size),
18841883 };
18851884
18861885 while (1) {
1887− data_read = read(o->fd, file_list.start + file_list.len, chunk_size);
1886+ data_read = read(o->fd, content.start + content.len, chunk_size);
18881887 if (data_read == -1 && errno == EINTR)
18891888 continue;
18901889 else if (data_read <= 0)
18911890 break;
1892− file_list.len += data_read;
1893− file_list.start = talloc_realloc_size(NULL, file_list.start, file_list.len + chunk_size);
1894− memset(file_list.start + file_list.len, 0, chunk_size);
1891+ content.len += data_read;
1892+ content.start = talloc_realloc_size(wl, content.start, content.len + chunk_size);
1893+ memset(content.start + content.len, 0, chunk_size);
18951894 }
18961895
18971896 if (data_read == -1) {
1898− MP_VERBOSE(wl, "DND aborted (read error)\n");
1897+ MP_VERBOSE(wl, "data offer aborted (read error)\n");
18991898 } else {
1900− MP_VERBOSE(wl, "Read %zu bytes from the DND fd\n", file_list.len);
1899+ MP_VERBOSE(wl, "Read %zu bytes from the data offer fd\n", content.len);
19011900
1902− if (o->offer)
1903− wl_data_offer_finish(o->offer);
1901+ if (is_dnd) {
1902+ if (o->offer)
1903+ wl_data_offer_finish(o->offer);
19041904
1905− assert(o->action >= 0);
1906− mp_event_drop_mime_data(wl->vo->input_ctx, o->mime_type,
1907− file_list, o->action);
1905+ assert(o->action >= 0);
1906+ mp_event_drop_mime_data(wl->vo->input_ctx, o->mime_type,
1907+ content, o->action);
1908+ }
19081909 }
19091910
1910− talloc_free(file_list.start);
1911+ talloc_free(content.start);
19111912 destroy_offer(o);
19121913 }
19131914
19141915 if (fdp.revents & (POLLIN | POLLERR | POLLHUP)) {
19151916 if (o->action >= 0)
1916− MP_VERBOSE(wl, "DND aborted (hang up or error)\n");
1917+ MP_VERBOSE(wl, "data offer aborted (hang up or error)\n");
19171918 destroy_offer(o);
19181919 }
19191920 }
@@ -2858,7 +2859,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) · 938 unmodified lines
28582859
28592860 switch (request) {
28602861 case VOCTRL_CHECK_EVENTS: {
2861− check_dnd_fd(wl);
2862+ check_fd(wl, wl->dnd_offer, true);
28622863 *events |= wl->pending_vo_events;
28632864 if (*events & VO_EVENT_RESIZE) {
28642865 *events |= VO_EVENT_EXPOSE;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t