Exemple #1
0
void
gdk_wayland_selection_add_targets (GdkWindow *window,
                                   GdkAtom    selection,
                                   guint      ntargets,
                                   GdkAtom   *targets)
{
  struct wl_data_source *data_source;
  guint i;

  g_return_if_fail (GDK_IS_WINDOW (window));

  data_source = gdk_wayland_selection_get_data_source (window, selection);

  if (!data_source)
    return;

  for (i = 0; i < ntargets; i++)
    wl_data_source_offer (data_source, gdk_atom_name (targets[i]));

  if (selection == atoms[ATOM_CLIPBOARD])
    {
      GdkDeviceManager *device_manager;
      GdkDisplay *display;
      GdkDevice *device;

      display = gdk_window_get_display (window);
      device_manager = gdk_display_get_device_manager (display);
      device = gdk_device_manager_get_client_pointer (device_manager);
      gdk_wayland_device_set_selection (device, data_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());
}
Exemple #4
0
void
gdk_wayland_selection_add_targets (GdkWindow *window,
                                   GdkAtom    selection,
                                   guint      ntargets,
                                   GdkAtom   *targets)
{
  GdkDisplay *display = gdk_window_get_display (window);
  GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display);
  gpointer data_source;
  guint i;

  g_return_if_fail (GDK_IS_WINDOW (window));

  data_source = gdk_wayland_selection_get_data_source (window, selection);

  if (!data_source)
    return;

  g_array_append_vals (wayland_selection->source_targets, targets, ntargets);

  for (i = 0; i < ntargets; i++)
    {
      gchar *mimetype = gdk_atom_name (targets[i]);

      wl_data_source_offer (data_source, mimetype);
      g_free (mimetype);
    }

  if (selection == atoms[ATOM_CLIPBOARD])
    {
      GdkDisplay *display;
      GdkDevice *device;

      display = gdk_window_get_display (window);
      device = gdk_seat_get_pointer (gdk_display_get_default_seat (display));
      gdk_wayland_device_set_selection (device, data_source);
    }
  else if (selection == atoms[ATOM_PRIMARY])
    {
      GdkSeat *seat;

      seat = gdk_display_get_default_seat (display);
      gdk_wayland_seat_set_primary (seat, data_source);
    }
}