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
1866 *o = (struct vo_wayland_data_offer){.fd = -1, .action = -1};1866 *o = (struct vo_wayland_data_offer){.fd = -1, .action = -1};
1867}1867}
1868 1868
1869static void check_dnd_fd(struct vo_wayland_state *wl)1869static void check_fd(struct vo_wayland_state *wl, struct vo_wayland_data_offer *o, bool is_dnd)
1870{1870{
1871 struct vo_wayland_data_offer *o = wl->dnd_offer;
1872 if (o->fd == -1)1871 if (o->fd == -1)
1873 return;1872 return;
1874 1873
@@ -1879,41 +1878,43 @@ static void check_dnd_fd(struct vo_wayland_state *wl) · 4 unmodified lines
1879 if (fdp.revents & POLLIN) {1878 if (fdp.revents & POLLIN) {
1880 ssize_t data_read = 0;1879 ssize_t data_read = 0;
1881 const size_t chunk_size = 256;1880 const size_t chunk_size = 256;
1882 bstr file_list = {1881 bstr content = {
1883 .start = talloc_zero_size(NULL, chunk_size),1882 .start = talloc_zero_size(wl, chunk_size),
1884 };1883 };
1885 1884
1886 while (1) {1885 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);
1888 if (data_read == -1 && errno == EINTR)1887 if (data_read == -1 && errno == EINTR)
1889 continue;1888 continue;
1890 else if (data_read <= 0)1889 else if (data_read <= 0)
1891 break;1890 break;
1892 file_list.len += data_read;1891 content.len += data_read;
1893 file_list.start = talloc_realloc_size(NULL, file_list.start, file_list.len + chunk_size);1892 content.start = talloc_realloc_size(wl, content.start, content.len + chunk_size);
1894 memset(file_list.start + file_list.len, 0, chunk_size);1893 memset(content.start + content.len, 0, chunk_size);
1895 }1894 }
1896 1895
1897 if (data_read == -1) {1896 if (data_read == -1) {
1898 MP_VERBOSE(wl, "DND aborted (read error)\n");1897 MP_VERBOSE(wl, "data offer aborted (read error)\n");
1899 } else {1898 } 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);
1901 1900
1902 if (o->offer)1901 if (is_dnd) {
1903 wl_data_offer_finish(o->offer);1902 if (o->offer)
1903 wl_data_offer_finish(o->offer);
1904 1904
1905 assert(o->action >= 0);1905 assert(o->action >= 0);
1906 mp_event_drop_mime_data(wl->vo->input_ctx, o->mime_type,1906 mp_event_drop_mime_data(wl->vo->input_ctx, o->mime_type,
1907 file_list, o->action);1907 content, o->action);
1908 }
1908 }1909 }
1909 1910
1910 talloc_free(file_list.start);1911 talloc_free(content.start);
1911 destroy_offer(o);1912 destroy_offer(o);
1912 }1913 }
1913 1914
1914 if (fdp.revents & (POLLIN | POLLERR | POLLHUP)) {1915 if (fdp.revents & (POLLIN | POLLERR | POLLHUP)) {
1915 if (o->action >= 0)1916 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");
1917 destroy_offer(o);1918 destroy_offer(o);
1918 }1919 }
1919}1920}
@@ -2858,7 +2859,7 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) · 938 unmodified lines
2858 2859
2859 switch (request) {2860 switch (request) {
2860 case VOCTRL_CHECK_EVENTS: {2861 case VOCTRL_CHECK_EVENTS: {
2861 check_dnd_fd(wl);2862 check_fd(wl, wl->dnd_offer, true);
2862 *events |= wl->pending_vo_events;2863 *events |= wl->pending_vo_events;
2863 if (*events & VO_EVENT_RESIZE) {2864 if (*events & VO_EVENT_RESIZE) {
2864 *events |= VO_EVENT_EXPOSE;2865 *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