Follow protocol changes in pointer attach
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Mon, 18 Jun 2012 13:53:07 +0000 (16:53 +0300)
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 19 Jun 2012 05:43:35 +0000 (07:43 +0200)
Change-Id: I68b480b7feea814f79997c6a39e4567c3a990f47
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/plugins/platforms/wayland/qwaylandcursor.cpp
src/plugins/platforms/wayland/qwaylandcursor.h
src/plugins/platforms/wayland/qwaylanddisplay.h
src/plugins/platforms/wayland/qwaylandinputdevice.cpp
src/plugins/platforms/wayland/qwaylandinputdevice.h
wayland_sha1.txt

index 560ec4e..7c6e8ca 100644 (file)
@@ -105,9 +105,32 @@ static const struct pointer_image {
 QWaylandCursor::QWaylandCursor(QWaylandScreen *screen)
     : mBuffer(0)
     , mDisplay(screen->display())
+    , mSurface(0)
 {
 }
 
+QWaylandCursor::~QWaylandCursor()
+{
+    if (mSurface)
+        wl_surface_destroy(mSurface);
+
+    delete mBuffer;
+}
+
+void QWaylandCursor::ensureSurface(const QSize &size)
+{
+    if (!mBuffer || mBuffer->size() != size) {
+        delete mBuffer;
+        mBuffer = new QWaylandShmBuffer(mDisplay, size,
+                                        QImage::Format_ARGB32);
+    }
+
+    if (!mSurface)
+        mSurface = mDisplay->createSurface(0);
+
+    wl_surface_attach(mSurface, mBuffer->buffer(), 0, 0);
+}
+
 void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window)
 {
     const struct pointer_image *p;
@@ -174,13 +197,9 @@ void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window)
         QImageReader reader(p->filename);
         if (!reader.canRead())
             return;
-        if (mBuffer == NULL || mBuffer->size() != reader.size()) {
-            delete mBuffer;
-            mBuffer = new QWaylandShmBuffer(mDisplay, reader.size(),
-                                            QImage::Format_ARGB32);
-        }
+        ensureSurface(reader.size());
         reader.read(mBuffer->image());
-        mDisplay->setCursor(mBuffer, p->hotspot_x, p->hotspot_y);
+        mDisplay->setCursor(mSurface, p->hotspot_x, p->hotspot_y);
     }
 }
 
@@ -191,24 +210,20 @@ void QWaylandCursor::setupPixmapCursor(QCursor *cursor)
         mBuffer = 0;
         return;
     }
-    if (!mBuffer || mBuffer->size() != cursor->pixmap().size()) {
-        delete mBuffer;
-        mBuffer = new QWaylandShmBuffer(mDisplay, cursor->pixmap().size(),
-                                        QImage::Format_ARGB32);
-    }
+    ensureSurface(cursor->pixmap().size());
     QImage src = cursor->pixmap().toImage().convertToFormat(QImage::Format_ARGB32);
     for (int y = 0; y < src.height(); ++y)
         qMemCopy(mBuffer->image()->scanLine(y), src.scanLine(y), src.bytesPerLine());
-    mDisplay->setCursor(mBuffer, cursor->hotSpot().x(), cursor->hotSpot().y());
+    mDisplay->setCursor(mSurface, cursor->hotSpot().x(), cursor->hotSpot().y());
 }
 
-void QWaylandDisplay::setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y)
+void QWaylandDisplay::setCursor(wl_surface *surface, int32_t x, int32_t y)
 {
     /* Qt doesn't tell us which input device we should set the cursor
      * for, so set it for all devices. */
     for (int i = 0; i < mInputDevices.count(); i++) {
         QWaylandInputDevice *inputDevice = mInputDevices.at(i);
-        inputDevice->attach(buffer, x, y);
+        inputDevice->setCursor(surface, x, y);
     }
 }
 
index ef37050..1c98558 100644 (file)
 class QWaylandShmBuffer;
 class QWaylandDisplay;
 class QWaylandScreen;
+struct wl_surface;
 
 class QWaylandCursor : public QPlatformCursor
 {
 public:
     QWaylandCursor(QWaylandScreen *screen);
+    ~QWaylandCursor();
 
     void changeCursor(QCursor *cursor, QWindow *window);
     void pointerEvent(const QMouseEvent &event);
@@ -62,8 +64,11 @@ public:
 
     QWaylandShmBuffer *mBuffer;
     QWaylandDisplay *mDisplay;
+    wl_surface *mSurface;
 
 private:
+    void ensureSurface(const QSize &size);
+
     QPoint mLastPos;
 };
 
index 1c6c411..a24b907 100644 (file)
@@ -86,7 +86,7 @@ public:
     QWaylandWindowManagerIntegration *windowManagerIntegration();
 #endif
 
-    void setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y);
+    void setCursor(wl_surface *surface, int32_t x, int32_t y);
 
     struct wl_display *wl_display() const { return mDisplay; }
     struct wl_compositor *wl_compositor() const { return mCompositor; }
index 4dc2022..e04ba3e 100644 (file)
@@ -198,10 +198,10 @@ void QWaylandInputDevice::removeMouseButtonFromState(Qt::MouseButton button)
     mButtons = mButtons & !button;
 }
 
-void QWaylandInputDevice::attach(QWaylandBuffer *buffer, int x, int y)
+void QWaylandInputDevice::setCursor(wl_surface *surface, int x, int y)
 {
     if (mCaps & WL_SEAT_CAPABILITY_POINTER)
-        wl_pointer_attach(mDeviceInterfaces.pointer, mTime, buffer->buffer(), x, y);
+        wl_pointer_set_cursor(mDeviceInterfaces.pointer, mTime, surface, x, y);
 }
 
 void QWaylandInputDevice::pointer_enter(void *data,
index 9e51b63..8ea73b8 100644 (file)
@@ -72,7 +72,7 @@ public:
 
     struct wl_seat *wl_seat() const { return mSeat; }
 
-    void attach(QWaylandBuffer *buffer, int x, int y);
+    void setCursor(wl_surface *surface, int x, int y);
     void handleWindowDestroyed(QWaylandWindow *window);
 
     void setTransferDevice(struct wl_data_device *device);
index 1880621..24bcbc9 100644 (file)
@@ -1,3 +1,3 @@
 This version of Qt-Compositor is checked against the following sha1 from the
 Wayland repository:
-dff84e563896566e952f8a6704eadb8c09f27830
+b576443a0eb848085d0fcdf2b2d2987bcfb58a7f