void QWaylandDataDevice::data_device_enter(uint32_t serial, wl_surface *surface, wl_fixed_t x, wl_fixed_t y, wl_data_offer *id) { m_enterSerial = serial; m_dragWindow = QWaylandWindow::fromWlSurface(surface)->window(); m_dragPoint = QPoint(wl_fixed_to_int(x), wl_fixed_to_int(y)); QDrag *drag = static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag(); QMimeData *dragData; Qt::DropActions supportedActions; if (drag) { dragData = drag->mimeData(); supportedActions = drag->supportedActions(); } else { m_dragOffer.reset(static_cast<QWaylandDataOffer *>(wl_data_offer_get_user_data(id))); if (m_dragOffer) { dragData = m_dragOffer->mimeData(); supportedActions = Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; } } const QPlatformDragQtResponse &response = QWindowSystemInterface::handleDrag(m_dragWindow, dragData, m_dragPoint, supportedActions); if (drag) { static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->setResponse(response); } else { if (response.isAccepted()) { wl_data_offer_accept(m_dragOffer->object(), m_enterSerial, m_dragOffer->firstFormat().toUtf8().constData()); } else { wl_data_offer_accept(m_dragOffer->object(), m_enterSerial, 0); } } }
void QWaylandDataDevice::data_device_motion(uint32_t time, wl_fixed_t x, wl_fixed_t y) { Q_UNUSED(time); QDrag *drag = static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag(); if (!drag && !m_dragOffer) return; m_dragPoint = QPoint(wl_fixed_to_int(x), wl_fixed_to_int(y)); QMimeData *dragData; Qt::DropActions supportedActions; if (drag) { dragData = drag->mimeData(); supportedActions = drag->supportedActions(); } else { dragData = m_dragOffer->mimeData(); supportedActions = Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; } QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(m_dragWindow, dragData, m_dragPoint, supportedActions); if (drag) { static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->setResponse(response); } else { if (response.isAccepted()) { wl_data_offer_accept(m_dragOffer->object(), m_enterSerial, m_dragOffer->firstFormat().toUtf8().constData()); } else { wl_data_offer_accept(m_dragOffer->object(), m_enterSerial, 0); } } }
void QWaylandDataDevice::data_device_drop() { QDrag *drag = static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->currentDrag(); qDebug() << Q_FUNC_INFO << drag << m_dragOffer.data(); QMimeData *dragData = 0; Qt::DropActions supportedActions; if (drag) { dragData = drag->mimeData(); supportedActions = drag->supportedActions(); } else if (m_dragOffer) { dragData = m_dragOffer->mimeData(); supportedActions = Qt::CopyAction | Qt::MoveAction | Qt::LinkAction; } else { return; } QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(m_dragWindow, dragData, m_dragPoint, supportedActions); if (drag) { static_cast<QWaylandDrag *>(QGuiApplicationPrivate::platformIntegration()->drag())->finishDrag(response); } }