xwayland: start drag on dnd selection notify

This commit is contained in:
emersion 2018-05-19 14:52:50 +01:00
parent 7d18812735
commit 0207105291
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
8 changed files with 170 additions and 83 deletions

View file

@ -237,22 +237,33 @@ static void xwm_handle_dnd_finished(struct wlr_xwm *xwm,
}
static bool xwm_add_atom_to_mime_types(struct wlr_xwm *xwm,
struct wl_array *mime_types, xcb_atom_t atom) {
struct wl_array *mime_types, struct wl_array *mime_types_atoms,
xcb_atom_t atom) {
char *mime_type = xwm_mime_type_from_atom(xwm, atom);
if (mime_type == NULL) {
return false;
}
char **mime_type_ptr =
wl_array_add(mime_types, sizeof(*mime_type_ptr));
if (mime_type_ptr == NULL) {
return false;
}
*mime_type_ptr = mime_type;
xcb_atom_t *mime_type_atom_ptr =
wl_array_add(mime_types_atoms, sizeof(*mime_type_atom_ptr));
if (mime_type_atom_ptr == NULL) {
return false;
}
*mime_type_atom_ptr = atom;
return true;
}
static bool xwm_dnd_get_mime_types(struct wlr_xwm *xwm,
struct wl_array *mime_types, xcb_window_t source) {
struct wl_array *mime_types, struct wl_array *mime_types_atoms,
xcb_window_t source) {
xcb_get_property_cookie_t cookie = xcb_get_property(xwm->xcb_conn,
1, // delete
source,
@ -274,7 +285,8 @@ static bool xwm_dnd_get_mime_types(struct wlr_xwm *xwm,
xcb_atom_t *atoms = xcb_get_property_value(reply);
for (uint32_t i = 0; i < reply->value_len; ++i) {
if (!xwm_add_atom_to_mime_types(xwm, mime_types, atoms[i])) {
if (!xwm_add_atom_to_mime_types(xwm, mime_types, mime_types_atoms,
atoms[i])) {
wlr_log(L_ERROR, "failed to add MIME type atom to list");
goto error;
}
@ -307,8 +319,15 @@ static void xwm_handle_dnd_enter(struct wlr_xwm *xwm,
return;
}
struct wl_array mime_types;
wl_array_init(&mime_types);
if (xwm->incoming_drag == NULL) {
wlr_log(L_DEBUG, "ignoring XdndEnter client message because "
"no xwayland drag is being performed");
return;
}
struct wlr_xwayland_data_source *source =
xwayland_data_source_from_wlr_data_source(xwm->incoming_drag->source);
if ((data->data32[1] & 1) == 0) {
// Less than 3 MIME types, those are in the message data
for (size_t i = 0; i < 3; ++i) {
@ -316,13 +335,15 @@ static void xwm_handle_dnd_enter(struct wlr_xwm *xwm,
if (atom == XCB_ATOM_NONE) {
break;
}
if (!xwm_add_atom_to_mime_types(xwm, &mime_types, atom)) {
if (!xwm_add_atom_to_mime_types(xwm, &source->base.mime_types,
&source->mime_types_atoms, atom)) {
wlr_log(L_ERROR, "failed to add MIME type atom to list");
break;
}
}
} else {
if (!xwm_dnd_get_mime_types(xwm, &mime_types, source_window)) {
if (!xwm_dnd_get_mime_types(xwm, &source->base.mime_types,
&source->mime_types_atoms, source_window)) {
wlr_log(L_ERROR, "failed to add MIME type atom to list");
}
}
@ -358,9 +379,38 @@ int xwm_dnd_handle_xfixes_selection_notify(struct wlr_xwm *xwm,
selection->owner = event->owner;
if (event->owner != XCB_ATOM_NONE) {
// TODO: start grab
wlr_log(L_INFO, "start grab");
xcb_map_window(xwm->xcb_conn, xwm->dnd_window);
static const uint32_t values[] = { XCB_STACK_MODE_ABOVE };
xcb_configure_window(xwm->xcb_conn, xwm->dnd_window,
XCB_CONFIG_WINDOW_STACK_MODE, values);
struct wlr_seat *seat = selection->xwm->seat;
struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(
seat, selection->xwm->xwayland->client);
struct wlr_xwayland_data_source *source =
xwayland_data_source_create(selection);
if (source == NULL) {
return 0;
}
selection->xwm->incoming_drag =
wlr_seat_client_start_grab(seat_client, &source->base, NULL, NULL);
if (selection->xwm->incoming_drag == NULL) {
wlr_log(L_ERROR, "could not start grab");
}
} else {
// TODO: end grab
wlr_log(L_INFO, "end grab");
static const uint32_t values[] = { XCB_STACK_MODE_BELOW };
xcb_configure_window(xwm->xcb_conn, xwm->dnd_window,
XCB_CONFIG_WINDOW_STACK_MODE, values);
xcb_unmap_window(xwm->xcb_conn, xwm->dnd_window);
// TODO: drag_end(selection->xwm->incoming_drag)
selection->xwm->incoming_drag = NULL;
}
return 1;

View file

@ -174,12 +174,6 @@ static void source_send(struct wlr_xwm_selection *selection,
transfer->source_fd = fd;
}
struct x11_data_source {
struct wlr_data_source base;
struct wlr_xwm_selection *selection;
struct wl_array mime_types_atoms;
};
static const struct wlr_data_source_impl data_source_impl;
bool data_source_is_xwayland(
@ -187,16 +181,16 @@ bool data_source_is_xwayland(
return wlr_source->impl == &data_source_impl;
}
static struct x11_data_source *data_source_from_wlr_data_source(
struct wlr_xwayland_data_source *xwayland_data_source_from_wlr_data_source(
struct wlr_data_source *wlr_source) {
assert(data_source_is_xwayland(wlr_source));
return (struct x11_data_source *)wlr_source;
return (struct wlr_xwayland_data_source *)wlr_source;
}
static void data_source_send(struct wlr_data_source *wlr_source,
const char *mime_type, int32_t fd) {
struct x11_data_source *source =
data_source_from_wlr_data_source(wlr_source);
struct wlr_xwayland_data_source *source =
xwayland_data_source_from_wlr_data_source(wlr_source);
struct wlr_xwm_selection *selection = source->selection;
source_send(selection, &wlr_source->mime_types, &source->mime_types_atoms,
@ -204,24 +198,34 @@ static void data_source_send(struct wlr_data_source *wlr_source,
}
static void data_source_cancel(struct wlr_data_source *wlr_source) {
struct x11_data_source *source =
data_source_from_wlr_data_source(wlr_source);
struct wlr_xwayland_data_source *source =
xwayland_data_source_from_wlr_data_source(wlr_source);
wlr_data_source_finish(&source->base);
wl_array_release(&source->mime_types_atoms);
free(source);
}
struct wlr_xwayland_data_source *xwayland_data_source_create(
struct wlr_xwm_selection *selection) {
struct wlr_xwayland_data_source *source =
calloc(1, sizeof(struct wlr_xwayland_data_source));
if (source == NULL) {
wlr_log(L_ERROR, "allocation failed");
return NULL;
}
wlr_data_source_init(&source->base, &data_source_impl);
source->selection = selection;
wl_array_init(&source->mime_types_atoms);
return source;
}
static const struct wlr_data_source_impl data_source_impl = {
.send = data_source_send,
.cancel = data_source_cancel,
};
struct x11_primary_selection_source {
struct wlr_primary_selection_source base;
struct wlr_xwm_selection *selection;
struct wl_array mime_types_atoms;
};
static void primary_selection_source_cancel(
struct wlr_primary_selection_source *wlr_source);
@ -233,8 +237,8 @@ bool primary_selection_source_is_xwayland(
static void primary_selection_source_send(
struct wlr_primary_selection_source *wlr_source, const char *mime_type,
int32_t fd) {
struct x11_primary_selection_source *source =
(struct x11_primary_selection_source *)wlr_source;
struct wlr_xwayland_primary_selection_source *source =
(struct wlr_xwayland_primary_selection_source *)wlr_source;
struct wlr_xwm_selection *selection = source->selection;
source_send(selection, &wlr_source->mime_types, &source->mime_types_atoms,
@ -243,8 +247,8 @@ static void primary_selection_source_send(
static void primary_selection_source_cancel(
struct wlr_primary_selection_source *wlr_source) {
struct x11_primary_selection_source *source =
(struct x11_primary_selection_source *)wlr_source;
struct wlr_xwayland_primary_selection_source *source =
(struct wlr_xwayland_primary_selection_source *)wlr_source;
wlr_primary_selection_source_finish(&source->base);
wl_array_release(&source->mime_types_atoms);
free(source);
@ -332,15 +336,11 @@ static void xwm_selection_get_targets(struct wlr_xwm_selection *selection) {
struct wlr_xwm *xwm = selection->xwm;
if (selection == &xwm->clipboard_selection) {
struct x11_data_source *source =
calloc(1, sizeof(struct x11_data_source));
struct wlr_xwayland_data_source *source =
xwayland_data_source_create(selection);
if (source == NULL) {
return;
}
wlr_data_source_init(&source->base, &data_source_impl);
source->selection = selection;
wl_array_init(&source->mime_types_atoms);
bool ok = source_get_targets(selection, &source->base.mime_types,
&source->mime_types_atoms);
@ -351,8 +351,8 @@ static void xwm_selection_get_targets(struct wlr_xwm_selection *selection) {
wlr_data_source_cancel(&source->base);
}
} else if (selection == &xwm->primary_selection) {
struct x11_primary_selection_source *source =
calloc(1, sizeof(struct x11_primary_selection_source));
struct wlr_xwayland_primary_selection_source *source =
calloc(1, sizeof(struct wlr_xwayland_primary_selection_source));
if (source == NULL) {
return;
}
@ -371,8 +371,6 @@ static void xwm_selection_get_targets(struct wlr_xwm_selection *selection) {
} else {
source->base.cancel(&source->base);
}
} else if (selection == &xwm->dnd_selection) {
// TODO
}
}
@ -442,15 +440,17 @@ int xwm_handle_xfixes_selection_notify(struct wlr_xwm *xwm,
} else {
selection->owner = event->owner;
// This is our selection window.
// 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 (event->owner == selection->window) {
// This is our selection window.
// 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.
selection->timestamp = event->timestamp;
return 1;
}
// This is a real X client's selection
struct wlr_xwm_selection_transfer *transfer = &selection->incoming;
transfer->incr = false;
// doing this will give a selection notify where we actually handle the sync

View file

@ -289,6 +289,11 @@ static void seat_handle_start_drag(struct wl_listener *listener, void *data) {
struct wlr_xwm *xwm = wl_container_of(listener, xwm, seat_start_drag);
struct wlr_drag *drag = data;
if (drag && (drag->source == NULL ||
!data_source_is_xwayland(drag->source))) {
return;
}
xwm_selection_set_owner(&xwm->dnd_selection, drag != NULL);
xwm_seat_handle_start_drag(xwm, drag);
}