summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@theqtcompany.com>2015-07-29 14:41:11 +0200
committerJørgen Lind <jorgen.lind@theqtcompany.com>2015-08-28 13:09:41 +0200
commit1e8f603c055444dc91e9d068ebb53d3a518aebe3 (patch)
tree750074f47a217a31530f7c12c2fe994dbf3512c9
parent0c093c9682ba6dc850365354863911e8d2ca9994 (diff)
Add a inputEventsEnabled property on QWaylandSurfaceItem
-rw-r--r--src/compositor/compositor_api/qwaylandsurfaceitem.cpp53
-rw-r--r--src/compositor/compositor_api/qwaylandsurfaceitem.h7
2 files changed, 53 insertions, 7 deletions
diff --git a/src/compositor/compositor_api/qwaylandsurfaceitem.cpp b/src/compositor/compositor_api/qwaylandsurfaceitem.cpp
index 2508cc170..de5172ff5 100644
--- a/src/compositor/compositor_api/qwaylandsurfaceitem.cpp
+++ b/src/compositor/compositor_api/qwaylandsurfaceitem.cpp
@@ -79,7 +79,9 @@ QWaylandSurfaceItem::QWaylandSurfaceItem(QQuickItem *parent)
, m_resizeSurfaceToItem(false)
, m_newTexture(false)
, m_followRequestedPos(true)
+ , m_inputEventsEnabled(true)
{
+ setAcceptHoverEvents(true);
if (!mutex)
mutex = new QMutex;
@@ -134,8 +136,10 @@ QSGTextureProvider *QWaylandSurfaceItem::textureProvider() const
void QWaylandSurfaceItem::mousePressEvent(QMouseEvent *event)
{
- if (!surface())
+ if (!shouldSendInputEvents()) {
+ event->ignore();
return;
+ }
if (!surface()->inputRegionContains(event->pos())) {
event->ignore();
@@ -150,17 +154,21 @@ void QWaylandSurfaceItem::mousePressEvent(QMouseEvent *event)
void QWaylandSurfaceItem::mouseMoveEvent(QMouseEvent *event)
{
- if (surface()) {
+ if (shouldSendInputEvents()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendMouseMoveEvent(this, event->localPos(), event->windowPos());
+ } else {
+ event->ignore();
}
}
void QWaylandSurfaceItem::mouseReleaseEvent(QMouseEvent *event)
{
- if (surface()) {
+ if (shouldSendInputEvents()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendMouseReleaseEvent(event->button(), event->localPos(), event->windowPos());
+ } else {
+ event->ignore();
}
}
@@ -171,8 +179,11 @@ void QWaylandSurfaceItem::hoverEnterEvent(QHoverEvent *event)
event->ignore();
return;
}
+ if (shouldSendInputEvents()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendMouseEnterEvent(this, event->pos());
+ } else {
+ event->ignore();
}
}
@@ -183,14 +194,27 @@ void QWaylandSurfaceItem::hoverMoveEvent(QHoverEvent *event)
event->ignore();
return;
}
+ if (shouldSendInputEvents()) {
+ QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
+ inputDevice->sendMouseMoveEvent(this, event->pos());
+ } else {
+ event->ignore();
+ }
+}
+
+void QWaylandSurfaceItem::hoverLeaveEvent(QHoverEvent *event)
+{
+ if (shouldSendInputEvents()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendMouseLeaveEvent(this);
+ } else {
+ event->ignore();
}
}
void QWaylandSurfaceItem::wheelEvent(QWheelEvent *event)
{
- if (surface()) {
+ if (shouldSendInputEvents()) {
if (!surface()->inputRegionContains(event->pos())) {
event->ignore();
return;
@@ -198,28 +222,34 @@ void QWaylandSurfaceItem::wheelEvent(QWheelEvent *event)
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendMouseWheelEvent(event->orientation(), event->delta());
+ } else {
+ event->ignore();
}
}
void QWaylandSurfaceItem::keyPressEvent(QKeyEvent *event)
{
- if (surface()) {
+ if (shouldSendInputEvents()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendFullKeyEvent(event);
+ } else {
+ event->ignore();
}
}
void QWaylandSurfaceItem::keyReleaseEvent(QKeyEvent *event)
{
- if (surface() && hasFocus()) {
+ if (shouldSendInputEvents() && hasFocus()) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
inputDevice->sendFullKeyEvent(event);
+ } else {
+ event->ignore();
}
}
void QWaylandSurfaceItem::touchEvent(QTouchEvent *event)
{
- if (m_touchEventsEnabled) {
+ if (shouldSendInputEvents() && m_touchEventsEnabled) {
QWaylandInputDevice *inputDevice = compositor()->inputDeviceFor(event);
if (event->type() == QEvent::TouchBegin) {
@@ -482,4 +512,13 @@ void QWaylandSurfaceItem::setResizeSurfaceToItem(bool enabled)
}
}
+void QWaylandSurfaceItem::setInputEventsEnabled(bool enabled)
+{
+ if (m_inputEventsEnabled != enabled) {
+ m_inputEventsEnabled = enabled;
+ setAcceptHoverEvents(enabled);
+ emit inputEventsEnabledChanged();
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/compositor/compositor_api/qwaylandsurfaceitem.h b/src/compositor/compositor_api/qwaylandsurfaceitem.h
index c2a73de18..6711d8ef2 100644
--- a/src/compositor/compositor_api/qwaylandsurfaceitem.h
+++ b/src/compositor/compositor_api/qwaylandsurfaceitem.h
@@ -66,6 +66,7 @@ class Q_COMPOSITOR_EXPORT QWaylandSurfaceItem : public QQuickItem, public QWayla
Q_PROPERTY(bool followRequestedPosition READ followRequestedPosition WRITE setFollowRequestedPosition NOTIFY followRequestedPositionChanged)
Q_PROPERTY(qreal requestedXPosition READ requestedXPosition WRITE setRequestedXPosition NOTIFY requestedXPositionChanged)
Q_PROPERTY(qreal requestedYPosition READ requestedYPosition WRITE setRequestedYPosition NOTIFY requestedYPositionChanged)
+ Q_PROPERTY(bool inputEventsEnabled READ inputEventsEnabled WRITE setInputEventsEnabled NOTIFY inputEventsEnabledChanged)
public:
QWaylandSurfaceItem(QQuickItem *parent = 0);
@@ -87,6 +88,9 @@ public:
void setTouchEventsEnabled(bool enabled);
void setResizeSurfaceToItem(bool enabled);
+ bool inputEventsEnabled() const { return m_inputEventsEnabled; }
+ void setInputEventsEnabled(bool enabled);
+
void setRequestedPosition(const QPointF &pos) Q_DECL_OVERRIDE;
QPointF pos() const Q_DECL_OVERRIDE;
@@ -134,6 +138,7 @@ Q_SIGNALS:
void followRequestedPositionChanged();
void requestedXPositionChanged();
void requestedYPositionChanged();
+ void inputEventsEnabledChanged();
protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
@@ -143,6 +148,7 @@ private:
friend class QWaylandQuickSurface;
void init(QWaylandQuickSurface *);
void updateTexture(bool changed);
+ bool shouldSendInputEvents() const { return surface() && m_inputEventsEnabled; }
static QMutex *mutex;
@@ -153,6 +159,7 @@ private:
bool m_resizeSurfaceToItem;
bool m_newTexture;
bool m_followRequestedPos;
+ bool m_inputEventsEnabled;
};
QT_END_NAMESPACE