diff options
author | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-01-20 13:41:21 +0100 |
---|---|---|
committer | Jørgen Lind <jorgen.lind@theqtcompany.com> | 2015-08-28 13:09:41 +0200 |
commit | 29abd3025107113665109976355f8845c1c896e2 (patch) | |
tree | 8975d8e0ff93e37e1397d3e3ddff938cacdf2a70 /src/compositor/wayland_wrapper | |
parent | d40a957da82c1d16ef1b3379478d4a4933212db6 (diff) |
Put the pointers current view and current possition into a separate class
This also, if the current mouse coordinate ends on the boundary of the
surface, then subtract 0.01 from the mouse coordinate. This is to work
around Qt's mouse event propogation which is QRectF::contains which is
including the boundary, and Wayland which uses a strict contains. We
cant just discard events since Qt handles also enter/leave and clicking
state etc.
Change-Id: I919651232a5027b9fe0cb15b6838d3b1fee682df
Diffstat (limited to 'src/compositor/wayland_wrapper')
-rw-r--r-- | src/compositor/wayland_wrapper/qwlpointer.cpp | 25 | ||||
-rw-r--r-- | src/compositor/wayland_wrapper/qwlpointer_p.h | 49 |
2 files changed, 58 insertions, 16 deletions
diff --git a/src/compositor/wayland_wrapper/qwlpointer.cpp b/src/compositor/wayland_wrapper/qwlpointer.cpp index 27887ba54..1d80fd4ff 100644 --- a/src/compositor/wayland_wrapper/qwlpointer.cpp +++ b/src/compositor/wayland_wrapper/qwlpointer.cpp @@ -91,8 +91,6 @@ Pointer::Pointer(Compositor *compositor, InputDevice *seat) , m_position(100, 100) , m_focus() , m_focusResource() - , m_current() - , m_currentPoint() , m_buttonCount() { connect(&m_focusDestroyListener, &WlListener::fired, this, &Pointer::focusDestroyed); @@ -141,7 +139,7 @@ void Pointer::startGrab(PointerGrabber *grab) m_grab = grab; grab->m_pointer = this; - if (m_current) + if (m_currentPosition.view()) grab->focus(); } @@ -153,8 +151,7 @@ void Pointer::endGrab() void Pointer::setCurrent(QWaylandSurfaceView *surface, const QPointF &point) { - m_current = surface; - m_currentPoint = point; + m_currentPosition.setCurrent(surface, point); } bool Pointer::buttonPressed() const @@ -189,7 +186,7 @@ QWaylandSurfaceView *Pointer::focusSurface() const QWaylandSurfaceView *Pointer::current() const { - return m_current; + return m_currentPosition.view(); } QPointF Pointer::position() const @@ -199,7 +196,7 @@ QPointF Pointer::position() const QPointF Pointer::currentPosition() const { - return m_currentPoint; + return m_currentPosition.position(); } QtWaylandServer::wl_pointer::Resource *Pointer::focusResource() const @@ -222,8 +219,7 @@ void Pointer::setMouseFocus(QWaylandSurfaceView *surface, const QPointF &localPo { m_position = globalPos; - m_current = surface; - m_currentPoint = localPos; + m_currentPosition.setCurrent(surface, localPos); m_grab->focus(); } @@ -265,7 +261,8 @@ void Pointer::sendMouseMoveEvent(const QPointF &localPos, const QPointF &globalP uint32_t time = m_compositor->currentTimeMsecs(); m_position = globalPos; - m_currentPoint = localPos; + + m_currentPosition.updatePosition(localPos); m_grab->motion(time); } @@ -286,15 +283,15 @@ void Pointer::focus() if (buttonPressed()) return; - setFocus(m_current, m_currentPoint); + setFocus(m_currentPosition.view(), m_currentPosition.position()); } void Pointer::motion(uint32_t time) { if (m_focusResource) send_motion(m_focusResource->handle, time, - wl_fixed_from_double(m_currentPoint.x()), - wl_fixed_from_double(m_currentPoint.y())); + wl_fixed_from_double(m_currentPosition.x()), + wl_fixed_from_double(m_currentPosition.y())); } @@ -305,7 +302,7 @@ void Pointer::button(uint32_t time, Qt::MouseButton button, uint32_t state) } if (!buttonPressed() && state == WL_POINTER_BUTTON_STATE_RELEASED) - setFocus(m_current, m_currentPoint); + setFocus(m_currentPosition.view(), m_currentPosition.position()); } static void requestCursorSurface(QWaylandCompositor *compositor, QWaylandSurface *surface, int32_t hotspot_x, int hotspot_y) diff --git a/src/compositor/wayland_wrapper/qwlpointer_p.h b/src/compositor/wayland_wrapper/qwlpointer_p.h index 96642ba7f..c92350970 100644 --- a/src/compositor/wayland_wrapper/qwlpointer_p.h +++ b/src/compositor/wayland_wrapper/qwlpointer_p.h @@ -45,6 +45,8 @@ #include <QtCore/QObject> #include <QtCompositor/private/qwayland-server-wayland.h> +#include <QtCompositor/QWaylandSurfaceView> +#include <QtCompositor/QWaylandSurface> #include <stdint.h> @@ -72,6 +74,50 @@ public: Pointer *m_pointer; }; +class CurrentPosition +{ +public: + CurrentPosition() + : m_view(Q_NULLPTR) + {} + + void updatePosition(const QPointF &position) + { + Q_ASSERT(m_view || position.isNull()); + m_point = position; + //we adjust if the mouse position is on the edge + //to work around Qt's event propogation + if (position.isNull()) + return; + if (m_view->surface()) { + QSizeF size(m_view->surface()->size()); + if (m_point.x() == size.width()) + m_point.rx() -= 0.01; + + if (m_point.y() == size.height()) + m_point.ry() -= 0.01; + } + } + + QPointF position() const { return m_point; } + qreal x() const { return m_point.x(); } + qreal y() const { return m_point.y(); } + + void setView(QWaylandSurfaceView *view) { m_view = view; } + QWaylandSurfaceView *view() const { return m_view; } + + void setCurrent(QWaylandSurfaceView *view, const QPointF &position) + { + QPointF toSet = view || position.isNull() ? position : QPointF(); + setView(view); + updatePosition(toSet); + } + +private: + QWaylandSurfaceView *m_view; + QPointF m_point; +}; + class Q_COMPOSITOR_EXPORT Pointer : public QObject, public QtWaylandServer::wl_pointer, public PointerGrabber { public: @@ -129,8 +175,7 @@ private: QWaylandSurfaceView *m_focus; Resource *m_focusResource; - QWaylandSurfaceView *m_current; - QPointF m_currentPoint; + CurrentPosition m_currentPosition; int m_buttonCount; |