g_message ("data device data offer, data device %p, offer %p",
data_device, offer));
- gdk_wayland_selection_set_offer (device->display, offer);
- emit_selection_owner_change_forall (gdk_atom_intern_static_string ("GdkWaylandSelection"));
+ gdk_wayland_selection_ensure_offer (device->display, offer);
}
static void
{
GdkWaylandDeviceData *device = (GdkWaylandDeviceData *)data;
GdkWindow *dest_window, *dnd_owner;
+ GdkAtom selection;
dest_window = wl_surface_get_user_data (surface);
gdk_wayland_drop_context_update_targets (device->drop_context);
- dnd_owner = gdk_selection_owner_get_for_display (device->display, gdk_drag_get_selection (device->drop_context));
+ selection = gdk_drag_get_selection (device->drop_context);
+ dnd_owner = gdk_selection_owner_get_for_display (device->display, selection);
if (!dnd_owner)
dnd_owner = device->foreign_dnd_window;
wl_fixed_to_double (y));
_gdk_wayland_drag_context_emit_event (device->drop_context, GDK_DRAG_ENTER,
GDK_CURRENT_TIME);
- gdk_wayland_selection_set_offer (device->display, offer);
- emit_selection_owner_change (dest_window,
- gdk_atom_intern_static_string ("GdkWaylandSelection"));
+
+ gdk_wayland_selection_set_offer (device->display, selection, offer);
+ emit_selection_owner_change_forall (selection);
}
static void
struct wl_data_offer *offer)
{
GdkWaylandDeviceData *device = (GdkWaylandDeviceData *) data;
+ GdkAtom selection;
GDK_NOTE (EVENTS,
g_message ("data device selection, data device %p, data offer %p",
wl_data_device, offer));
- gdk_wayland_selection_set_offer (device->display, offer);
- emit_selection_owner_change_forall (gdk_atom_intern_static_string ("CLIPBOARD"));
+ selection = gdk_atom_intern_static_string ("CLIPBOARD");
+ gdk_wayland_selection_set_offer (device->display, selection, offer);
+ emit_selection_owner_change_forall (selection);
}
static const struct wl_data_device_listener data_device_listener = {
typedef struct _SelectionBuffer SelectionBuffer;
typedef struct _StoredSelection StoredSelection;
typedef struct _AsyncWriteData AsyncWriteData;
+typedef struct _DataOfferData DataOfferData;
struct _SelectionBuffer
{
GdkAtom selection;
};
+struct _DataOfferData
+{
+ struct wl_data_offer *offer;
+ GList *targets; /* List of GdkAtom */
+ GdkAtom requested_target;
+};
+
struct _AsyncWriteData
{
GOutputStream *stream;
struct _GdkWaylandSelection
{
/* Destination-side data */
- struct wl_data_offer *offer;
- GdkAtom source_requested_target;
-
+ DataOfferData *dnd_offer;
+ DataOfferData *clipboard_offer;
+ GHashTable *offers; /* Currently alive offers, Hashtable of wl_data_offer->DataOfferData */
GHashTable *selection_buffers; /* Hashtable of target_atom->SelectionBuffer */
- GList *targets; /* List of GdkAtom */
/* Source-side data */
StoredSelection stored_selection;
buffer);
}
+static DataOfferData *
+data_offer_data_new (struct wl_data_offer *offer)
+{
+ DataOfferData *info;
+
+ info = g_slice_new0 (DataOfferData);
+ info->offer = offer;
+
+ return info;
+}
+
+static void
+data_offer_data_free (DataOfferData *info)
+{
+ wl_data_offer_destroy (info->offer);
+ g_list_free (info->targets);
+ g_slice_free (DataOfferData, info);
+}
+
GdkWaylandSelection *
gdk_wayland_selection_new (void)
{
selection = g_new0 (GdkWaylandSelection, 1);
selection->selection_buffers =
- g_hash_table_new_full (NULL, NULL, NULL,
- (GDestroyNotify) selection_buffer_cancel_and_unref);
+ g_hash_table_new_full (NULL, NULL, NULL,
+ (GDestroyNotify) selection_buffer_cancel_and_unref);
+ selection->offers =
+ g_hash_table_new_full (NULL, NULL, NULL,
+ (GDestroyNotify) data_offer_data_free);
selection->stored_selection.fd = -1;
selection->source_targets = g_array_new (FALSE, FALSE, sizeof (GdkAtom));
return selection;
g_hash_table_destroy (selection->selection_buffers);
g_array_unref (selection->source_targets);
- if (selection->targets)
- g_list_free (selection->targets);
-
+ g_hash_table_destroy (selection->offers);
g_free (selection->stored_selection.data);
if (selection->stored_selection.cancellable)
if (selection->stored_selection.fd > 0)
close (selection->stored_selection.fd);
- if (selection->offer)
- wl_data_offer_destroy (selection->offer);
if (selection->clipboard_source)
wl_data_source_destroy (selection->clipboard_source);
if (selection->dnd_source)
const char *type)
{
GdkWaylandSelection *selection = data;
+ DataOfferData *info;
GdkAtom atom = gdk_atom_intern (type, FALSE);
- if (g_list_find (selection->targets, atom))
+ info = g_hash_table_lookup (selection->offers, wl_data_offer);
+
+ if (!info || g_list_find (info->targets, atom))
return;
- selection->targets = g_list_prepend (selection->targets, atom);
+ info->targets = g_list_prepend (info->targets, atom);
}
static const struct wl_data_offer_listener data_offer_listener = {
data_offer_offer,
};
+DataOfferData *
+selection_lookup_offer_by_atom (GdkWaylandSelection *selection,
+ GdkAtom selection_atom)
+{
+ if (selection_atom == atoms[ATOM_CLIPBOARD])
+ return selection->clipboard_offer;
+ else if (selection_atom == atoms[ATOM_DND])
+ return selection->dnd_offer;
+ else
+ return NULL;
+}
+
+void
+gdk_wayland_selection_ensure_offer (GdkDisplay *display,
+ struct wl_data_offer *wl_offer)
+{
+ GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display);
+ DataOfferData *info;
+
+ info = g_hash_table_lookup (selection->offers, wl_offer);
+
+ if (!info)
+ {
+ info = data_offer_data_new (wl_offer);
+ g_hash_table_insert (selection->offers, wl_offer, info);
+ wl_data_offer_add_listener (wl_offer,
+ &data_offer_listener,
+ selection);
+ }
+}
+
void
gdk_wayland_selection_set_offer (GdkDisplay *display,
+ GdkAtom selection_atom,
struct wl_data_offer *wl_offer)
{
GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display);
+ struct wl_data_offer *prev_offer;
+ DataOfferData *info;
- if (selection->offer == wl_offer)
- return;
+ info = g_hash_table_lookup (selection->offers, wl_offer);
- if (selection->offer)
- wl_data_offer_destroy (selection->offer);
+ prev_offer = gdk_wayland_selection_get_offer (display, selection_atom);
- selection->offer = wl_offer;
+ if (prev_offer)
+ g_hash_table_remove (selection->offers, prev_offer);
- if (wl_offer)
- wl_data_offer_add_listener (wl_offer,
- &data_offer_listener,
- selection);
+ if (selection_atom == atoms[ATOM_CLIPBOARD])
+ selection->clipboard_offer = info;
+ else if (selection_atom == atoms[ATOM_DND])
+ selection->dnd_offer = info;
/* Clear all buffers */
g_hash_table_remove_all (selection->selection_buffers);
- g_list_free (selection->targets);
- selection->targets = NULL;
}
struct wl_data_offer *
-gdk_wayland_selection_get_offer (GdkDisplay *display)
+gdk_wayland_selection_get_offer (GdkDisplay *display,
+ GdkAtom selection_atom)
{
GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display);
+ const DataOfferData *info;
- return selection->offer;
+ info = selection_lookup_offer_by_atom (selection, selection_atom);
+
+ if (info)
+ return info->offer;
+
+ return NULL;
}
GList *
-gdk_wayland_selection_get_targets (GdkDisplay *display)
+gdk_wayland_selection_get_targets (GdkDisplay *display,
+ GdkAtom selection_atom)
{
GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display);
+ const DataOfferData *info;
- return selection->targets;
+ info = selection_lookup_offer_by_atom (selection, selection_atom);
+
+ if (info)
+ return info->targets;
+
+ return NULL;
}
static void
GdkAtom target,
gint fd)
{
+ DataOfferData *offer;
GdkAtom selection;
if (wayland_selection->clipboard_owner == window)
else
return FALSE;
+ offer = selection_lookup_offer_by_atom (wayland_selection, selection);
+
if (wayland_selection->stored_selection.fd == fd &&
- wayland_selection->source_requested_target == target)
+ offer->requested_target == target)
return FALSE;
/* If we didn't issue gdk_wayland_selection_check_write() yet
close (wayland_selection->stored_selection.fd);
wayland_selection->stored_selection.fd = fd;
-
- wayland_selection->source_requested_target = target;
+ offer->requested_target = target;
if (window &&
gdk_wayland_selection_source_handles_target (wayland_selection, target))
_gdk_wayland_drag_context_emit_event (context, GDK_DROP_FINISHED,
GDK_CURRENT_TIME);
}
-
- wayland_selection->source_requested_target = GDK_NONE;
}
static void
{
GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display);
SelectionBuffer *buffer_data;
+ struct wl_data_offer *offer;
gchar *mimetype;
+ GList *target_list;
+
+ offer = gdk_wayland_selection_get_offer (display, selection);
+ target_list = gdk_wayland_selection_get_targets (display, selection);
- if (!wayland_selection->offer)
+ if (!offer)
{
GdkEvent *event;
mimetype = gdk_atom_name (target);
if (target != gdk_atom_intern_static_string ("TARGETS"))
- wl_data_offer_accept (wayland_selection->offer,
+ wl_data_offer_accept (offer,
_gdk_wayland_display_get_serial (GDK_WAYLAND_DISPLAY (display)),
mimetype);
gint i = 0;
GList *l;
- natoms = g_list_length (wayland_selection->targets);
+ natoms = g_list_length (target_list);
targets = g_new0 (GdkAtom, natoms);
- for (l = wayland_selection->targets; l; l = l->next)
+ for (l = target_list; l; l = l->next)
targets[i++] = l->data;
}
else
{
g_unix_open_pipe (pipe_fd, FD_CLOEXEC, NULL);
- wl_data_offer_receive (wayland_selection->offer,
- mimetype, pipe_fd[1]);
+ wl_data_offer_receive (offer, mimetype, pipe_fd[1]);
stream = g_unix_input_stream_new (pipe_fd[0], TRUE);
close (pipe_fd[1]);
}