diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-01-09 14:48:01 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-01-21 12:32:04 +0100 |
commit | 10472dce9202e4460b2d908bdbe0cd65291f77e5 (patch) | |
tree | 4a0d970fcedb4e7b0b01c3f65cd9c7886473dfe0 /src/platformsupport/fbconvenience | |
parent | f93c04e44a5bd08fea76a1147b1aa51953bce925 (diff) |
Unify input device hotplugging support for embedded
On embedded the mouse cursor will now appear and reappear regardless of
how the input handling code is loaded (via a generic plugin or compiled-in
to the platform plugin).
Instead of passing around QDeviceDiscovery instances that only works
when compiling-in the code into the platform plugin, introduce a new
internal central QInputDeviceManager. The single instance of this
provides a place to store any future input device related signals and
properties.
Also introduce mouse hotplugging support to linuxfb.
[ChangeLog][QtGui] The mouse cursor on Embedded Linux is now handling
hotplugging correctly with eglfs and linuxfb regardless of how the input
handling code is loaded (via a generic plugin or built in to the platform
plugin).
Change-Id: I147c1b04a193baf216598015264f2c06e1b20f84
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/platformsupport/fbconvenience')
-rw-r--r-- | src/platformsupport/fbconvenience/qfbcursor.cpp | 46 | ||||
-rw-r--r-- | src/platformsupport/fbconvenience/qfbcursor_p.h | 23 |
2 files changed, 64 insertions, 5 deletions
diff --git a/src/platformsupport/fbconvenience/qfbcursor.cpp b/src/platformsupport/fbconvenience/qfbcursor.cpp index 806556b1e4..8d6a695d68 100644 --- a/src/platformsupport/fbconvenience/qfbcursor.cpp +++ b/src/platformsupport/fbconvenience/qfbcursor.cpp @@ -34,14 +34,47 @@ #include "qfbcursor_p.h" #include "qfbscreen_p.h" #include <QtGui/QPainter> +#include <QtGui/private/qguiapplication_p.h> QT_BEGIN_NAMESPACE +bool QFbCursorDeviceListener::hasMouse() const +{ + return QGuiApplicationPrivate::inputDeviceManager()->deviceCount(QInputDeviceManager::DeviceTypePointer) > 0; +} + +void QFbCursorDeviceListener::onDeviceListChanged(QInputDeviceManager::DeviceType type) +{ + if (type == QInputDeviceManager::DeviceTypePointer) + m_cursor->updateMouseStatus(); +} + QFbCursor::QFbCursor(QFbScreen *screen) - : mScreen(screen), mDirty(false), mOnScreen(false) + : mVisible(true), + mScreen(screen), + mDirty(false), + mOnScreen(false), + mGraphic(0), + mDeviceListener(0) { + QByteArray hideCursorVal = qgetenv("QT_QPA_FB_HIDECURSOR"); + if (!hideCursorVal.isEmpty()) + mVisible = hideCursorVal.toInt() == 0; + if (!mVisible) + return; + mGraphic = new QPlatformCursorImage(0, 0, 0, 0, 0, 0); setCursor(Qt::ArrowCursor); + + mDeviceListener = new QFbCursorDeviceListener(this); + connect(QGuiApplicationPrivate::inputDeviceManager(), &QInputDeviceManager::deviceListChanged, + mDeviceListener, &QFbCursorDeviceListener::onDeviceListChanged); + updateMouseStatus(); +} + +QFbCursor::~QFbCursor() +{ + delete mDeviceListener; } QRect QFbCursor::getCurrentRect() @@ -68,6 +101,9 @@ void QFbCursor::pointerEvent(const QMouseEvent & e) QRect QFbCursor::drawCursor(QPainter & painter) { + if (!mVisible) + return QRect(); + mDirty = false; if (mCurrentRect.isNull()) return QRect(); @@ -131,15 +167,19 @@ void QFbCursor::changeCursor(QCursor * widgetCursor, QWindow *window) void QFbCursor::setDirty() { + if (!mVisible) + return; + if (!mDirty) { mDirty = true; mScreen->scheduleUpdate(); } } -void QFbCursor::setMouseDeviceDiscovery(QDeviceDiscovery *dd) +void QFbCursor::updateMouseStatus() { - Q_UNUSED(dd); + mVisible = mDeviceListener->hasMouse(); + mScreen->setDirty(mVisible ? getCurrentRect() : lastPainted()); } QT_END_NAMESPACE diff --git a/src/platformsupport/fbconvenience/qfbcursor_p.h b/src/platformsupport/fbconvenience/qfbcursor_p.h index 75501a0ff0..bec781fb21 100644 --- a/src/platformsupport/fbconvenience/qfbcursor_p.h +++ b/src/platformsupport/fbconvenience/qfbcursor_p.h @@ -46,11 +46,27 @@ // #include <qpa/qplatformcursor.h> +#include <QtGui/private/qinputdevicemanager_p.h> QT_BEGIN_NAMESPACE class QFbScreen; -class QDeviceDiscovery; +class QFbCursor; + +class QFbCursorDeviceListener : public QObject +{ + Q_OBJECT + +public: + QFbCursorDeviceListener(QFbCursor *cursor) : m_cursor(cursor) { } + bool hasMouse() const; + +public slots: + void onDeviceListChanged(QInputDeviceManager::DeviceType type); + +private: + QFbCursor *m_cursor; +}; class QFbCursor : public QPlatformCursor { @@ -58,6 +74,7 @@ class QFbCursor : public QPlatformCursor public: QFbCursor(QFbScreen *screen); + ~QFbCursor(); // output methods QRect dirtyRect(); @@ -74,7 +91,7 @@ public: virtual bool isOnScreen() const { return mOnScreen; } virtual QRect lastPainted() const { return mPrevRect; } - void setMouseDeviceDiscovery(QDeviceDiscovery *dd); + void updateMouseStatus(); private: void setCursor(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY); @@ -82,12 +99,14 @@ private: void setCursor(const QImage &image, int hotx, int hoty); QRect getCurrentRect(); + bool mVisible; QFbScreen *mScreen; QRect mCurrentRect; // next place to draw the cursor QRect mPrevRect; // last place the cursor was drawn bool mDirty; bool mOnScreen; QPlatformCursorImage *mGraphic; + QFbCursorDeviceListener *mDeviceListener; }; QT_END_NAMESPACE |