SDL_WaylandDataSource* Wayland_data_source_create(_THIS) { SDL_WaylandDataSource *data_source = NULL; SDL_VideoData *driver_data = NULL; struct wl_data_source *id = NULL; if (_this == NULL || _this->driverdata == NULL) { SDL_SetError("Video driver uninitialized"); } else { driver_data = _this->driverdata; if (driver_data->data_device_manager != NULL) { id = wl_data_device_manager_create_data_source( driver_data->data_device_manager); } if (id == NULL) { SDL_SetError("Wayland unable to create data source"); } else { data_source = SDL_calloc(1, sizeof *data_source); if (data_source == NULL) { SDL_OutOfMemory(); wl_data_source_destroy(id); } else { WAYLAND_wl_list_init(&(data_source->mimes)); data_source->source = id; wl_data_source_set_user_data(id, data_source); wl_data_source_add_listener(id, &data_source_listener, data_source); } } } return data_source; }
struct wl_data_source * gdk_wayland_selection_get_data_source (GdkWindow *owner, GdkAtom selection) { GdkDisplay *display = gdk_window_get_display (owner); GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display); struct wl_data_source *source = NULL; GdkWaylandDisplay *display_wayland; gboolean is_clipboard = FALSE; if (selection == atoms[ATOM_DND]) { if (wayland_selection->dnd_source && (!owner || owner == wayland_selection->dnd_owner)) return wayland_selection->dnd_source; } else if (selection == atoms[ATOM_CLIPBOARD]) { if (wayland_selection->clipboard_source && (!owner || owner == wayland_selection->clipboard_owner)) return wayland_selection->clipboard_source; if (wayland_selection->clipboard_source) { wl_data_source_destroy (wayland_selection->clipboard_source); wayland_selection->clipboard_source = NULL; } is_clipboard = TRUE; } else return NULL; if (!owner) return NULL; display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (owner)); source = wl_data_device_manager_create_data_source (display_wayland->data_device_manager); wl_data_source_add_listener (source, &data_source_listener, wayland_selection); if (is_clipboard) { wayland_selection->clipboard_source = source; wayland_selection->clipboard_owner = owner; } else { wayland_selection->dnd_source = source; wayland_selection->dnd_owner = owner; } return source; }
QWaylandDataSource::QWaylandDataSource(QWaylandDataDeviceManager *dndSelectionHandler, QMimeData *mimeData) : m_mime_data(mimeData) { m_data_source = wl_data_device_manager_create_data_source(dndSelectionHandler->handle()); wl_data_source_add_listener(m_data_source,&data_source_listener,this); if (!mimeData) return; QStringList formats = mimeData->formats(); for (int i = 0; i < formats.size(); i++) { const char *offer = qPrintable(formats.at(i)); wl_data_source_offer(m_data_source,offer); } }
void PasteboardWayland::write(std::map<std::string, std::string>&& dataMap) { if (m_dataSourceData.data_source) wl_data_source_destroy(m_dataSourceData.data_source); m_dataSourceData.dataMap = dataMap; ViewBackend::WaylandDisplay& display = ViewBackend::WaylandDisplay::singleton(); m_dataSourceData.data_source = wl_data_device_manager_create_data_source(display.interfaces().data_device_manager); for (auto dataPair : m_dataSourceData.dataMap) wl_data_source_offer(m_dataSourceData.data_source, dataPair.first.c_str()); wl_data_source_add_listener(m_dataSourceData.data_source, &g_dataSourceListener, &m_dataSourceData); wl_data_device_set_selection(m_dataDevice, m_dataSourceData.data_source, display.singleton().serial()); }
struct wl_data_source * gdk_wayland_selection_get_data_source (GdkWindow *owner, GdkAtom selection) { GdkDisplay *display = gdk_window_get_display (owner); GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display); gpointer source = NULL; GdkWaylandDisplay *display_wayland; if (selection == atoms[ATOM_DND]) { if (wayland_selection->dnd_source && (!owner || owner == wayland_selection->dnd_owner)) return wayland_selection->dnd_source; } else if (selection == atoms[ATOM_PRIMARY]) { if (wayland_selection->primary_source && (!owner || owner == wayland_selection->primary_owner)) return (gpointer) wayland_selection->primary_source; if (wayland_selection->primary_source) { gtk_primary_selection_source_destroy (wayland_selection->primary_source); wayland_selection->primary_source = NULL; } } else if (selection == atoms[ATOM_CLIPBOARD]) { if (wayland_selection->clipboard_source && (!owner || owner == wayland_selection->clipboard_owner)) return wayland_selection->clipboard_source; if (wayland_selection->clipboard_source) { wl_data_source_destroy (wayland_selection->clipboard_source); wayland_selection->clipboard_source = NULL; } } else return NULL; if (!owner) return NULL; display_wayland = GDK_WAYLAND_DISPLAY (gdk_window_get_display (owner)); if (selection == atoms[ATOM_PRIMARY]) { if (display_wayland->primary_selection_manager) { source = gtk_primary_selection_device_manager_create_source (display_wayland->primary_selection_manager); gtk_primary_selection_source_add_listener (source, &primary_source_listener, wayland_selection); } } else { source = wl_data_device_manager_create_data_source (display_wayland->data_device_manager); wl_data_source_add_listener (source, &data_source_listener, wayland_selection); } if (selection == atoms[ATOM_DND]) wayland_selection->dnd_source = source; else if (selection == atoms[ATOM_PRIMARY]) wayland_selection->primary_source = source; else if (selection == atoms[ATOM_CLIPBOARD]) wayland_selection->clipboard_source = source; return source; }