Skip to content

Commit 05d38eb

Browse files
committed
clipboard-wayland: create data sources in clipboard thread
Currently, it is done in set_data which is called by core. It was never meant to do so and it is not thread safe when data sources are created while a seat is being added/removed. Fix this by passing a message to clipboard thread instead so that it is done in a thread safe way.
1 parent 42e5501 commit 05d38eb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

player/clipboard/clipboard-wayland.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "osdep/threads.h"
2929

3030
static const char MESSAGE_DEATH = 0;
31+
static const char MESSAGE_CREATE_SOURCES = 1;
3132

3233
struct clipboard_wayland_data_offer {
3334
struct ext_data_control_offer_v1 *offer;
@@ -435,8 +436,14 @@ static bool clipboard_wayland_dispatch_events(struct clipboard_wayland_priv *wl,
435436
return false;
436437
}
437438

438-
if (fds[1].revents & POLLIN)
439-
return false;
439+
if (fds[1].revents & POLLIN) {
440+
char msg = 0;
441+
if (read(wl->message_pipe[0], &msg, 1) == 1 && msg == MESSAGE_CREATE_SOURCES) {
442+
create_data_sources(wl);
443+
} else {
444+
return false;
445+
}
446+
}
440447

441448
if (fds[2].revents & POLLIN)
442449
get_selection_data(wl, wl->selection_offer, false);
@@ -570,7 +577,7 @@ static int set_data(struct clipboard_ctx *cl, struct clipboard_access_params *pa
570577
break;
571578
}
572579
mp_mutex_unlock(&priv->lock);
573-
create_data_sources(priv);
580+
(void)write(priv->message_pipe[1], &(char){MESSAGE_CREATE_SOURCES}, 1);
574581
return CLIPBOARD_SUCCESS;
575582
}
576583

0 commit comments

Comments
 (0)