summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-09-16 12:37:04 +0200
committerPaul Olav Tvete <paul.tvete@theqtcompany.com>2015-09-17 12:59:32 +0000
commitdca52a541eaf61269c8e746555380a7aef942b1e (patch)
treea19d253ad35f0e00ea77afa799fbf0483d96aa10 /src
parent69194916afd652d0282b23b0db06059fe30fd2ae (diff)
New API for drag and drop
Let the compositor implementation keep all the GUI state. Change-Id: I73a865fa3407340276d6765e10378b8e23a76fe2 Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/compositor/compositor_api/qwaylandcompositor.cpp24
-rw-r--r--src/compositor/compositor_api/qwaylandcompositor.h7
-rw-r--r--src/compositor/compositor_api/qwaylanddrag.cpp49
-rw-r--r--src/compositor/compositor_api/qwaylanddrag.h17
-rw-r--r--src/compositor/wayland_wrapper/qwldatadevice.cpp102
-rw-r--r--src/compositor/wayland_wrapper/qwldatadevice_p.h12
6 files changed, 89 insertions, 122 deletions
diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp
index 64abb6fba..104f85f2f 100644
--- a/src/compositor/compositor_api/qwaylandcompositor.cpp
+++ b/src/compositor/compositor_api/qwaylandcompositor.cpp
@@ -562,30 +562,6 @@ QWaylandInputDevice *QWaylandCompositor::defaultInputDevice() const
return d->inputDevices.first();
}
-QWaylandDrag *QWaylandCompositor::drag() const
-{
- return defaultInputDevice()->drag();
-}
-
-bool QWaylandCompositor::isDragging() const
-{
- return false;
-}
-
-void QWaylandCompositor::sendDragMoveEvent(const QPoint &global, const QPoint &local,
- QWaylandSurface *surface)
-{
- Q_UNUSED(global);
- Q_UNUSED(local);
- Q_UNUSED(surface);
-// Drag::instance()->dragMove(global, local, surface);
-}
-
-void QWaylandCompositor::sendDragEndEvent()
-{
-// Drag::instance()->dragEnd();
-}
-
QWaylandInputDevice *QWaylandCompositor::inputDeviceFor(QInputEvent *inputEvent)
{
Q_D(QWaylandCompositor);
diff --git a/src/compositor/compositor_api/qwaylandcompositor.h b/src/compositor/compositor_api/qwaylandcompositor.h
index a0d416b91..7fe17c4f3 100644
--- a/src/compositor/compositor_api/qwaylandcompositor.h
+++ b/src/compositor/compositor_api/qwaylandcompositor.h
@@ -58,7 +58,6 @@ class QWaylandCompositorPrivate;
class QWaylandClient;
class QWaylandSurface;
class QWaylandInputDevice;
-class QWaylandDrag;
class QWaylandGlobalInterface;
class QWaylandView;
class QWaylandOutputSpace;
@@ -114,12 +113,6 @@ public:
QWaylandInputDevice *defaultInputDevice() const;
- QWaylandDrag *drag() const;
-
- bool isDragging() const;
- void sendDragMoveEvent(const QPoint &global, const QPoint &local, QWaylandSurface *surface);
- void sendDragEndEvent();
-
QWaylandView *createSurfaceView(QWaylandSurface *surface);
QWaylandInputDevice *inputDeviceFor(QInputEvent *inputEvent);
diff --git a/src/compositor/compositor_api/qwaylanddrag.cpp b/src/compositor/compositor_api/qwaylanddrag.cpp
index 935feda5b..2348907f0 100644
--- a/src/compositor/compositor_api/qwaylanddrag.cpp
+++ b/src/compositor/compositor_api/qwaylanddrag.cpp
@@ -52,6 +52,16 @@ public:
{
}
+ QtWayland::DataDevice *dataDevice()
+ {
+ return QWaylandInputDevicePrivate::get(inputDevice)->dataDevice();
+ }
+
+ const QtWayland::DataDevice *dataDevice() const
+ {
+ return QWaylandInputDevicePrivate::get(inputDevice)->dataDevice();
+ }
+
QWaylandInputDevice *inputDevice;
};
@@ -65,32 +75,49 @@ QWaylandSurface *QWaylandDrag::icon() const
{
Q_D(const QWaylandDrag);
- const QtWayland::DataDevice *dataDevice = QWaylandInputDevicePrivate::get(d->inputDevice)->dataDevice();
+ const QtWayland::DataDevice *dataDevice = d->dataDevice();
if (!dataDevice)
return 0;
return dataDevice->dragIcon();
}
-QPointF QWaylandDrag::position() const
-{
- Q_D(const QWaylandDrag);
-
- const QtWayland::DataDevice *dataDevice = QWaylandInputDevicePrivate::get(d->inputDevice)->dataDevice();
- if (!dataDevice)
- return QPointF();
- return dataDevice->dragIconPosition();
-}
bool QWaylandDrag::visible() const
{
Q_D(const QWaylandDrag);
- const QtWayland::DataDevice *dataDevice = QWaylandInputDevicePrivate::get(d->inputDevice)->dataDevice();
+ const QtWayland::DataDevice *dataDevice = d->dataDevice();
if (!dataDevice)
return false;
return dataDevice->dragIcon() != 0;
}
+void QWaylandDrag::dragMove(QWaylandSurface *target, const QPointF &pos)
+{
+ Q_D(QWaylandDrag);
+ QtWayland::DataDevice *dataDevice = d->dataDevice();
+ if (!dataDevice)
+ return;
+ dataDevice->dragMove(target, pos);
+}
+void QWaylandDrag::drop()
+{
+ Q_D(QWaylandDrag);
+ QtWayland::DataDevice *dataDevice = d->dataDevice();
+ if (!dataDevice)
+ return;
+ dataDevice->drop();
+}
+
+void QWaylandDrag::cancelDrag()
+{
+ Q_D(QWaylandDrag);
+ QtWayland::DataDevice *dataDevice = d->dataDevice();
+ if (!dataDevice)
+ return;
+ dataDevice->cancelDrag();
+}
+
QT_END_NAMESPACE
diff --git a/src/compositor/compositor_api/qwaylanddrag.h b/src/compositor/compositor_api/qwaylanddrag.h
index 4903c3544..e7fcaad8e 100644
--- a/src/compositor/compositor_api/qwaylanddrag.h
+++ b/src/compositor/compositor_api/qwaylanddrag.h
@@ -49,25 +49,36 @@ class QWaylandSurface;
class QWaylandView;
class QWaylandInputDevice;
+namespace QtWayland {
+ class DataDevice;
+}
+
class Q_COMPOSITOR_EXPORT QWaylandDrag : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QWaylandDrag)
Q_PROPERTY(QWaylandSurface *icon READ icon NOTIFY iconChanged)
- Q_PROPERTY(QPointF position READ position NOTIFY positionChanged)
Q_PROPERTY(bool visible READ visible NOTIFY iconChanged)
public:
explicit QWaylandDrag(QWaylandInputDevice *inputDevice);
QWaylandSurface *icon() const;
- QPointF position() const;
+ // QPointF position() const;
bool visible() const;
+public Q_SLOTS:
+ void dragMove(QWaylandSurface *target, const QPointF &pos);
+ void drop();
+ void cancelDrag();
+
Q_SIGNALS:
void iconChanged();
- void positionChanged();
+ void dragStarted(); // QWaylandSurface *icon????
+
+private:
+ //friend class QtWayland::DataDevice;
};
QT_END_NAMESPACE
diff --git a/src/compositor/wayland_wrapper/qwldatadevice.cpp b/src/compositor/wayland_wrapper/qwldatadevice.cpp
index eec142a85..56f24db95 100644
--- a/src/compositor/wayland_wrapper/qwldatadevice.cpp
+++ b/src/compositor/wayland_wrapper/qwldatadevice.cpp
@@ -84,7 +84,7 @@ void DataDevice::setFocus(QWaylandClient *focusClient)
}
}
-void DataDevice::setDragFocus(QWaylandView *focus, const QPointF &localPosition)
+void DataDevice::setDragFocus(QWaylandSurface *focus, const QPointF &localPosition)
{
if (m_dragFocusResource) {
send_leave(m_dragFocusResource->handle);
@@ -95,10 +95,10 @@ void DataDevice::setDragFocus(QWaylandView *focus, const QPointF &localPosition)
if (!focus)
return;
- if (!m_dragDataSource && m_dragClient != focus->surface()->waylandClient())
+ if (!m_dragDataSource && m_dragClient != focus->waylandClient())
return;
- Resource *resource = resourceMap().value(focus->surface()->waylandClient());
+ Resource *resource = resourceMap().value(focus->waylandClient());
if (!resource)
return;
@@ -110,7 +110,7 @@ void DataDevice::setDragFocus(QWaylandView *focus, const QPointF &localPosition)
if (m_dragDataSource && !offer)
return;
- send_enter(resource->handle, serial, focus->surface()->resource(),
+ send_enter(resource->handle, serial, focus->resource(),
wl_fixed_from_double(localPosition.x()), wl_fixed_from_double(localPosition.y()),
offer->resource()->handle);
@@ -123,83 +123,43 @@ QWaylandSurface *DataDevice::dragIcon() const
return m_dragIcon;
}
-QPointF DataDevice::dragIconPosition() const
-{
- return m_dragIconPosition;
-}
-
void DataDevice::sourceDestroyed(DataSource *source)
{
if (m_selectionSource == source)
m_selectionSource = 0;
}
-// void DataDevice::focus()
-// {
-// QWaylandView *focus = pointer->mouseFocus();
-// if (focus != m_dragFocus) {
-// setDragFocus(focus, pointer->currentLocalPosition());
-// }
-// }
-
-// void DataDevice::motion(uint32_t time)
-// {
-// Q_EMIT m_inputDevice->drag()->positionChanged();
-// Q_UNUSED(time);
-// // This abstraction is wrong.
-// // We might intersept hover events or something, but forget about global coordinates mapping to local coordinates
-// // m_dragIconPosition = pointer->currentSpacePosition();
-
-// // if (m_dragFocusResource && m_dragFocus) {
-// // const QPointF &surfacePoint = outputSpace()->mapToView(m_dragFocus, pointer->currentSpacePosition());
-// // send_motion(m_dragFocusResource->handle, time,
-// // wl_fixed_from_double(surfacePoint.x()), wl_fixed_from_double(surfacePoint.y()));
-// // }
-// }
-
-// void DataDevice::button(uint32_t time, Qt::MouseButton button, uint32_t state)
-// {
-// Q_UNUSED(time);
-
-// if (m_dragFocusResource &&
-// pointer->grabButton() == button &&
-// state == QWaylandPointerPrivate::button_state_released)
-// send_drop(m_dragFocusResource->handle);
-
-// if (!pointer->isButtonPressed() &&
-// state == QWaylandPointerPrivate::button_state_released) {
-
-// if (m_dragIcon) {
-// m_dragIcon = 0;
-// m_dragIconPosition = QPointF();
-// Q_EMIT m_inputDevice->drag()->positionChanged();
-// Q_EMIT m_inputDevice->drag()->iconChanged();
-// }
-
-// setDragFocus(0, QPointF());
-// pointer->endGrab();
-// }
-// }
+void DataDevice::dragMove(QWaylandSurface *target, const QPointF &pos)
+{
+ if (target != m_dragFocus)
+ setDragFocus(target, pos);
+ if (!target)
+ return;
+ uint time = m_compositor->currentTimeMsecs(); //### should be serial
+ send_motion(m_dragFocusResource->handle, time,
+ wl_fixed_from_double(pos.x()), wl_fixed_from_double(pos.y()));
+}
-void DataDevice::data_device_start_drag(Resource *resource, struct ::wl_resource *source, struct ::wl_resource *origin, struct ::wl_resource *icon, uint32_t serial)
+void DataDevice::drop()
{
+ if (m_dragFocusResource)
+ send_drop(m_dragFocusResource->handle);
+}
- qDebug() << "data_device_start_drag";
+void DataDevice::cancelDrag()
+{
+}
- // if (m_inputDevice->pointer()->grabSerial() == serial) {
- // if (!m_inputDevice->pointer()->isButtonPressed() ||
- // m_inputDevice->mouseFocus()->surfaceResource() != origin)
- // return;
-
- // m_dragClient = resource->client();
- // m_dragDataSource = source != 0 ? DataSource::fromResource(source) : 0;
- // m_dragIcon = icon != 0 ? QWaylandSurface::fromResource(icon) : 0;
- // m_dragIconPosition = QPointF();
- // Q_EMIT m_inputDevice->drag()->positionChanged();
- // Q_EMIT m_inputDevice->drag()->iconChanged();
-
- // m_inputDevice->pointer()->startGrab(this);
- // }
+void DataDevice::data_device_start_drag(Resource *resource, struct ::wl_resource *source, struct ::wl_resource *origin, struct ::wl_resource *icon, uint32_t serial)
+{
+ m_dragClient = resource->client();
+ m_dragDataSource = source ? DataSource::fromResource(source) : 0;
+ m_dragIcon = icon ? QWaylandSurface::fromResource(icon) : 0;
+ Q_EMIT m_inputDevice->drag()->iconChanged();
+ Q_EMIT m_inputDevice->drag()->dragStarted();
+
+ Q_UNUSED(serial);
+ //### need to verify that we have an implicit grab with this serial
}
void DataDevice::data_device_set_selection(Resource *, struct ::wl_resource *source, uint32_t serial)
diff --git a/src/compositor/wayland_wrapper/qwldatadevice_p.h b/src/compositor/wayland_wrapper/qwldatadevice_p.h
index e440b7d86..49e4da702 100644
--- a/src/compositor/wayland_wrapper/qwldatadevice_p.h
+++ b/src/compositor/wayland_wrapper/qwldatadevice_p.h
@@ -43,8 +43,6 @@
QT_BEGIN_NAMESPACE
-class QWaylandView;
-
namespace QtWayland {
class Compositor;
@@ -59,13 +57,16 @@ public:
void setFocus(QWaylandClient *client);
- void setDragFocus(QWaylandView *focus, const QPointF &localPosition);
+ void setDragFocus(QWaylandSurface *focus, const QPointF &localPosition);
QWaylandSurface *dragIcon() const;
- QPointF dragIconPosition() const;
void sourceDestroyed(DataSource *source);
+ void dragMove(QWaylandSurface *target, const QPointF &pos);
+ void drop();
+ void cancelDrag();
+
protected:
void data_device_start_drag(Resource *resource, struct ::wl_resource *source, struct ::wl_resource *origin, struct ::wl_resource *icon, uint32_t serial) Q_DECL_OVERRIDE;
void data_device_set_selection(Resource *resource, struct ::wl_resource *source, uint32_t serial) Q_DECL_OVERRIDE;
@@ -80,11 +81,10 @@ private:
struct ::wl_client *m_dragClient;
DataSource *m_dragDataSource;
- QWaylandView *m_dragFocus;
+ QWaylandSurface *m_dragFocus;
Resource *m_dragFocusResource;
QWaylandSurface *m_dragIcon;
- QPointF m_dragIconPosition;
};
}