xwm: get selection targets

master
Tony Crisci 7 years ago
parent 1ada1b7f0b
commit 39e2ea8420

@ -16,6 +16,7 @@ struct wlr_xwayland_cursor;
struct wlr_xwayland {
pid_t pid;
int display;
struct wlr_seat *seat;
int x_fd[2], wl_fd[2], wm_fd[2];
struct wl_client *client;
struct wl_display *wl_display;

@ -38,6 +38,12 @@ int main(int argc, char **argv) {
server.desktop = desktop_create(&server, server.config);
server.input = input_create(&server, server.config);
struct roots_seat *default_seat =
roots_seat_create(server.input, ROOTS_CONFIG_DEFAULT_SEAT_NAME);
if (server.desktop->xwayland) {
server.desktop->xwayland->seat = default_seat->seat;
}
const char *socket = wl_display_add_socket_auto(server.wl_display);
if (!socket) {
wlr_log_errno(L_ERROR, "Unable to open wayland socket");

@ -1,3 +1,6 @@
#define _XOPEN_SOURCE 700
#include <stdlib.h>
#include <string.h>
#include <xcb/xfixes.h>
#include <fcntl.h>
#include "wlr/util/log.h"
@ -71,7 +74,54 @@ 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
wlr_log(L_DEBUG, "TODO: GET SELECTION TARGETS");
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
);
xcb_get_property_reply_t *reply =
xcb_get_property_reply(xwm->xcb_conn, cookie, NULL);
if (reply == NULL)
return;
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);
xcb_atom_t *value = xcb_get_property_value(reply);
for (uint32_t i = 0; i < reply->value_len; i++) {
if (value[i] == xwm->atoms[UTF8_STRING]) {
char **p = wl_array_add(&source->base.mime_types, sizeof *p);
if (p) {
*p = strdup("text/plain;charset=utf-8");
}
}
}
wlr_seat_set_selection(xwm->xwayland->seat, &source->base,
wl_display_next_serial(xwm->xwayland->wl_display));
free(reply);
}
static void xwm_handle_selection_notify(struct wlr_xwm *xwm,
@ -133,6 +183,12 @@ static int xwm_handle_xfixes_selection_notify(struct wlr_xwm *xwm,
int xwm_handle_selection_event(struct wlr_xwm *xwm,
xcb_generic_event_t *event) {
if (!xwm->xwayland->seat) {
wlr_log(L_DEBUG, "not handling selection events:"
"no seat assigned to xwayland");
return 0;
}
switch (event->response_type & ~0x80) {
case XCB_SELECTION_NOTIFY:
xwm_handle_selection_notify(xwm, event);

Loading…
Cancel
Save