Add wheel event support
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Thu, 10 May 2012 11:23:54 +0000 (14:23 +0300)
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>
Thu, 10 May 2012 17:15:04 +0000 (19:15 +0200)
Change-Id: Id827485138758ccb4c0db420559b2b9af5c45bbc
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
examples/qwindow-compositor/qwindowcompositor.cpp
src/compositor/compositor_api/waylandinput.cpp
src/compositor/compositor_api/waylandinput.h
src/compositor/wayland_wrapper/wlinputdevice.cpp
src/compositor/wayland_wrapper/wlinputdevice.h
src/plugins/platforms/wayland/qwaylandinputdevice.cpp

index b9661f0..7162e2b 100644 (file)
@@ -302,6 +302,11 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
         }
         break;
     }
+    case QEvent::Wheel: {
+        QWheelEvent *we = static_cast<QWheelEvent *>(event);
+        input->sendMouseWheelEvent(we->orientation(), we->delta());
+        break;
+    }
     case QEvent::KeyPress: {
         QKeyEvent *ke = static_cast<QKeyEvent *>(event);
         if (ke->key() == Qt::Key_Meta || ke->key() == Qt::Key_Super_L) {
index 97a1315..2a5cb6b 100644 (file)
@@ -79,6 +79,11 @@ void WaylandInputDevice::sendMouseMoveEvent(WaylandSurface *surface, const QPoin
     d->sendMouseMoveEvent(wlsurface,localPos,globalPos);
 }
 
+void WaylandInputDevice::sendMouseWheelEvent(Qt::Orientation orientation, int delta)
+{
+    d->sendMouseWheelEvent(orientation, delta);
+}
+
 void WaylandInputDevice::sendKeyPressEvent(uint code)
 {
     d->sendKeyPressEvent(code);
index 826f135..be38511 100644 (file)
@@ -65,6 +65,7 @@ public:
     void sendMouseReleaseEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos = QPointF());
     void sendMouseMoveEvent(const QPointF &localPos, const QPointF &globalPos = QPointF());
     void sendMouseMoveEvent(WaylandSurface *surface , const QPointF &localPos, const QPointF &globalPos = QPointF());
+    void sendMouseWheelEvent(Qt::Orientation orientation, int delta);
 
     void sendKeyPressEvent(uint code);
     void sendKeyReleaseEvent(uint code);
@@ -85,6 +86,7 @@ public:
 
     WaylandCompositor *compositor() const;
     Wayland::InputDevice *handle() const;
+
 private:
     Wayland::InputDevice *d;
     Q_DISABLE_COPY(WaylandInputDevice)
index 9fc120b..4bbf0dd 100644 (file)
@@ -104,6 +104,17 @@ void InputDevice::sendMouseMoveEvent(Surface *surface, const QPointF &localPos,
     sendMouseMoveEvent(localPos,globalPos);
 }
 
+void InputDevice::sendMouseWheelEvent(Qt::Orientation orientation, int delta)
+{
+    struct wl_resource *resource = base()->pointer_focus_resource;
+    if (!resource)
+        return;
+    uint32_t time = m_compositor->currentTimeMsecs();
+    uint32_t axis = orientation == Qt::Horizontal ? WL_INPUT_DEVICE_AXIS_HORIZONTAL_SCROLL
+                                                  : WL_INPUT_DEVICE_AXIS_VERTICAL_SCROLL;
+    wl_input_device_send_axis(resource, time, axis, delta);
+}
+
 void InputDevice::sendKeyPressEvent(uint code)
 {
     if (base()->keyboard_focus_resource != NULL) {
index a4c905a..060a671 100644 (file)
@@ -69,6 +69,7 @@ public:
     void sendMouseReleaseEvent(Qt::MouseButton button, const QPointF &localPos, const QPointF &globalPos = QPointF());
     void sendMouseMoveEvent(const QPointF &localPos, const QPointF &globalPos = QPointF());
     void sendMouseMoveEvent(Surface *surface, const QPointF &localPos, const QPointF &globalPos = QPointF());
+    void sendMouseWheelEvent(Qt::Orientation orientation, int delta);
 
     void sendKeyPressEvent(uint code);
     void sendKeyReleaseEvent(uint code);
index 942920f..4a92b6f 100644 (file)
@@ -245,12 +245,17 @@ void QWaylandInputDevice::inputHandleAxis(void *data,
                                           uint32_t axis,
                                           int32_t value)
 {
-    Q_UNUSED(data);
     Q_UNUSED(wl_input_device);
-    Q_UNUSED(time);
-    Q_UNUSED(axis);
-    Q_UNUSED(value);
+    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
+    QWaylandWindow *window = inputDevice->mPointerFocus;
+    Qt::Orientation orientation = axis == WL_INPUT_DEVICE_AXIS_HORIZONTAL_SCROLL ? Qt::Horizontal
+                                                                                 : Qt::Vertical;
+    QWindowSystemInterface::handleWheelEvent(window->window(), time,
+                                             inputDevice->mSurfacePos,
+                                             inputDevice->mGlobalPos,
+                                             value, orientation);
 }
+
 #ifndef QT_NO_WAYLAND_XKB
 static Qt::KeyboardModifiers translateModifiers(xkb_state *state)
 {