diff options
author | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-06-04 13:35:20 +0200 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@theqtcompany.com> | 2015-06-04 12:32:26 +0000 |
commit | 5098eae737c5321112ab6c6345acfa36ca483135 (patch) | |
tree | 3f9f77bd11cf5f09be6c604be1e1666fe710f58c | |
parent | f5bdd92e5d0217bf3eec13395e4baa95bd8fda37 (diff) |
Make QCursor::pos() actually follow the cursor pos
We need to map based on the screen where the cursor actually is.
Drag and drop works on xcb now. Note that this change means that
QMouseEvent::globalPos() is no longer necessarily the same as
QCursor::pos().
Change-Id: I0a4aa0806a3251881890ac6daa09ac7c6c2fd74c
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
-rw-r--r-- | src/gui/kernel/qcursor.cpp | 11 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.cpp | 26 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen.h | 2 |
3 files changed, 36 insertions, 3 deletions
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index 236b3b0565..d52ecb7a68 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -178,9 +178,14 @@ QT_BEGIN_NAMESPACE */ QPoint QCursor::pos(const QScreen *screen) { - if (screen) - if (const QPlatformCursor *cursor = screen->handle()->cursor()) - return QHighDpi::fromNativePixels(cursor->pos(), screen); + if (screen) { + if (const QPlatformCursor *cursor = screen->handle()->cursor()) { + QPlatformScreen *ps = screen->handle(); + QPoint nativePos = cursor->pos(); + ps = ps->screenForPosition(nativePos); + return QHighDpi::fromNativePixels(nativePos, ps->screen()); + } + } return QGuiApplicationPrivate::lastCursorPosition.toPoint(); } diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp index ccb0452629..3a4adbc436 100644 --- a/src/gui/kernel/qplatformscreen.cpp +++ b/src/gui/kernel/qplatformscreen.cpp @@ -98,6 +98,32 @@ QWindow *QPlatformScreen::topLevelAt(const QPoint & pos) const } /*! + Find the sibling screen corresponding to \a globalPos. + + Returns this screen if no suitable screen is found at the position. + */ +const QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) const +{ + QPlatformScreen *that = const_cast<QPlatformScreen*>(this); + return that->screenForPosition(point); +} + +/*! + \overload + */ +QPlatformScreen *QPlatformScreen::screenForPosition(const QPoint &point) +{ + if (!geometry().contains(point)) { + Q_FOREACH (QPlatformScreen* screen, virtualSiblings()) { + if (screen->geometry().contains(point)) + return screen; + } + } + return this; +} + + +/*! Returns a list of all the platform screens that are part of the same virtual desktop. diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h index 24c617c8dd..0bd0b77751 100644 --- a/src/gui/kernel/qplatformscreen.h +++ b/src/gui/kernel/qplatformscreen.h @@ -106,6 +106,8 @@ public: virtual QWindow *topLevelAt(const QPoint &point) const; virtual QList<QPlatformScreen *> virtualSiblings() const; + const QPlatformScreen *screenForPosition(const QPoint &point) const; + QPlatformScreen *screenForPosition(const QPoint &point); QScreen *screen() const; |