22 #include "../../SDL_internal.h" 24 #if SDL_VIDEO_DRIVER_WAYLAND 33 #include "../../core/unix/SDL_poll.h" 41 write_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 pthread_sigmask(SIG_BLOCK, &sig_set, &old_sig_set);
60 }
else if (ready < 0) {
64 bytes_written = write(fd, (
Uint8*)buffer + *pos,
SDL_min(length, PIPE_BUF));
67 if (bytes_written > 0) {
68 *pos += bytes_written;
72 sigtimedwait(&sig_set, 0, &zerotime);
73 pthread_sigmask(SIG_SETMASK, &old_sig_set,
NULL);
79 read_pipe(
int fd,
void** buffer,
size_t* total_length,
SDL_bool null_terminate)
82 void* output_buffer =
NULL;
84 size_t new_buffer_length = 0;
85 ssize_t bytes_read = 0;
92 }
else if (ready < 0) {
95 bytes_read = read(fd, temp,
sizeof(temp));
100 *total_length += bytes_read;
103 new_buffer_length = *total_length + 1;
105 new_buffer_length = *total_length;
108 if (*buffer ==
NULL) {
109 output_buffer =
SDL_malloc(new_buffer_length);
111 output_buffer =
SDL_realloc(*buffer, new_buffer_length);
114 if (output_buffer ==
NULL) {
123 *buffer = output_buffer;
130 #define MIME_LIST_SIZE 4 132 static const char* mime_conversion_list[MIME_LIST_SIZE][2] = {
142 const char *found = mime_type;
146 for (index = 0; index < MIME_LIST_SIZE; ++
index) {
147 if (strcmp(mime_conversion_list[index][0], mime_type) == 0) {
148 found = mime_conversion_list[
index][1];
157 mime_data_list_find(
struct wl_list* list,
158 const char* mime_type)
163 wl_list_for_each(mime_list, list, link) {
164 if (strcmp(mime_list->
mime_type, mime_type) == 0) {
173 mime_data_list_add(
struct wl_list* list,
174 const char* mime_type,
175 void* buffer,
size_t length)
178 size_t mime_type_length = 0;
182 mime_data = mime_data_list_find(list, mime_type);
184 if (mime_data ==
NULL) {
185 mime_data =
SDL_calloc(1,
sizeof(*mime_data));
186 if (mime_data ==
NULL) {
189 WAYLAND_wl_list_insert(list, &(mime_data->
link));
191 mime_type_length = strlen(mime_type) + 1;
201 if (mime_data !=
NULL && buffer !=
NULL && length > 0) {
213 mime_data_list_free(
struct wl_list *list)
218 wl_list_for_each_safe(mime_data, next, list, link) {
231 const char *mime_type,
int fd)
233 size_t written_bytes = 0;
238 mime_data = mime_data_list_find(&source->
mimes,
245 while (write_pipe(fd, mime_data->
data, mime_data->
length,
246 &written_bytes) > 0);
248 status = written_bytes;
254 const char *mime_type,
261 if (internal_buffer ==
NULL) {
265 status = mime_data_list_add(&source->
mimes, mime_type,
266 internal_buffer, length);
274 const char *mime_type)
278 if (source !=
NULL) {
279 found = mime_data_list_find(&source->
mimes, mime_type) !=
NULL;
286 size_t *length,
const char* mime_type,
293 if (source ==
NULL) {
296 mime_data = mime_data_list_find(&source->
mimes, mime_type);
297 if (mime_data !=
NULL && mime_data->
length > 0) {
299 if (buffer ==
NULL) {
302 *length = mime_data->
length;
314 if (source !=
NULL) {
316 mime_data_list_free(&source->
mimes);
323 size_t *length,
const char* mime_type,
336 }
else if (pipe2(pipefd, O_CLOEXEC|O_NONBLOCK) == -1) {
346 while (read_pipe(pipefd[0], &buffer, length, null_terminate) > 0);
354 const char* mime_type)
356 return mime_data_list_add(&offer->
mimes, mime_type,
NULL, 0);
362 const char *mime_type)
367 found = mime_data_list_find(&offer->
mimes, mime_type) !=
NULL;
377 mime_data_list_free(&offer->
mimes);
401 size_t num_offers = 0;
404 if (data_device ==
NULL) {
406 }
else if (source ==
NULL) {
411 wl_list_for_each(mime_data, &(source->
mimes), link) {
416 for (index = 0; index < MIME_LIST_SIZE; ++
index) {
417 if (strcmp(mime_conversion_list[index][1], mime_data->
mime_type) == 0) {
419 mime_conversion_list[index][0]);
427 if (num_offers == 0) {
449 if (data_device !=
NULL) {
ssize_t Wayland_data_source_send(SDL_WaylandDataSource *source, const char *mime_type, int fd)
int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, SDL_WaylandDataSource *source)
int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
struct wl_display * display
static void wl_data_source_offer(struct wl_data_source *wl_data_source, const char *mime_type)
struct wl_data_source * source
SDL_WaylandDataSource * selection_source
static void wl_data_offer_destroy(struct wl_data_offer *wl_data_offer)
SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, const char *mime_type)
static void wl_data_offer_receive(struct wl_data_offer *wl_data_offer, const char *mime_type, int32_t fd)
void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer)
void Wayland_data_source_destroy(SDL_WaylandDataSource *source)
int Wayland_data_device_set_serial(SDL_WaylandDataDevice *device, uint32_t serial)
GLsizei GLsizei GLchar * source
uint32_t selection_serial
int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
SDL_VideoData * video_data
#define SDL_OutOfMemory()
const char * Wayland_convert_mime_type(const char *mime_type)
struct wl_data_device * data_device
struct wl_data_offer * offer
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_source_destroy(struct wl_data_source *wl_data_source)
int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device)
GLuint GLsizei GLsizei * length
void * Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, size_t *length, const char *mime_type, SDL_bool null_terminate)
int Wayland_data_source_add_data(SDL_WaylandDataSource *source, const char *mime_type, const void *buffer, size_t length)
void * Wayland_data_source_get_data(SDL_WaylandDataSource *source, size_t *length, const char *mime_type, SDL_bool null_terminate)