summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiulio Camuffo <giulio.camuffo@jollamobile.com>2015-01-04 18:27:51 +0200
committerGiulio Camuffo <giulio.camuffo@jollamobile.com>2015-01-13 14:01:20 +0100
commit101698bd0ffa3e51186eb14cfdb317526cc9512b (patch)
tree7738b89d69d47e8c88c51ef20fc886e960a3ec3f /src
parent7142ca521df1daa251f3f4cfb97a5c76928df2da (diff)
Send proper mouse enter events
The wl_pointer.event carries the surface local position of the pointer. Notify Qt of it, without pretending it to be a motion event. Change-Id: Ibbe1d125a93b478f9c350a50bfea25b01f628178 Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/client/qwaylandinputdevice.cpp48
-rw-r--r--src/client/qwaylandinputdevice_p.h24
-rw-r--r--src/client/qwaylandwindow.cpp54
-rw-r--r--src/client/qwaylandwindow_p.h16
4 files changed, 92 insertions, 50 deletions
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp
index 43c5807d4..ada2cf2b5 100644
--- a/src/client/qwaylandinputdevice.cpp
+++ b/src/client/qwaylandinputdevice.cpp
@@ -345,12 +345,17 @@ void QWaylandInputDevice::setCursor(struct wl_buffer *buffer, struct wl_cursor_i
}
}
+class EnterEvent : public QWaylandPointerEvent
+{
+public:
+ EnterEvent(const QPointF &l, const QPointF &g)
+ : QWaylandPointerEvent(QWaylandPointerEvent::Enter, 0, l, g, 0, Qt::NoModifier)
+ {}
+};
+
void QWaylandInputDevice::Pointer::pointer_enter(uint32_t serial, struct wl_surface *surface,
wl_fixed_t sx, wl_fixed_t sy)
{
- Q_UNUSED(sx);
- Q_UNUSED(sy);
-
if (!surface)
return;
@@ -358,15 +363,16 @@ void QWaylandInputDevice::Pointer::pointer_enter(uint32_t serial, struct wl_surf
window->window()->setCursor(window->window()->cursor());
mFocus = window;
+ mSurfacePos = QPointF(wl_fixed_to_double(sx), wl_fixed_to_double(sy));
+ mGlobalPos = window->window()->mapToGlobal(mSurfacePos.toPoint());
- mParent->mTime = QWaylandDisplay::currentTimeMillisec();
mParent->mSerial = serial;
mEnterSerial = serial;
QWaylandWindow *grab = QWaylandWindow::mouseGrab();
if (!grab) {
- window->handleMouseEnter(mParent);
- window->handleMouse(mParent, mParent->mTime, mSurfacePos, mGlobalPos, mButtons, Qt::NoModifier);
+ EnterEvent evt(mSurfacePos, mGlobalPos);
+ window->handleMouse(mParent, evt);
}
}
@@ -387,11 +393,17 @@ void QWaylandInputDevice::Pointer::pointer_leave(uint32_t time, struct wl_surfac
mParent->mTime = time;
}
-void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
+class MotionEvent : public QWaylandPointerEvent
{
- Q_UNUSED(surface_x);
- Q_UNUSED(surface_y);
+public:
+ MotionEvent(ulong t, const QPointF &l, const QPointF &g, Qt::MouseButtons b, Qt::KeyboardModifiers m)
+ : QWaylandPointerEvent(QWaylandPointerEvent::Motion, t, l, g, b, m)
+ {
+ }
+};
+void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
+{
QWaylandWindow *window = mFocus;
if (window == NULL) {
@@ -415,9 +427,12 @@ void QWaylandInputDevice::Pointer::pointer_motion(uint32_t time, wl_fixed_t surf
// so we just set it outside of the window boundaries.
pos = QPointF(-1, -1);
global = grab->window()->mapToGlobal(pos.toPoint());
- grab->handleMouse(mParent, time, pos, global, mButtons, Qt::NoModifier);
- } else
- window->handleMouse(mParent, time, mSurfacePos, mGlobalPos, mButtons, Qt::NoModifier);
+ MotionEvent e(time, pos, global, mButtons, Qt::NoModifier);
+ grab->handleMouse(mParent, e);
+ } else {
+ MotionEvent e(time, mSurfacePos, mGlobalPos, mButtons, Qt::NoModifier);
+ window->handleMouse(mParent, e);
+ }
}
void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time,
@@ -461,9 +476,12 @@ void QWaylandInputDevice::Pointer::pointer_button(uint32_t serial, uint32_t time
if (grab && grab != mFocus) {
QPointF pos = QPointF(-1, -1);
QPointF global = grab->window()->mapToGlobal(pos.toPoint());
- grab->handleMouse(mParent, time, pos, global, mButtons, Qt::NoModifier);
- } else if (window)
- window->handleMouse(mParent, time, mSurfacePos, mGlobalPos, mButtons, Qt::NoModifier);
+ MotionEvent e(time, pos, global, mButtons, Qt::NoModifier);
+ grab->handleMouse(mParent, e);
+ } else if (window) {
+ MotionEvent e(time, mSurfacePos, mGlobalPos, mButtons, Qt::NoModifier);
+ window->handleMouse(mParent, e);
+ }
}
void QWaylandInputDevice::Pointer::pointer_axis(uint32_t time, uint32_t axis, int32_t value)
diff --git a/src/client/qwaylandinputdevice_p.h b/src/client/qwaylandinputdevice_p.h
index f1c264545..a5da8bd0f 100644
--- a/src/client/qwaylandinputdevice_p.h
+++ b/src/client/qwaylandinputdevice_p.h
@@ -260,7 +260,29 @@ public:
QList<QWindowSystemInterface::TouchPoint> mPrevTouchPoints;
};
-
+class QWaylandPointerEvent
+{
+public:
+ enum Type {
+ Enter,
+ Motion
+ };
+ inline QWaylandPointerEvent(Type t, ulong ts, const QPointF &l, const QPointF &g, Qt::MouseButtons b, Qt::KeyboardModifiers m)
+ : type(t)
+ , timestamp(ts)
+ , local(l)
+ , global(g)
+ , buttons(b)
+ , modifiers(m)
+ {}
+
+ Type type;
+ ulong timestamp;
+ QPointF local;
+ QPointF global;
+ Qt::MouseButtons buttons;
+ Qt::KeyboardModifiers modifiers;
+};
QT_END_NAMESPACE
diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp
index fd06972ff..08a123b61 100644
--- a/src/client/qwaylandwindow.cpp
+++ b/src/client/qwaylandwindow.cpp
@@ -603,27 +603,28 @@ QWaylandWindow *QWaylandWindow::transientParent() const
return 0;
}
-void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
+void QWaylandWindow::handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e)
{
- if (b != Qt::NoButton) {
+ if (e.buttons != Qt::NoButton) {
mMouseSerial = inputDevice->serial();
mMouseDevice = inputDevice;
}
if (mWindowDecoration) {
- handleMouseEventWithDecoration(inputDevice, timestamp,local,global,b,mods);
- return;
+ handleMouseEventWithDecoration(inputDevice, e);
+ } else {
+ switch (e.type) {
+ case QWaylandPointerEvent::Enter:
+ QWindowSystemInterface::handleEnterEvent(window(), e.local, e.global);
+ break;
+ case QWaylandPointerEvent::Motion:
+ QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, e.local, e.global, e.buttons, e.modifiers);
+ break;
+ }
}
- QWindowSystemInterface::handleMouseEvent(window(),timestamp,local,global,b,mods);
-}
-
-void QWaylandWindow::handleMouseEnter(QWaylandInputDevice *inputDevice)
-{
- if (!mWindowDecoration) {
- QWindowSystemInterface::handleEnterEvent(window());
- }
- restoreMouseCursor(inputDevice);
+ if (e.type == QWaylandPointerEvent::Enter)
+ restoreMouseCursor(inputDevice);
}
void QWaylandWindow::handleMouseLeave(QWaylandInputDevice *inputDevice)
@@ -645,19 +646,22 @@ bool QWaylandWindow::touchDragDecoration(QWaylandInputDevice *inputDevice, const
return mWindowDecoration->handleTouch(inputDevice, local, global, state, mods);
}
-void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, ulong timestamp, const QPointF &local, const QPointF &global, Qt::MouseButtons b, Qt::KeyboardModifiers mods)
+void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e)
{
- if (mWindowDecoration->handleMouse(inputDevice,local,global,b,mods))
+ if (mWindowDecoration->handleMouse(inputDevice, e.local, e.global, e.buttons, e.modifiers)) {
+ if (mMouseEventsInContentArea)
+ QWindowSystemInterface::handleLeaveEvent(window());
return;
+ }
QMargins marg = frameMargins();
QRect windowRect(0 + marg.left(),
0 + marg.top(),
geometry().size().width() - marg.right(),
geometry().size().height() - marg.bottom());
- if (windowRect.contains(local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
- QPointF localTranslated = local;
- QPointF globalTranslated = global;
+ if (windowRect.contains(e.local.toPoint()) || mMousePressedInContentArea != Qt::NoButton) {
+ QPointF localTranslated = e.local;
+ QPointF globalTranslated = e.global;
localTranslated.setX(localTranslated.x() - marg.left());
localTranslated.setY(localTranslated.y() - marg.top());
globalTranslated.setX(globalTranslated.x() - marg.left());
@@ -666,15 +670,23 @@ void QWaylandWindow::handleMouseEventWithDecoration(QWaylandInputDevice *inputDe
restoreMouseCursor(inputDevice);
QWindowSystemInterface::handleEnterEvent(window());
}
- QWindowSystemInterface::handleMouseEvent(window(), timestamp, localTranslated, globalTranslated, b, mods);
+
+ switch (e.type) {
+ case QWaylandPointerEvent::Enter:
+ QWindowSystemInterface::handleEnterEvent(window(), localTranslated, globalTranslated);
+ break;
+ case QWaylandPointerEvent::Motion:
+ QWindowSystemInterface::handleMouseEvent(window(), e.timestamp, localTranslated, globalTranslated, e.buttons, e.modifiers);
+ break;
+ }
+
mMouseEventsInContentArea = true;
- mMousePressedInContentArea = b;
+ mMousePressedInContentArea = e.buttons;
} else {
if (mMouseEventsInContentArea) {
QWindowSystemInterface::handleLeaveEvent(window());
mMouseEventsInContentArea = false;
}
- mWindowDecoration->handleMouse(inputDevice,local,global,b,mods);
}
}
diff --git a/src/client/qwaylandwindow_p.h b/src/client/qwaylandwindow_p.h
index 0d982d43e..2650f46d1 100644
--- a/src/client/qwaylandwindow_p.h
+++ b/src/client/qwaylandwindow_p.h
@@ -64,6 +64,7 @@ class QWaylandAbstractDecoration;
class QWaylandInputDevice;
class QWaylandScreen;
class QWaylandShmBackingStore;
+class QWaylandPointerEvent;
class Q_WAYLAND_CLIENT_EXPORT QWaylandWindowConfigure
{
@@ -151,13 +152,7 @@ public:
QWaylandAbstractDecoration *decoration() const;
- void handleMouse(QWaylandInputDevice *inputDevice,
- ulong timestamp,
- const QPointF & local,
- const QPointF & global,
- Qt::MouseButtons b,
- Qt::KeyboardModifiers mods);
- void handleMouseEnter(QWaylandInputDevice *inputDevice);
+ void handleMouse(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
void handleMouseLeave(QWaylandInputDevice *inputDevice);
bool touchDragDecoration(QWaylandInputDevice *inputDevice, const QPointF &local, const QPointF &global,
@@ -237,12 +232,7 @@ private:
bool setWindowStateInternal(Qt::WindowState flags);
void setGeometry_helper(const QRect &rect);
- void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice,
- ulong timestamp,
- const QPointF & local,
- const QPointF & global,
- Qt::MouseButtons b,
- Qt::KeyboardModifiers mods);
+ void handleMouseEventWithDecoration(QWaylandInputDevice *inputDevice, const QWaylandPointerEvent &e);
static const wl_callback_listener callbackListener;
static void frameCallback(void *data, struct wl_callback *wl_callback, uint32_t time);