Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions player/clipboard/clipboard-wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "osdep/poll_wrapper.h"
#include "osdep/threads.h"

static const uint8_t MESSAGE_DEATH = 0;
static const uint8_t MESSAGE_CREATE_SOURCES = 1;

struct clipboard_wayland_data_offer {
struct ext_data_control_offer_v1 *offer;
char *mime_type;
Expand All @@ -36,7 +39,7 @@ struct clipboard_wayland_data_offer {
struct clipboard_wayland_priv {
mp_mutex lock;
// accessed by both threads
int death_pipe[2];
int message_pipe[2];
bstr selection_text;
bstr primary_selection_text;
bool data_changed;
Expand Down Expand Up @@ -298,7 +301,6 @@ static void create_data_sources(struct clipboard_wayland_priv *wl)
seat_create_data_source(seat, true);
}
}
wl_display_flush(wl->display);
}

static void clipboard_wayland_uninit(struct clipboard_wayland_priv *wl)
Expand Down Expand Up @@ -410,7 +412,7 @@ static bool clipboard_wayland_dispatch_events(struct clipboard_wayland_priv *wl,

struct pollfd fds[] = {
{.fd = wl->display_fd, .events = POLLIN },
{.fd = wl->death_pipe[0], .events = POLLIN },
{.fd = wl->message_pipe[0], .events = POLLIN },
{.fd = wl->selection_offer->fd, .events = POLLIN },
{.fd = wl->primary_selection_offer->fd, .events = POLLIN },
};
Expand All @@ -433,8 +435,14 @@ static bool clipboard_wayland_dispatch_events(struct clipboard_wayland_priv *wl,
return false;
}

if (fds[1].revents & POLLIN)
return false;
if (fds[1].revents & POLLIN) {
uint8_t msg = 0;
if (read(wl->message_pipe[0], &msg, sizeof(msg)) == sizeof(msg) && msg == MESSAGE_CREATE_SOURCES) {
create_data_sources(wl);
} else {
return false;
}
}

if (fds[2].revents & POLLIN)
get_selection_data(wl, wl->selection_offer, false);
Expand Down Expand Up @@ -471,15 +479,15 @@ static int init(struct clipboard_ctx *cl, struct clipboard_init_params *params)
{
cl->priv = talloc_zero(cl, struct clipboard_wayland_priv);
struct clipboard_wayland_priv *priv = cl->priv;
priv->death_pipe[0] = priv->death_pipe[1] = priv->display_fd = -1;
priv->message_pipe[0] = priv->message_pipe[1] = priv->display_fd = -1;
priv->log = mp_log_new(priv, cl->log, "wayland");
priv->selection_offer = talloc_zero(priv, struct clipboard_wayland_data_offer),
priv->primary_selection_offer = talloc_zero(priv, struct clipboard_wayland_data_offer),
priv->selection_offer->fd = priv->primary_selection_offer->fd = -1;
wl_list_init(&priv->seat_list);
mp_mutex_init(&priv->lock);

if (mp_make_wakeup_pipe(priv->death_pipe) < 0)
if (mp_make_wakeup_pipe(priv->message_pipe) < 0)
goto pipe_err;
if (!clipboard_wayland_init(priv))
goto init_err;
Expand All @@ -490,8 +498,8 @@ static int init(struct clipboard_ctx *cl, struct clipboard_init_params *params)
thread_err:
clipboard_wayland_uninit(priv);
init_err:
close(priv->death_pipe[0]);
close(priv->death_pipe[1]);
close(priv->message_pipe[0]);
close(priv->message_pipe[1]);
pipe_err:
mp_mutex_destroy(&priv->lock);
TA_FREEP(&cl->priv);
Expand All @@ -503,10 +511,10 @@ static void uninit(struct clipboard_ctx *cl)
struct clipboard_wayland_priv *priv = cl->priv;
if (!priv)
return;
(void)write(priv->death_pipe[1], &(char){0}, 1);
(void)write(priv->message_pipe[1], &MESSAGE_DEATH, sizeof(MESSAGE_DEATH));
mp_thread_join(priv->thread);
close(priv->death_pipe[0]);
close(priv->death_pipe[1]);
close(priv->message_pipe[0]);
close(priv->message_pipe[1]);
mp_mutex_destroy(&priv->lock);
TA_FREEP(&cl->priv);
}
Expand Down Expand Up @@ -568,7 +576,7 @@ static int set_data(struct clipboard_ctx *cl, struct clipboard_access_params *pa
break;
}
mp_mutex_unlock(&priv->lock);
create_data_sources(priv);
(void)write(priv->message_pipe[1], &MESSAGE_CREATE_SOURCES, sizeof(MESSAGE_CREATE_SOURCES));
return CLIPBOARD_SUCCESS;
}

Expand Down