From ec984bdd3e8e640606d420a68bcb00967d5f55fe Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 25 Jul 2011 12:57:57 +0300 Subject: Pixmap cursor support in QWaylandCursor. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7075229584e9705fae63679b5512c11fd8535797 Reviewed-on: http://codereview.qt.nokia.com/2100 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/plugins/platforms/wayland/qwaylandcursor.cpp | 67 +++++++++++++++++++----- src/plugins/platforms/wayland/qwaylandcursor.h | 12 ++++- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylandcursor.cpp b/src/plugins/platforms/wayland/qwaylandcursor.cpp index 6612d67cb4..bbbab6dca7 100644 --- a/src/plugins/platforms/wayland/qwaylandcursor.cpp +++ b/src/plugins/platforms/wayland/qwaylandcursor.cpp @@ -47,6 +47,7 @@ #include "qwaylandshmbackingstore.h" #include +#include #define DATADIR "/usr/share" @@ -116,6 +117,7 @@ void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window) return; p = NULL; + bool isBitmap = false; switch (cursor->shape()) { case Qt::ArrowCursor: @@ -152,32 +154,53 @@ void QWaylandCursor::changeCursor(QCursor *cursor, QWindow *window) p = &pointer_images[cursor->shape()]; break; - default: case Qt::BitmapCursor: + isBitmap = true; + break; + + default: break; } - if (!p) { + if (!p && !isBitmap) { p = &pointer_images[0]; qWarning("unhandled cursor %d", cursor->shape()); } - QImageReader reader(p->filename); - - if (!reader.canRead()) - return; - - if (mBuffer == NULL || mBuffer->size() != reader.size()) { - if (mBuffer) + if (isBitmap && !cursor->pixmap().isNull()) { + setupPixmapCursor(cursor); + } else if (isBitmap && cursor->bitmap()) { + qWarning("unsupported QBitmap cursor"); + } else { + 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); + } + reader.read(mBuffer->image()); + mDisplay->setCursor(mBuffer, p->hotspot_x, p->hotspot_y); + } +} - mBuffer = new QWaylandShmBuffer(mDisplay, reader.size(), +void QWaylandCursor::setupPixmapCursor(QCursor *cursor) +{ + if (!cursor) { + delete mBuffer; + mBuffer = 0; + return; + } + if (!mBuffer || mBuffer->size() != cursor->pixmap().size()) { + delete mBuffer; + mBuffer = new QWaylandShmBuffer(mDisplay, cursor->pixmap().size(), QImage::Format_ARGB32); } - - reader.read(mBuffer->image()); - - mDisplay->setCursor(mBuffer, p->hotspot_x, p->hotspot_y); + 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()); } void QWaylandDisplay::setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y) @@ -189,3 +212,19 @@ void QWaylandDisplay::setCursor(QWaylandBuffer *buffer, int32_t x, int32_t y) inputDevice->attach(buffer, x, y); } } + +void QWaylandCursor::pointerEvent(const QMouseEvent &event) +{ + mLastPos = event.globalPos(); +} + +QPoint QWaylandCursor::pos() const +{ + return mLastPos; +} + +void QWaylandCursor::setPos(const QPoint &pos) +{ + Q_UNUSED(pos); + qWarning() << "QWaylandCursor::setPos: not implemented"; +} diff --git a/src/plugins/platforms/wayland/qwaylandcursor.h b/src/plugins/platforms/wayland/qwaylandcursor.h index 4409eea828..8753aa5698 100644 --- a/src/plugins/platforms/wayland/qwaylandcursor.h +++ b/src/plugins/platforms/wayland/qwaylandcursor.h @@ -48,13 +48,23 @@ class QWaylandShmBuffer; class QWaylandDisplay; class QWaylandScreen; -class QWaylandCursor : QPlatformCursor { +class QWaylandCursor : public QPlatformCursor +{ public: QWaylandCursor(QWaylandScreen *screen); void changeCursor(QCursor *cursor, QWindow *window); + void pointerEvent(const QMouseEvent &event); + QPoint pos() const; + void setPos(const QPoint &pos); + + void setupPixmapCursor(QCursor *cursor); + QWaylandShmBuffer *mBuffer; QWaylandDisplay *mDisplay; + +private: + QPoint mLastPos; }; #endif // QWAYLANDCURSOR_H -- cgit v1.2.3