22#include "../../SDL_internal.h"
24#if SDL_VIDEO_DRIVER_WAYLAND
33#include "../../core/unix/SDL_poll.h"
41write_pipe(
int fd,
const void*
buffer,
size_t total_length,
size_t *pos)
44 ssize_t bytes_written = 0;
45 ssize_t
length = total_length - *pos;
49 struct timespec zerotime = {0};
53 sigemptyset(&sig_set);
54 sigaddset(&sig_set, SIGPIPE);
56#if SDL_THREADS_DISABLED
57 sigprocmask(SIG_BLOCK, &sig_set, &old_sig_set);
59 pthread_sigmask(SIG_BLOCK, &sig_set, &old_sig_set);
64 }
else if (ready < 0) {
71 if (bytes_written > 0) {
72 *pos += bytes_written;
76 sigtimedwait(&sig_set, 0, &zerotime);
78#if SDL_THREADS_DISABLED
79 sigprocmask(SIG_SETMASK, &old_sig_set,
NULL);
81 pthread_sigmask(SIG_SETMASK, &old_sig_set,
NULL);
88read_pipe(
int fd,
void**
buffer,
size_t* total_length,
SDL_bool null_terminate)
91 void* output_buffer =
NULL;
93 size_t new_buffer_length = 0;
94 ssize_t bytes_read = 0;
101 }
else if (ready < 0) {
104 bytes_read = read(
fd, temp,
sizeof(temp));
107 if (bytes_read > 0) {
109 *total_length += bytes_read;
112 new_buffer_length = *total_length + 1;
114 new_buffer_length = *total_length;
118 output_buffer =
SDL_malloc(new_buffer_length);
123 if (output_buffer ==
NULL) {
139#define MIME_LIST_SIZE 4
141static const char* mime_conversion_list[MIME_LIST_SIZE][2] = {
151 const char *found = mime_type;
156 if (strcmp(mime_conversion_list[
index][0], mime_type) == 0) {
157 found = mime_conversion_list[
index][1];
166mime_data_list_find(
struct wl_list* list,
167 const char* mime_type)
172 wl_list_for_each(mime_list, list, link) {
173 if (strcmp(mime_list->
mime_type, mime_type) == 0) {
182mime_data_list_add(
struct wl_list* list,
183 const char* mime_type,
187 size_t mime_type_length = 0;
191 mime_data = mime_data_list_find(list, mime_type);
193 if (mime_data ==
NULL) {
194 mime_data =
SDL_calloc(1,
sizeof(*mime_data));
195 if (mime_data ==
NULL) {
198 WAYLAND_wl_list_insert(list, &(mime_data->
link));
200 mime_type_length = strlen(mime_type) + 1;
222mime_data_list_free(
struct wl_list *list)
227 wl_list_for_each_safe(mime_data, next, list, link) {
240 const char *mime_type,
int fd)
242 size_t written_bytes = 0;
247 mime_data = mime_data_list_find(&
source->mimes,
254 while (write_pipe(
fd, mime_data->
data, mime_data->
length,
255 &written_bytes) > 0);
257 status = written_bytes;
263 const char *mime_type,
270 if (internal_buffer ==
NULL) {
274 status = mime_data_list_add(&
source->mimes, mime_type,
283 const char *mime_type)
288 found = mime_data_list_find(&
source->mimes, mime_type) !=
NULL;
295 size_t *
length,
const char* mime_type,
305 mime_data = mime_data_list_find(&
source->mimes, mime_type);
306 if (mime_data !=
NULL && mime_data->
length > 0) {
325 mime_data_list_free(&
source->mimes);
332 size_t *
length,
const char* mime_type,
345 }
else if (pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) {
355 while (read_pipe(pipefd[0], &
buffer,
length, null_terminate) > 0);
363 const char* mime_type)
365 return mime_data_list_add(&offer->
mimes, mime_type,
NULL, 0);
371 const char *mime_type)
376 found = mime_data_list_find(&offer->
mimes, mime_type) !=
NULL;
386 mime_data_list_free(&offer->
mimes);
410 size_t num_offers = 0;
413 if (data_device ==
NULL) {
420 wl_list_for_each(mime_data, &(
source->mimes), link) {
426 if (strcmp(mime_conversion_list[
index][1], mime_data->
mime_type) == 0) {
428 mime_conversion_list[
index][0]);
436 if (num_offers == 0) {
458 if (data_device !=
NULL) {
#define SDL_OutOfMemory()
GLsizei GLsizei GLchar * source
GLuint GLsizei GLsizei * length
int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, const char *mime_type)
int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, SDL_WaylandDataSource *source)
void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer)
void * Wayland_data_source_get_data(SDL_WaylandDataSource *source, size_t *length, const char *mime_type, SDL_bool null_terminate)
ssize_t Wayland_data_source_send(SDL_WaylandDataSource *source, const char *mime_type, int fd)
int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device)
int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
void Wayland_data_source_destroy(SDL_WaylandDataSource *source)
const char * Wayland_convert_mime_type(const char *mime_type)
SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
void * Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, size_t *length, const char *mime_type, SDL_bool null_terminate)
int Wayland_data_device_set_serial(SDL_WaylandDataDevice *device, uint32_t serial)
int Wayland_data_source_add_data(SDL_WaylandDataSource *source, const char *mime_type, const void *buffer, size_t length)
static void wl_data_device_set_selection(struct wl_data_device *wl_data_device, struct wl_data_source *source, uint32_t serial)
static void wl_data_offer_destroy(struct wl_data_offer *wl_data_offer)
static void wl_data_offer_receive(struct wl_data_offer *wl_data_offer, const char *mime_type, int32_t fd)
static void wl_data_source_offer(struct wl_data_source *wl_data_source, const char *mime_type)
static void wl_data_source_destroy(struct wl_data_source *wl_data_source)
struct wl_display * display
SDL_VideoData * video_data
SDL_WaylandDataSource * selection_source
struct wl_data_device * data_device
uint32_t selection_serial
struct wl_data_offer * offer
struct wl_data_source * source