@@ -16,84 +16,57 @@
17#include "MousePointer.h"
17#include "MousePointer.h"
18#include "CursorImageProvider.h"
18#include "CursorImageProvider.h"
19−
19+#include "InputDispatcherFilter.h"
21−#include <unity/shell/application/MirPlatformCursor.h>
23#include <QQuickWindow>
21#include <QQuickWindow>
24−#include <QGuiApplication>
27−#include <qpa/qwindowsysteminterface.h>
23+// Unity API
24+#include <unity/shell/application/MirPlatformCursor.h>
29MousePointer::MousePointer(QQuickItem *parent)
26MousePointer::MousePointer(QQuickItem *parent)
30 : MirMousePointerInterface(parent)
27 : MirMousePointerInterface(parent)
31 , m_cursorName(QStringLiteral("left_ptr"))
28 , m_cursorName(QStringLiteral("left_ptr"))
32 , m_themeName(QStringLiteral("default"))
29 , m_themeName(QStringLiteral("default"))
34−}
31+ InputDispatcherFilter::instance()->registerPointer(this);
36−void MousePointer::handleMouseEvent(ulong timestamp, QPointF movement, Qt::MouseButtons buttons,
33+ auto mouseMovedFunc = [this]() {
37− Qt::KeyboardModifiers modifiers)
40− return;
34+ if (!isEnabled() || !window()) return;
41− }
35+ QPointF globalPosition = mapToItem(nullptr, QPointF(0, 0));
42−
36+ InputDispatcherFilter::instance()->setPosition(globalPosition);
43− if (!movement.isNull()) {
44 Q_EMIT mouseMoved();
37 Q_EMIT mouseMoved();
46−
39+ connect(this, &QQuickItem::xChanged, this, mouseMovedFunc);
47− m_accumulatedMovement += movement;
40+ connect(this, &QQuickItem::yChanged, this, mouseMovedFunc);
48− // don't apply the fractional part
41+
49− QPointF appliedMovement(int(m_accumulatedMovement.x()), int(m_accumulatedMovement.y()));
42+ connect(this, &QQuickItem::enabledChanged, this, [this]() {
50− m_accumulatedMovement -= appliedMovement;
43+ if (!isEnabled()) setVisible(false);
52− qreal newX = x() + appliedMovement.x();
45+
53− qreal newY = y() + appliedMovement.y();
46+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedLeftBoundary,
54− const qreal sceneWidth = parentItem()->width();
47+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
55− const qreal sceneHeight = parentItem()->height();
48+ if (window() && window()->screen() == screen) {
56−
49+ Q_EMIT pushedLeftBoundary(amount, buttons);
57− if (newX <= 0 && newY < m_topBoundaryOffset) { // top left corner
58− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-m_topBoundaryOffset, 2));
59− Q_EMIT pushedTopLeftCorner(qAbs(distance), buttons);
61− } else if (newX >= sceneWidth-1 && newY < m_topBoundaryOffset) { // top right corner
62− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-m_topBoundaryOffset, 2));
63− Q_EMIT pushedTopRightCorner(qAbs(distance), buttons);
65− } else if (newX < 0 && newY >= sceneHeight-1) { // bottom left corner
66− const auto distance = qSqrt(qPow(newX, 2) + qPow(newY-sceneHeight, 2));
67− Q_EMIT pushedBottomLeftCorner(qAbs(distance), buttons);
69− } else if (newX >= sceneWidth-1 && newY >= sceneHeight-1) { // bottom right corner
70− const auto distance = qSqrt(qPow(newX-sceneWidth, 2) + qPow(newY-sceneHeight, 2));
71− Q_EMIT pushedBottomRightCorner(qAbs(distance), buttons);
73− } else if (newX < 0) { // left edge
74− Q_EMIT pushedLeftBoundary(qAbs(newX), buttons);
76− } else if (newX >= sceneWidth) { // right edge
77− Q_EMIT pushedRightBoundary(newX - (sceneWidth - 1), buttons);
79− } else if (newY < m_topBoundaryOffset) { // top edge
80− Q_EMIT pushedTopBoundary(qAbs(newY - m_topBoundaryOffset), buttons);
82− } else if (Q_LIKELY(newX > 0 && newX < sceneWidth-1 && newY > 0 && newY < sceneHeight-1)) { // normal pos, not pushing
84− Q_EMIT pushStopped();
89− applyItemConfinement(newX, newY);
53+ connect(InputDispatcherFilter::instance(), &InputDispatcherFilter::pushedRightBoundary,
54+ this, [this](QScreen* screen, qreal amount, Qt::MouseButtons buttons) {
55+ if (window() && window()->screen() == screen) {
56+ Q_EMIT pushedRightBoundary(amount, buttons);
91− setX(qBound(0.0, newX, sceneWidth - 1));
61+MousePointer::~MousePointer()
92− setY(qBound(0.0, newY, sceneHeight - 1));
62+{
63+ registerScreen(nullptr);
64+ InputDispatcherFilter::instance()->unregisterPointer(this);
94− QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
67+void MousePointer::handleMouseEvent(ulong /*timestamp*/, QPointF /*movement*/, Qt::MouseButtons /*buttons*/,
95− QWindowSystemInterface::handleMouseEvent(window(), timestamp, scenePosition /*local*/, scenePosition /*global*/,
96− buttons, modifiers);
68+ Qt::KeyboardModifiers /*modifiers*/)
99void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
72void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
@@ -121,15 +94,8 @@ void MousePointer::applyItemConfinement(qreal &newX, qreal &newY)
124−void MousePointer::handleWheelEvent(ulong timestamp, QPoint angleDelta, Qt::KeyboardModifiers modifiers)
97+void MousePointer::handleWheelEvent(ulong /*timestamp*/, QPoint /*angleDelta*/, Qt::KeyboardModifiers /*modifiers*/)
126− if (!parentItem()) {
130− QPointF scenePosition = mapToItem(nullptr, QPointF(0, 0));
131− QWindowSystemInterface::handleWheelEvent(window(), timestamp, scenePosition /* local */, scenePosition /* global */,
132− QPoint() /* pixelDelta */, angleDelta, modifiers, Qt::ScrollUpdate);
135int MousePointer::topBoundaryOffset() const
101int MousePointer::topBoundaryOffset() const
@@ -182,7 +148,7 @@ void MousePointer::registerScreen(QScreen *screen)
182 if (m_registeredScreen) {
148 if (m_registeredScreen) {
183 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
149 auto previousCursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
184 if (previousCursor) {
150 if (previousCursor) {
185− previousCursor->setMousePointer(nullptr);
151+ previousCursor->unregisterMousePointer(this);
187 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
153 qCritical("QPlatformCursor is not a MirPlatformCursor! Cursor module only works in a Mir server.");
@@ -193,7 +159,7 @@ void MousePointer::registerScreen(QScreen *screen)
193 if (m_registeredScreen) {
159 if (m_registeredScreen) {
194 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
160 auto cursor = dynamic_cast<MirPlatformCursor*>(m_registeredScreen->handle()->cursor());
195 if (cursor) {
161 if (cursor) {
196− cursor->setMousePointer(this);
162+ cursor->registerMousePointer(this);
198 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
164 qCritical("QPlaformCursor is not a MirPlatformCursor! Cursor module only works in Mir.");
@@ -233,3 +199,4 @@ void MousePointer::setConfiningItem(QQuickItem *item)
233 Q_EMIT confiningItemChanged();
199 Q_EMIT confiningItemChanged();