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;
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);
}
}
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);
}
}
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,