WL_EXPORT void wl_data_device_set_keyboard_focus(struct weston_seat *seat) { struct wl_resource *data_device, *offer; struct weston_data_source *source; struct weston_surface *focus; if (!seat->keyboard) return; focus = seat->keyboard->focus; if (!focus || !focus->resource) return; data_device = wl_resource_find_for_client(&seat->drag_resource_list, wl_resource_get_client(focus->resource)); if (!data_device) return; source = seat->selection_data_source; if (source) { offer = weston_data_source_send_offer(source, data_device); wl_data_device_send_selection(data_device, offer); } }
static void meta_wayland_data_device_set_selection (MetaWaylandDataDevice *data_device, MetaWaylandDataSource *source, guint32 serial) { MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device); struct wl_resource *data_device_resource, *offer; struct wl_client *focus_client; if (data_device->selection_data_source && data_device->selection_serial - serial < UINT32_MAX / 2) return; if (data_device->selection_data_source) { wl_data_source_send_cancelled (data_device->selection_data_source->resource); wl_list_remove (&data_device->selection_data_source_listener.link); data_device->selection_data_source = NULL; } data_device->selection_data_source = source; data_device->selection_serial = serial; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard); if (focus_client) { data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client); if (data_device_resource) { if (data_device->selection_data_source) { offer = meta_wayland_data_source_send_offer (data_device->selection_data_source, data_device_resource); wl_data_device_send_selection (data_device_resource, offer); } else { wl_data_device_send_selection (data_device_resource, NULL); } } } if (source) { data_device->selection_data_source_listener.notify = destroy_selection_data_source; wl_resource_add_destroy_listener (source->resource, &data_device->selection_data_source_listener); } }
WL_EXPORT void wl_seat_set_selection(struct wl_seat *seat, struct wl_data_source *source, uint32_t serial) { struct wl_resource *data_device, *offer; struct wl_resource *focus = NULL; if (seat->selection_data_source && seat->selection_serial - serial < UINT32_MAX / 2) return; if (seat->selection_data_source) { seat->selection_data_source->cancel(seat->selection_data_source); wl_list_remove(&seat->selection_data_source_listener.link); seat->selection_data_source = NULL; } seat->selection_data_source = source; seat->selection_serial = serial; if (seat->keyboard) focus = seat->keyboard->focus_resource; if (focus) { data_device = find_resource(&seat->drag_resource_list, focus->client); if (data_device && source) { offer = wl_data_source_send_offer(seat->selection_data_source, data_device); wl_data_device_send_selection(data_device, offer); } else if (data_device) { wl_data_device_send_selection(data_device, NULL); } } wl_signal_emit(&seat->selection_signal, seat); if (source) { seat->selection_data_source_listener.notify = destroy_selection_data_source; wl_signal_add(&source->resource.destroy_signal, &seat->selection_data_source_listener); } }
static void destroy_selection_data_source (struct wl_listener *listener, void *data) { MetaWaylandDataDevice *data_device = wl_container_of (listener, data_device, selection_data_source_listener); MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device); struct wl_resource *data_device_resource; struct wl_client *focus_client = NULL; data_device->selection_data_source = NULL; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard); if (focus_client) { data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client); if (data_device_resource) wl_data_device_send_selection (data_device_resource, NULL); } }
bool DataDeviceManager::offerFromCompositorToClient(wl_resource *clientDataDeviceResource) { if (!m_compositorOwnsSelection) return false; wl_client *client = clientDataDeviceResource->client; //qDebug("compositor offers %d types to %p", m_retainedData.formats().count(), client); struct wl_resource *selectionOffer = wl_client_new_object(client, &wl_data_offer_interface, &compositor_offer_interface, this); wl_data_device_send_data_offer(clientDataDeviceResource, selectionOffer); foreach (const QString &format, m_retainedData.formats()) { QByteArray ba = format.toLatin1(); wl_data_offer_send_offer(selectionOffer, ba.constData()); } wl_data_device_send_selection(clientDataDeviceResource, selectionOffer); return true; }
void data_device_offer_selection(struct data_device * data_device, struct wl_client * client) { struct wl_resource * resource; struct wl_resource * offer; /* Look for the client's data_device resource. */ resource = wl_resource_find_for_client(&data_device->resources, client); /* If the client does not have a data device, there is nothing to do. */ if (!resource) return; /* If we don't have a selection, send NULL to the client. */ offer = data_device->selection ? new_offer(resource, client, data_device->selection) : NULL; wl_data_device_send_selection(resource, offer); }
static void destroy_selection_data_source(struct wl_listener *listener, void *data) { struct wl_seat *seat = container_of(listener, struct wl_seat, selection_data_source_listener); struct wl_resource *data_device; struct wl_resource *focus = NULL; seat->selection_data_source = NULL; if (seat->keyboard) focus = seat->keyboard->focus_resource; if (focus) { data_device = find_resource(&seat->drag_resource_list, focus->client); if (data_device) wl_data_device_send_selection(data_device, NULL); } wl_signal_emit(&seat->selection_signal, seat); }
void DataDevice::sendSelectionFocus() { if (m_data_device_manager->offerFromCompositorToClient(m_data_device_resource)) return; DataSource *source = m_data_device_manager->currentSelectionSource(); if (!source || !source->client()) { m_data_device_manager->offerRetainedSelection(m_data_device_resource); return; } if (source->time() > m_sent_selection_time) { //this makes sure we don't resend if (source->client() != m_data_device_resource->client) { //don't send selection to the client that owns the selection DataOffer *data_offer = source->dataOffer(); wl_resource *client_resource = data_offer->addDataDeviceResource(m_data_device_resource); //qDebug() << "sending data_offer for source" << source; wl_data_device_send_selection(m_data_device_resource,client_resource); m_sent_selection_time = source->time(); } } }
static void destroy_selection_data_source(struct wl_listener *listener, void *data) { struct weston_seat *seat = container_of(listener, struct weston_seat, selection_data_source_listener); struct wl_resource *data_device; struct weston_surface *focus = NULL; seat->selection_data_source = NULL; if (seat->keyboard) focus = seat->keyboard->focus; if (focus && focus->resource) { data_device = wl_resource_find_for_client(&seat->drag_resource_list, wl_resource_get_client(focus->resource)); if (data_device) wl_data_device_send_selection(data_device, NULL); } wl_signal_emit(&seat->selection_signal, seat); }
void meta_wayland_data_device_set_keyboard_focus (MetaWaylandDataDevice *data_device) { MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device); struct wl_client *focus_client; struct wl_resource *data_device_resource, *offer; MetaWaylandDataSource *source; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard); if (!focus_client) return; data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client); if (!data_device_resource) return; source = data_device->selection_data_source; if (source) { offer = meta_wayland_data_source_send_offer (source, data_device_resource); wl_data_device_send_selection (data_device_resource, offer); } }
WL_EXPORT void wl_data_device_set_keyboard_focus(struct wl_seat *seat) { struct wl_resource *data_device, *focus, *offer; struct wl_data_source *source; if (!seat->keyboard) return; focus = seat->keyboard->focus_resource; if (!focus) return; data_device = find_resource(&seat->drag_resource_list, focus->client); if (!data_device) return; source = seat->selection_data_source; if (source) { offer = wl_data_source_send_offer(source, data_device); wl_data_device_send_selection(data_device, offer); } }