wlroots-hyprland/xwayland/selection.c

704 lines
19 KiB
C
Raw Normal View History

2017-11-22 00:09:25 +01:00
#define _XOPEN_SOURCE 700
#include <stdlib.h>
2017-11-22 00:25:21 +01:00
#include <unistd.h>
2017-11-22 00:09:25 +01:00
#include <string.h>
2017-11-22 14:10:06 +01:00
#include <assert.h>
2017-11-20 13:23:17 +01:00
#include <xcb/xfixes.h>
2017-11-21 17:19:55 +01:00
#include <fcntl.h>
2017-11-20 13:23:17 +01:00
#include "wlr/util/log.h"
2017-11-21 17:19:55 +01:00
#include "wlr/types/wlr_data_device.h"
#include "wlr/xwm.h"
2017-11-20 13:23:17 +01:00
2017-11-22 14:10:06 +01:00
static const size_t incr_chunk_size = 64 * 1024;
static void xwm_send_selection_notify(struct wlr_xwm *xwm,
xcb_atom_t property) {
xcb_selection_notify_event_t selection_notify;
memset(&selection_notify, 0, sizeof selection_notify);
selection_notify.response_type = XCB_SELECTION_NOTIFY;
selection_notify.sequence = 0;
selection_notify.time = xwm->selection_request.time;
selection_notify.requestor = xwm->selection_request.requestor;
selection_notify.selection = xwm->selection_request.selection;
selection_notify.target = xwm->selection_request.target;
selection_notify.property = property;
xcb_send_event(xwm->xcb_conn, 0, // propagate
xwm->selection_request.requestor,
XCB_EVENT_MASK_NO_EVENT, (char *)&selection_notify);
}
static int xwm_flush_source_data(struct wlr_xwm *xwm)
{
xcb_change_property(xwm->xcb_conn,
XCB_PROP_MODE_REPLACE,
xwm->selection_request.requestor,
xwm->selection_request.property,
xwm->selection_target,
8, // format
xwm->source_data.size,
xwm->source_data.data);
xwm->selection_property_set = 1;
int length = xwm->source_data.size;
xwm->source_data.size = 0;
return length;
}
static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
struct wlr_xwm *xwm = data;
void *p;
int current = xwm->source_data.size;
if (xwm->source_data.size < incr_chunk_size) {
p = wl_array_add(&xwm->source_data, incr_chunk_size);
} else {
p = (char *) xwm->source_data.data + xwm->source_data.size;
2017-11-20 14:51:40 +01:00
}
2017-11-22 14:10:06 +01:00
int available = xwm->source_data.alloc - current;
int len = read(fd, p, available);
if (len == -1) {
wlr_log(L_ERROR, "read error from data source: %m");
2017-11-22 14:10:06 +01:00
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
wl_event_source_remove(xwm->property_source);
xwm->property_source = NULL;
close(fd);
wl_array_release(&xwm->source_data);
}
wlr_log(L_DEBUG, "read %d (available %d, mask 0x%x) bytes: \"%.*s\"",
2017-11-22 14:10:06 +01:00
len, available, mask, len, (char *) p);
xwm->source_data.size = current + len;
if (xwm->source_data.size >= incr_chunk_size) {
if (!xwm->incr) {
wlr_log(L_DEBUG, "got %zu bytes, starting incr",
2017-11-22 14:10:06 +01:00
xwm->source_data.size);
xwm->incr = 1;
xcb_change_property(xwm->xcb_conn,
XCB_PROP_MODE_REPLACE,
xwm->selection_request.requestor,
xwm->selection_request.property,
xwm->atoms[INCR],
32, /* format */
1, &incr_chunk_size);
xwm->selection_property_set = 1;
xwm->flush_property_on_delete = 1;
wl_event_source_remove(xwm->property_source);
xwm->property_source = NULL;
xwm_send_selection_notify(xwm, xwm->selection_request.property);
} else if (xwm->selection_property_set) {
wlr_log(L_DEBUG, "got %zu bytes, waiting for "
"property delete", xwm->source_data.size);
2017-11-22 14:10:06 +01:00
xwm->flush_property_on_delete = 1;
wl_event_source_remove(xwm->property_source);
xwm->property_source = NULL;
} else {
wlr_log(L_DEBUG, "got %zu bytes, "
"property deleted, setting new property",
2017-11-22 14:10:06 +01:00
xwm->source_data.size);
xwm_flush_source_data(xwm);
}
} else if (len == 0 && !xwm->incr) {
wlr_log(L_DEBUG, "non-incr transfer complete");
2017-11-22 14:10:06 +01:00
/* Non-incr transfer all done. */
xwm_flush_source_data(xwm);
xwm_send_selection_notify(xwm, xwm->selection_request.property);
xcb_flush(xwm->xcb_conn);
wl_event_source_remove(xwm->property_source);
xwm->property_source = NULL;
close(fd);
wl_array_release(&xwm->source_data);
xwm->selection_request.requestor = XCB_NONE;
} else if (len == 0 && xwm->incr) {
wlr_log(L_DEBUG, "incr transfer complete");
2017-11-22 14:10:06 +01:00
xwm->flush_property_on_delete = 1;
if (xwm->selection_property_set) {
wlr_log(L_DEBUG, "got %zu bytes, waiting for "
"property delete", xwm->source_data.size);
2017-11-22 14:10:06 +01:00
} else {
wlr_log(L_DEBUG, "got %zu bytes, "
"property deleted, setting new property",
2017-11-22 14:10:06 +01:00
xwm->source_data.size);
xwm_flush_source_data(xwm);
}
xcb_flush(xwm->xcb_conn);
wl_event_source_remove(xwm->property_source);
xwm->property_source = NULL;
close(xwm->data_source_fd);
xwm->data_source_fd = -1;
close(fd);
} else {
wlr_log(L_DEBUG, "nothing happened, buffered the bytes");
2017-11-22 14:10:06 +01:00
}
return 1;
}
static void xwm_send_data(struct wlr_xwm *xwm, xcb_atom_t target,
const char *mime_type) {
struct wlr_data_source *source;
int p[2];
if (pipe(p) == -1) {
wlr_log(L_ERROR, "pipe failed: %m");
2017-11-22 14:10:06 +01:00
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
return;
}
fcntl(p[0], F_SETFD, FD_CLOEXEC);
fcntl(p[0], F_SETFL, O_NONBLOCK);
fcntl(p[1], F_SETFD, FD_CLOEXEC);
fcntl(p[1], F_SETFL, O_NONBLOCK);
wl_array_init(&xwm->source_data);
xwm->selection_target = target;
xwm->data_source_fd = p[0];
struct wl_event_loop *loop =
wl_display_get_event_loop(xwm->xwayland->wl_display);
xwm->property_source = wl_event_loop_add_fd(loop,
xwm->data_source_fd,
WL_EVENT_READABLE,
xwm_read_data_source,
xwm);
source = xwm->seat->selection_source;
source->send(source, mime_type, p[1]);
close(p[1]);
}
static void xwm_send_timestamp(struct wlr_xwm *xwm) {
xcb_change_property(xwm->xcb_conn,
XCB_PROP_MODE_REPLACE,
xwm->selection_request.requestor,
xwm->selection_request.property,
XCB_ATOM_INTEGER,
32, // format
1, &xwm->selection_timestamp);
xwm_send_selection_notify(xwm, xwm->selection_request.property);
}
static void xwm_send_targets(struct wlr_xwm *xwm) {
struct wlr_data_source *source = xwm->seat->selection_source;
size_t n = 2 + source->mime_types.size / sizeof(char *);
xcb_atom_t *targets = malloc(n * sizeof(xcb_atom_t));
if (targets == NULL) {
return;
}
targets[0] = xwm->atoms[TIMESTAMP];
targets[1] = xwm->atoms[TARGETS];
size_t i = 2;
char **mime_type_ptr;
wl_array_for_each(mime_type_ptr, &source->mime_types) {
char *mime_type = *mime_type_ptr;
xcb_atom_t atom;
if (strcmp(mime_type, "text/plain;charset=utf-8") == 0) {
atom = xwm->atoms[UTF8_STRING];
} else if (strcmp(mime_type, "text/plain") == 0) {
atom = xwm->atoms[TEXT];
} else {
xcb_intern_atom_cookie_t cookie =
xcb_intern_atom(xwm->xcb_conn, 0, strlen(mime_type), mime_type);
xcb_intern_atom_reply_t *reply =
xcb_intern_atom_reply(xwm->xcb_conn, cookie, NULL);
if (reply == NULL) {
--n;
continue;
}
atom = reply->atom;
free(reply);
}
targets[i] = atom;
++i;
}
2017-11-22 14:10:06 +01:00
xcb_change_property(xwm->xcb_conn,
XCB_PROP_MODE_REPLACE,
xwm->selection_request.requestor,
xwm->selection_request.property,
XCB_ATOM_ATOM,
32, // format
n, targets);
2017-11-22 14:10:06 +01:00
xwm_send_selection_notify(xwm, xwm->selection_request.property);
free(targets);
2017-11-20 13:23:17 +01:00
}
2017-11-20 14:51:40 +01:00
static void xwm_handle_selection_request(struct wlr_xwm *xwm,
xcb_generic_event_t *event) {
2017-11-22 14:10:06 +01:00
xcb_selection_request_event_t *selection_request =
(xcb_selection_request_event_t *) event;
if (selection_request->selection != xwm->atoms[CLIPBOARD]) {
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
return;
}
2017-11-22 14:10:06 +01:00
xwm->selection_request = *selection_request;
xwm->incr = 0;
xwm->flush_property_on_delete = 0;
if (selection_request->selection == xwm->atoms[CLIPBOARD_MANAGER]) {
// The wlroots clipboard should already have grabbed
// the first target, so just send selection notify
// now. This isn't synchronized with the clipboard
// finishing getting the data, so there's a race here.
xwm_send_selection_notify(xwm, xwm->selection_request.property);
return;
}
if (xwm->seat->selection_source == NULL) {
wlr_log(L_DEBUG, "not handling selection request: "
"no selection source assigned to xwayland seat");
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
return;
}
// No xwayland surface focused, deny access to clipboard
if (xwm->focus_surface == NULL) {
wlr_log(L_DEBUG, "denying read access to clipboard: "
"no xwayland surface focused");
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
return;
}
2017-11-22 14:10:06 +01:00
if (selection_request->target == xwm->atoms[TARGETS]) {
xwm_send_targets(xwm);
} else if (selection_request->target == xwm->atoms[TIMESTAMP]) {
xwm_send_timestamp(xwm);
} else if (selection_request->target == xwm->atoms[UTF8_STRING]) {
xwm_send_data(xwm, selection_request->target, "text/plain;charset=utf-8");
} else if (selection_request->target == xwm->atoms[TEXT]) {
xwm_send_data(xwm, selection_request->target, "text/plain");
2017-11-22 14:10:06 +01:00
} else {
xcb_get_atom_name_cookie_t name_cookie =
xcb_get_atom_name(xwm->xcb_conn, selection_request->target);
xcb_get_atom_name_reply_t *name_reply =
xcb_get_atom_name_reply(xwm->xcb_conn, name_cookie, NULL);
if (name_reply == NULL) {
wlr_log(L_DEBUG, "not handling selection request: unknown atom");
xwm_send_selection_notify(xwm, XCB_ATOM_NONE);
return;
}
size_t len = xcb_get_atom_name_name_length(name_reply);
char *mime_type = malloc((len + 1) * sizeof(char));
if (mime_type == NULL) {
free(name_reply);
return;
}
memcpy(mime_type, xcb_get_atom_name_name(name_reply), len);
mime_type[len] = '\0';
xwm_send_data(xwm, selection_request->target, mime_type);
free(mime_type);
free(name_reply);
2017-11-22 14:10:06 +01:00
}
2017-11-20 13:23:17 +01:00
}
2017-11-22 00:25:21 +01:00
static int writable_callback(int fd, uint32_t mask, void *data) {
struct wlr_xwm *xwm = data;
unsigned char *property = xcb_get_property_value(xwm->property_reply);
int remainder = xcb_get_property_value_length(xwm->property_reply) -
xwm->property_start;
int len = write(fd, property + xwm->property_start, remainder);
if (len == -1) {
free(xwm->property_reply);
xwm->property_reply = NULL;
if (xwm->property_source) {
wl_event_source_remove(xwm->property_source);
}
xwm->property_source = NULL;
close(fd);
wlr_log(L_ERROR, "write error to target fd: %m");
2017-11-22 00:25:21 +01:00
return 1;
}
wlr_log(L_DEBUG, "wrote %d (chunk size %d) of %d bytes",
2017-11-22 00:25:21 +01:00
xwm->property_start + len,
len, xcb_get_property_value_length(xwm->property_reply));
xwm->property_start += len;
if (len == remainder) {
free(xwm->property_reply);
xwm->property_reply = NULL;
if (xwm->property_source) {
wl_event_source_remove(xwm->property_source);
}
xwm->property_source = NULL;
if (xwm->incr) {
xcb_delete_property(xwm->xcb_conn,
xwm->selection_window,
xwm->atoms[WL_SELECTION]);
} else {
wlr_log(L_DEBUG, "transfer complete");
2017-11-22 00:25:21 +01:00
close(fd);
}
}
return 1;
}
static void xwm_write_property(struct wlr_xwm *xwm,
xcb_get_property_reply_t *reply) {
xwm->property_start = 0;
xwm->property_reply = reply;
writable_callback(xwm->data_source_fd, WL_EVENT_WRITABLE, xwm);
if (xwm->property_reply) {
struct wl_event_loop *loop =
wl_display_get_event_loop(xwm->xwayland->wl_display);
xwm->property_source =
wl_event_loop_add_fd(loop,
xwm->data_source_fd,
WL_EVENT_WRITABLE,
writable_callback, xwm);
}
}
2017-11-21 16:18:44 +01:00
static void xwm_get_selection_data(struct wlr_xwm *xwm) {
2017-11-22 00:25:21 +01:00
xcb_get_property_cookie_t cookie =
xcb_get_property(xwm->xcb_conn,
1, // delete
xwm->selection_window,
xwm->atoms[WL_SELECTION],
XCB_GET_PROPERTY_TYPE_ANY,
0, // offset
0x1fffffff // length
);
xcb_get_property_reply_t *reply =
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
if (reply == NULL) {
return;
} else if (reply->type == xwm->atoms[INCR]) {
xwm->incr = 1;
free(reply);
} else {
xwm->incr = 0;
// reply's ownership is transferred to wm, which is responsible
// for freeing it
xwm_write_property(xwm, reply);
}
2017-11-21 16:18:44 +01:00
}
2017-11-21 17:19:55 +01:00
struct x11_data_source {
struct wlr_data_source base;
struct wlr_xwm *xwm;
struct wl_array mime_types_atoms;
2017-11-21 17:19:55 +01:00
};
static void data_source_accept(struct wlr_data_source *source, uint32_t time,
const char *mime_type) {
}
static void data_source_send(struct wlr_data_source *base,
const char *requested_mime_type, int32_t fd) {
2017-11-21 17:19:55 +01:00
struct x11_data_source *source = (struct x11_data_source *)base;
struct wlr_xwm *xwm = source->xwm;
bool found = false;
xcb_atom_t mime_type_atom;
char **mime_type_ptr;
size_t i = 0;
wl_array_for_each(mime_type_ptr, &source->base.mime_types) {
char *mime_type = *mime_type_ptr;
if (strcmp(mime_type, requested_mime_type) == 0) {
found = true;
xcb_atom_t *atoms = source->mime_types_atoms.data;
mime_type_atom = atoms[i];
break;
}
++i;
}
if (!found) {
return;
}
2017-11-21 17:19:55 +01:00
xcb_convert_selection(xwm->xcb_conn,
xwm->selection_window,
xwm->atoms[CLIPBOARD],
mime_type_atom,
xwm->atoms[WL_SELECTION],
XCB_TIME_CURRENT_TIME);
2017-11-21 17:19:55 +01:00
xcb_flush(xwm->xcb_conn);
fcntl(fd, F_SETFL, O_WRONLY | O_NONBLOCK);
xwm->data_source_fd = fd;
2017-11-21 17:19:55 +01:00
}
static void data_source_cancel(struct wlr_data_source *source) {
}
static void xwm_get_selection_targets(struct wlr_xwm *xwm) {
// set the wayland clipboard selection to the copied selection
2017-11-22 00:09:25 +01:00
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn,
1, // delete
xwm->selection_window,
xwm->atoms[WL_SELECTION],
XCB_GET_PROPERTY_TYPE_ANY,
0, // offset
4096 // length
2017-11-22 00:09:25 +01:00
);
xcb_get_property_reply_t *reply =
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
if (reply == NULL) {
2017-11-22 00:09:25 +01:00
return;
}
2017-11-22 00:09:25 +01:00
if (reply->type != XCB_ATOM_ATOM) {
free(reply);
return;
}
struct x11_data_source *source = calloc(1, sizeof(struct x11_data_source));
if (source == NULL) {
free(reply);
return;
}
wl_signal_init(&source->base.events.destroy);
source->base.accept = data_source_accept;
source->base.send = data_source_send;
source->base.cancel = data_source_cancel;
source->xwm = xwm;
wl_array_init(&source->base.mime_types);
wl_array_init(&source->mime_types_atoms);
2017-11-22 00:09:25 +01:00
xcb_atom_t *value = xcb_get_property_value(reply);
for (uint32_t i = 0; i < reply->value_len; i++) {
char *mime_type = NULL;
2017-11-22 00:09:25 +01:00
if (value[i] == xwm->atoms[UTF8_STRING]) {
mime_type = strdup("text/plain;charset=utf-8");
} else if (value[i] == xwm->atoms[TEXT]) {
mime_type = strdup("text/plain");
} else if (value[i] != xwm->atoms[TARGETS] &&
value[i] != xwm->atoms[TIMESTAMP]) {
xcb_get_atom_name_cookie_t name_cookie =
xcb_get_atom_name(xwm->xcb_conn, value[i]);
xcb_get_atom_name_reply_t *name_reply =
xcb_get_atom_name_reply(xwm->xcb_conn, name_cookie, NULL);
if (name_reply == NULL) {
continue;
}
size_t len = xcb_get_atom_name_name_length(name_reply);
char *name = xcb_get_atom_name_name(name_reply); // not a C string
if (memchr(name, '/', len) != NULL) {
mime_type = malloc((len + 1) * sizeof(char));
if (mime_type == NULL) {
free(name_reply);
continue;
}
memcpy(mime_type, name, len);
mime_type[len] = '\0';
2017-11-22 00:09:25 +01:00
}
free(name_reply);
}
if (mime_type != NULL) {
char **mime_type_ptr =
wl_array_add(&source->base.mime_types, sizeof(*mime_type_ptr));
if (mime_type_ptr == NULL) {
break;
}
*mime_type_ptr = mime_type;
xcb_atom_t *atom_ptr =
wl_array_add(&source->mime_types_atoms, sizeof(*atom_ptr));
if (atom_ptr == NULL) {
break;
}
*atom_ptr = value[i];
2017-11-22 00:09:25 +01:00
}
}
2017-11-22 14:10:06 +01:00
wlr_seat_set_selection(xwm->seat, &source->base,
2017-11-22 00:09:25 +01:00
wl_display_next_serial(xwm->xwayland->wl_display));
free(reply);
2017-11-21 17:19:55 +01:00
}
2017-11-21 16:18:44 +01:00
static void xwm_handle_selection_notify(struct wlr_xwm *xwm,
2017-11-20 13:23:17 +01:00
xcb_generic_event_t *event) {
2017-11-21 16:18:44 +01:00
xcb_selection_notify_event_t *selection_notify =
(xcb_selection_notify_event_t *) event;
if (selection_notify->selection != xwm->atoms[CLIPBOARD]) {
return;
}
2017-11-21 16:18:44 +01:00
if (selection_notify->property == XCB_ATOM_NONE) {
2017-11-21 17:19:55 +01:00
wlr_log(L_ERROR, "convert selection failed");
2017-11-21 16:18:44 +01:00
} else if (selection_notify->target == xwm->atoms[TARGETS]) {
2017-12-15 09:42:42 +01:00
// No xwayland surface focused, deny access to clipboard
if (xwm->focus_surface == NULL) {
wlr_log(L_DEBUG, "denying write access to clipboard: "
"no xwayland surface focused");
return;
}
// This sets the Wayland clipboard (by calling wlr_seat_set_selection)
2017-11-21 16:18:44 +01:00
xwm_get_selection_targets(xwm);
} else {
xwm_get_selection_data(xwm);
}
}
2017-11-21 15:25:05 +01:00
2017-11-21 16:18:44 +01:00
static int xwm_handle_xfixes_selection_notify(struct wlr_xwm *xwm,
xcb_generic_event_t *event) {
2017-11-21 15:25:05 +01:00
xcb_xfixes_selection_notify_event_t *xfixes_selection_notify =
(xcb_xfixes_selection_notify_event_t *) event;
if (xfixes_selection_notify->selection != xwm->atoms[CLIPBOARD]) {
return 0;
}
2017-11-21 15:25:05 +01:00
if (xfixes_selection_notify->owner == XCB_WINDOW_NONE) {
if (xwm->selection_owner != xwm->selection_window) {
// A real X client selection went away, not our
// proxy selection
2017-12-08 15:46:50 +01:00
wlr_seat_set_selection(xwm->seat, NULL,
wl_display_next_serial(xwm->xwayland->wl_display));
2017-11-21 15:25:05 +01:00
}
xwm->selection_owner = XCB_WINDOW_NONE;
return 1;
}
2017-12-08 15:46:50 +01:00
xwm->selection_owner = xfixes_selection_notify->owner;
2017-11-21 15:25:05 +01:00
// We have to use XCB_TIME_CURRENT_TIME when we claim the
// selection, so grab the actual timestamp here so we can
// answer TIMESTAMP conversion requests correctly.
if (xfixes_selection_notify->owner == xwm->selection_window) {
xwm->selection_timestamp = xfixes_selection_notify->timestamp;
2017-12-09 15:21:11 +01:00
wlr_log(L_DEBUG, "our window, skipping");
2017-11-21 15:25:05 +01:00
return 1;
}
xwm->incr = 0;
// doing this will give a selection notify where we actually handle the sync
xcb_convert_selection(xwm->xcb_conn, xwm->selection_window,
xfixes_selection_notify->selection,
2017-11-21 15:25:05 +01:00
xwm->atoms[TARGETS],
xwm->atoms[WL_SELECTION],
xfixes_selection_notify->timestamp);
xcb_flush(xwm->xcb_conn);
2017-11-20 13:23:17 +01:00
return 1;
}
2017-11-20 14:51:40 +01:00
int xwm_handle_selection_event(struct wlr_xwm *xwm,
xcb_generic_event_t *event) {
if (xwm->seat == NULL) {
2017-11-22 00:09:25 +01:00
wlr_log(L_DEBUG, "not handling selection events:"
"no seat assigned to xwayland");
return 0;
}
2017-11-20 13:23:17 +01:00
switch (event->response_type & ~0x80) {
case XCB_SELECTION_NOTIFY:
xwm_handle_selection_notify(xwm, event);
return 1;
case XCB_SELECTION_REQUEST:
xwm_handle_selection_request(xwm, event);
return 1;
}
switch (event->response_type - xwm->xfixes->first_event) {
case XCB_XFIXES_SELECTION_NOTIFY:
2017-11-21 15:25:05 +01:00
// an X11 window has copied something to the clipboard
2017-11-21 16:18:44 +01:00
return xwm_handle_xfixes_selection_notify(xwm, event);
2017-11-20 13:23:17 +01:00
}
return 0;
}
2017-11-20 14:51:40 +01:00
void xwm_selection_init(struct wlr_xwm *xwm) {
uint32_t values[1], mask;
xwm->selection_request.requestor = XCB_NONE;
values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
xwm->selection_window = xcb_generate_id(xwm->xcb_conn);
xcb_create_window(xwm->xcb_conn,
XCB_COPY_FROM_PARENT,
xwm->selection_window,
xwm->screen->root,
0, 0,
10, 10,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
xwm->screen->root_visual,
XCB_CW_EVENT_MASK, values);
xcb_set_selection_owner(xwm->xcb_conn,
xwm->selection_window,
xwm->atoms[CLIPBOARD_MANAGER],
XCB_TIME_CURRENT_TIME);
mask =
XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER |
XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY |
XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE;
xcb_xfixes_select_selection_input(xwm->xcb_conn, xwm->selection_window,
xwm->atoms[CLIPBOARD], mask);
}
2017-11-22 14:10:06 +01:00
static void handle_seat_set_selection(struct wl_listener *listener,
void *data) {
struct wlr_seat *seat = data;
struct wlr_xwm *xwm =
wl_container_of(listener, xwm, seat_selection_change);
struct wlr_data_source *source = seat->selection_source;
if (source == NULL) {
if (xwm->selection_owner == xwm->selection_window) {
xcb_set_selection_owner(xwm->xcb_conn,
XCB_ATOM_NONE,
xwm->atoms[CLIPBOARD],
xwm->selection_timestamp);
}
return;
}
2017-12-08 15:46:50 +01:00
if (source->send == data_source_send) {
2017-11-22 14:10:06 +01:00
return;
2017-12-08 15:46:50 +01:00
}
xcb_set_selection_owner(xwm->xcb_conn,
xwm->selection_window,
xwm->atoms[CLIPBOARD],
XCB_TIME_CURRENT_TIME);
2017-11-22 14:10:06 +01:00
}
void xwm_set_seat(struct wlr_xwm *xwm, struct wlr_seat *seat) {
assert(xwm);
assert(seat);
if (xwm->seat) {
wl_list_remove(&xwm->seat_selection_change.link);
xwm->seat = NULL;
}
wl_signal_add(&seat->events.selection, &xwm->seat_selection_change);
xwm->seat_selection_change.notify = handle_seat_set_selection;
xwm->seat = seat;
handle_seat_set_selection(&xwm->seat_selection_change, seat);
}