wayland: Split input device out to its own file
authorKristian Høgsberg <krh@bitplanet.net>
Thu, 7 Oct 2010 14:54:39 +0000 (10:54 -0400)
committerJørgen Lind <jorgen.lind@nokia.com>
Tue, 25 Jan 2011 17:50:19 +0000 (18:50 +0100)
src/plugins/platforms/wayland/qwaylandinputdevice.cpp [new file with mode: 0644]
src/plugins/platforms/wayland/qwaylandintegration.cpp
src/plugins/platforms/wayland/qwaylandintegration.h
src/plugins/platforms/wayland/wayland.pro

diff --git a/src/plugins/platforms/wayland/qwaylandinputdevice.cpp b/src/plugins/platforms/wayland/qwaylandinputdevice.cpp
new file mode 100644 (file)
index 0000000..eeda105
--- /dev/null
@@ -0,0 +1,178 @@
+#include <QWindowSystemInterface>
+#include "qwaylandintegration.h"
+#include "qwaylandwindowsurface.h"
+#include "qfontconfigdatabase.h"
+
+#include <QtGui/private/qpixmap_raster_p.h>
+#include <QtGui/QPlatformWindow>
+
+#include <unistd.h>
+#include <fcntl.h>
+
+class QWaylandInputDevice {
+public:
+    QWaylandInputDevice(struct wl_display *display, uint32_t id);
+
+private:
+    struct wl_display *mDisplay;
+    struct wl_input_device *mInputDevice;
+    struct wl_surface *mPointerFocus;
+    struct wl_surface *mKeyboardFocus;
+    static const struct wl_input_device_listener inputDeviceListener;
+    Qt::MouseButtons mButtons;
+    QPoint mSurfacePos;
+    QPoint mGlobalPos;
+
+    static void inputHandleMotion(void *data,
+                                 struct wl_input_device *input_device,
+                                 uint32_t time,
+                                 int32_t x, int32_t y,
+                                 int32_t sx, int32_t sy);
+    static void inputHandleButton(void *data,
+                                 struct wl_input_device *input_device,
+                                 uint32_t time, uint32_t button, uint32_t state);
+    static void inputHandleKey(void *data,
+                              struct wl_input_device *input_device,
+                              uint32_t time, uint32_t key, uint32_t state);
+    static void inputHandlePointerFocus(void *data,
+                                       struct wl_input_device *input_device,
+                                       uint32_t time, struct wl_surface *surface,
+                                       int32_t x, int32_t y, int32_t sx, int32_t sy);
+    static void inputHandleKeyboardFocus(void *data,
+                                        struct wl_input_device *input_device,
+                                        uint32_t time,
+                                        struct wl_surface *surface,
+                                        struct wl_array *keys);
+};
+
+QWaylandInputDevice::QWaylandInputDevice(struct wl_display *display,
+                                        uint32_t id)
+    : mDisplay(display)
+    , mInputDevice(wl_input_device_create(display, id))
+    , mPointerFocus(NULL)
+    , mKeyboardFocus(NULL)
+    , mButtons(0)
+{
+    wl_input_device_add_listener(mInputDevice,
+                                &inputDeviceListener,
+                                this);
+    wl_input_device_set_user_data(mInputDevice, this);
+}
+
+void QWaylandInputDevice::inputHandleMotion(void *data,
+                                           struct wl_input_device *input_device,
+                                           uint32_t time,
+                                           int32_t x, int32_t y,
+                                           int32_t surface_x, int32_t surface_y)
+{
+    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
+    QWaylandWindow *window =
+       (QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
+
+    inputDevice->mSurfacePos = QPoint(surface_x, surface_y);
+    inputDevice->mGlobalPos = QPoint(x, y);
+    QWindowSystemInterface::handleMouseEvent(window->widget(),
+                                            time,
+                                            inputDevice->mSurfacePos,
+                                            inputDevice->mGlobalPos,
+                                            inputDevice->mButtons);
+}
+
+void QWaylandInputDevice::inputHandleButton(void *data,
+                                           struct wl_input_device *input_device,
+                                           uint32_t time, uint32_t button, uint32_t state)
+{
+    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
+    QWaylandWindow *window =
+       (QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
+    Qt::MouseButton qt_button;
+
+    switch (button) {
+    case 272:
+       qt_button = Qt::LeftButton;
+       break;
+    case 273:
+       qt_button = Qt::RightButton;
+       break;
+    case 274:
+       qt_button = Qt::MidButton;
+       break;
+    default:
+       return;
+    }
+
+    if (state)
+       inputDevice->mButtons |= qt_button;
+    else
+       inputDevice->mButtons &= ~qt_button;
+
+    QWindowSystemInterface::handleMouseEvent(window->widget(),
+                                            time,
+                                            inputDevice->mSurfacePos,
+                                            inputDevice->mGlobalPos,
+                                            inputDevice->mButtons);
+}
+
+void QWaylandInputDevice::inputHandleKey(void *data,
+                                        struct wl_input_device *input_device,
+                                        uint32_t time, uint32_t key, uint32_t state)
+{
+}
+
+void QWaylandInputDevice::inputHandlePointerFocus(void *data,
+                                                 struct wl_input_device *input_device,
+                                                 uint32_t time, struct wl_surface *surface,
+                                                 int32_t x, int32_t y, int32_t sx, int32_t sy)
+{
+    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
+    QWaylandWindow *window;
+
+    if (inputDevice->mPointerFocus) {
+       window = (QWaylandWindow *)
+           wl_surface_get_user_data(inputDevice->mPointerFocus);
+       QWindowSystemInterface::handleLeaveEvent(window->widget());
+       inputDevice->mPointerFocus = NULL;
+    }
+
+    if (surface) {
+       window = (QWaylandWindow *) wl_surface_get_user_data(surface);
+       QWindowSystemInterface::handleEnterEvent(window->widget());
+       inputDevice->mPointerFocus = surface;
+    }
+}
+
+void QWaylandInputDevice::inputHandleKeyboardFocus(void *data,
+                                                  struct wl_input_device *input_device,
+                                                  uint32_t time,
+                                                  struct wl_surface *surface,
+                                                  struct wl_array *keys)
+{
+    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
+    QWaylandWindow *window;
+
+    if (inputDevice->mKeyboardFocus) {
+       window = (QWaylandWindow *)
+           wl_surface_get_user_data(inputDevice->mKeyboardFocus);
+       inputDevice->mKeyboardFocus = NULL;
+    }
+
+    if (surface) {
+       window = (QWaylandWindow *) wl_surface_get_user_data(surface);
+       inputDevice->mKeyboardFocus = surface;
+    }
+}
+
+const struct wl_input_device_listener QWaylandInputDevice::inputDeviceListener = {
+    QWaylandInputDevice::inputHandleMotion,
+    QWaylandInputDevice::inputHandleButton,
+    QWaylandInputDevice::inputHandleKey,
+    QWaylandInputDevice::inputHandlePointerFocus,
+    QWaylandInputDevice::inputHandleKeyboardFocus,
+};
+
+
+QWaylandInputDevice *
+waylandInputDeviceCreate(struct wl_display *display, uint32_t id)
+{
+    return new QWaylandInputDevice(display, id);
+}
index 577dd28..c93ff25 100644 (file)
@@ -74,167 +74,6 @@ const struct wl_output_listener QWaylandDisplay::outputListener = {
     QWaylandDisplay::outputHandleGeometry
 };
 
-class QWaylandInputDevice {
-public:
-    QWaylandInputDevice(struct wl_display *display, uint32_t id);
-
-private:
-    struct wl_display *mDisplay;
-    struct wl_input_device *mInputDevice;
-    struct wl_surface *mPointerFocus;
-    struct wl_surface *mKeyboardFocus;
-    static const struct wl_input_device_listener inputDeviceListener;
-    Qt::MouseButtons mButtons;
-    QPoint mSurfacePos;
-    QPoint mGlobalPos;
-
-    static void inputHandleMotion(void *data,
-                                 struct wl_input_device *input_device,
-                                 uint32_t time,
-                                 int32_t x, int32_t y,
-                                 int32_t sx, int32_t sy);
-    static void inputHandleButton(void *data,
-                                 struct wl_input_device *input_device,
-                                 uint32_t time, uint32_t button, uint32_t state);
-    static void inputHandleKey(void *data,
-                              struct wl_input_device *input_device,
-                              uint32_t time, uint32_t key, uint32_t state);
-    static void inputHandlePointerFocus(void *data,
-                                       struct wl_input_device *input_device,
-                                       uint32_t time, struct wl_surface *surface,
-                                       int32_t x, int32_t y, int32_t sx, int32_t sy);
-    static void inputHandleKeyboardFocus(void *data,
-                                        struct wl_input_device *input_device,
-                                        uint32_t time,
-                                        struct wl_surface *surface,
-                                        struct wl_array *keys);
-};
-
-QWaylandInputDevice::QWaylandInputDevice(struct wl_display *display,
-                                        uint32_t id)
-    : mDisplay(display)
-    , mInputDevice(wl_input_device_create(display, id))
-    , mPointerFocus(NULL)
-    , mKeyboardFocus(NULL)
-    , mButtons(0)
-{
-    wl_input_device_add_listener(mInputDevice,
-                                &inputDeviceListener,
-                                this);
-    wl_input_device_set_user_data(mInputDevice, this);
-}
-
-void QWaylandInputDevice::inputHandleMotion(void *data,
-                                           struct wl_input_device *input_device,
-                                           uint32_t time,
-                                           int32_t x, int32_t y,
-                                           int32_t surface_x, int32_t surface_y)
-{
-    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
-    QWaylandWindow *window =
-       (QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
-
-    inputDevice->mSurfacePos = QPoint(surface_x, surface_y);
-    inputDevice->mGlobalPos = QPoint(x, y);
-    QWindowSystemInterface::handleMouseEvent(window->widget(),
-                                            time,
-                                            inputDevice->mSurfacePos,
-                                            inputDevice->mGlobalPos,
-                                            inputDevice->mButtons);
-}
-
-void QWaylandInputDevice::inputHandleButton(void *data,
-                                           struct wl_input_device *input_device,
-                                           uint32_t time, uint32_t button, uint32_t state)
-{
-    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
-    QWaylandWindow *window =
-       (QWaylandWindow *) wl_surface_get_user_data(inputDevice->mPointerFocus);
-    Qt::MouseButton qt_button;
-
-    switch (button) {
-    case 272:
-       qt_button = Qt::LeftButton;
-       break;
-    case 273:
-       qt_button = Qt::RightButton;
-       break;
-    case 274:
-       qt_button = Qt::MidButton;
-       break;
-    default:
-       return;
-    }
-
-    if (state)
-       inputDevice->mButtons |= qt_button;
-    else
-       inputDevice->mButtons &= ~qt_button;
-
-    QWindowSystemInterface::handleMouseEvent(window->widget(),
-                                            time,
-                                            inputDevice->mSurfacePos,
-                                            inputDevice->mGlobalPos,
-                                            inputDevice->mButtons);
-}
-
-void QWaylandInputDevice::inputHandleKey(void *data,
-                                        struct wl_input_device *input_device,
-                                        uint32_t time, uint32_t key, uint32_t state)
-{
-}
-
-void QWaylandInputDevice::inputHandlePointerFocus(void *data,
-                                                 struct wl_input_device *input_device,
-                                                 uint32_t time, struct wl_surface *surface,
-                                                 int32_t x, int32_t y, int32_t sx, int32_t sy)
-{
-    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
-    QWaylandWindow *window;
-
-    if (inputDevice->mPointerFocus) {
-       window = (QWaylandWindow *)
-           wl_surface_get_user_data(inputDevice->mPointerFocus);
-       QWindowSystemInterface::handleLeaveEvent(window->widget());
-       inputDevice->mPointerFocus = NULL;
-    }
-
-    if (surface) {
-       window = (QWaylandWindow *) wl_surface_get_user_data(surface);
-       QWindowSystemInterface::handleEnterEvent(window->widget());
-       inputDevice->mPointerFocus = surface;
-    }
-}
-
-void QWaylandInputDevice::inputHandleKeyboardFocus(void *data,
-                                                  struct wl_input_device *input_device,
-                                                  uint32_t time,
-                                                  struct wl_surface *surface,
-                                                  struct wl_array *keys)
-{
-    QWaylandInputDevice *inputDevice = (QWaylandInputDevice *) data;
-    QWaylandWindow *window;
-
-    if (inputDevice->mKeyboardFocus) {
-       window = (QWaylandWindow *)
-           wl_surface_get_user_data(inputDevice->mKeyboardFocus);
-       inputDevice->mKeyboardFocus = NULL;
-    }
-
-    if (surface) {
-       window = (QWaylandWindow *) wl_surface_get_user_data(surface);
-       inputDevice->mKeyboardFocus = surface;
-    }
-}
-
-const struct wl_input_device_listener QWaylandInputDevice::inputDeviceListener = {
-    QWaylandInputDevice::inputHandleMotion,
-    QWaylandInputDevice::inputHandleButton,
-    QWaylandInputDevice::inputHandleKey,
-    QWaylandInputDevice::inputHandlePointerFocus,
-    QWaylandInputDevice::inputHandleKeyboardFocus,
-};
-
 void QWaylandDisplay::displayHandleGlobal(struct wl_display *display,
                                          uint32_t id,
                                          const char *interface,
@@ -254,7 +93,8 @@ void QWaylandDisplay::displayHandleGlobal(struct wl_display *display,
        struct wl_output *output = wl_output_create(display, id);
        wl_output_add_listener(output, &outputListener, qwd);
     } else if (strcmp(interface, "input_device") == 0) {
-       QWaylandInputDevice *inputDevice = new QWaylandInputDevice(display, id);
+       QWaylandInputDevice *inputDevice =
+           waylandInputDeviceCreate(display, id);
        qwd->mInputDevices.append(inputDevice);
     }
 }
index d777175..20d890e 100644 (file)
@@ -53,6 +53,9 @@ QT_BEGIN_NAMESPACE
 
 class QWaylandInputDevice;
 
+QWaylandInputDevice *
+waylandInputDeviceCreate(struct wl_display *display, uint32_t id);
+
 class QWaylandDisplay : public QObject {
     Q_OBJECT;
 
index 62ff4df..c1f5bae 100644 (file)
@@ -5,7 +5,8 @@ QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/platforms
 
 SOURCES =   main.cpp \
             qwaylandintegration.cpp \
-            qwaylandwindowsurface.cpp
+            qwaylandwindowsurface.cpp \
+            qwaylandinputdevice.cpp
 
 HEADERS =   qwaylandintegration.h \
             qwaylandwindowsurface.h