summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-05 14:42:42 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-07 22:43:43 +0100
commitb319d44798fe4c5aa8b859966d64f28b08be28dd (patch)
treefc24d20ebff32b89f02e0390950fc33f38f7e972 /src/gui/kernel
parentb7915a4d0d97a60fc30e55eb4cc1b10e7fe9ce2f (diff)
QCursor: Associate cursor with screen.
- Introduce cursor() accessor to QPlatformScreen. - Remove screen member of QPlatformCursor (a cursor can be shared by multiple screens of a virtual desktop). - Add QCursor::pos()/ QCursor::setPos() taking a QScreen-parameter, use primaryScreen() for old overloads. QCursor::pos() can then query the platform cursor for the position and return the position even if the mouse position is outside the windows owned by the Qt application. - Fix tests Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com> Task-number: QTBUG-22457 Task-number: QTBUG-22565 Task-number: QTBUG-20753 Change-Id: Ia69f37343f95772e934eab1cd806bd54cbdbbe51 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qcursor.cpp46
-rw-r--r--src/gui/kernel/qcursor.h4
-rw-r--r--src/gui/kernel/qcursor_qpa.cpp40
-rw-r--r--src/gui/kernel/qguiapplication.cpp22
-rw-r--r--src/gui/kernel/qplatformcursor_qpa.cpp15
-rw-r--r--src/gui/kernel/qplatformcursor_qpa.h10
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp11
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.h2
8 files changed, 103 insertions, 47 deletions
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp
index f16e5c85de..95b2b4a28e 100644
--- a/src/gui/kernel/qcursor.cpp
+++ b/src/gui/kernel/qcursor.cpp
@@ -185,10 +185,10 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn QPoint QCursor::pos()
+ \fn QPoint QCursor::pos(const QScreen *screen)
- Returns the position of the cursor (hot spot) in global screen
- coordinates.
+ Returns the position of the cursor (hot spot) of the \a screen
+ in global screen coordinates.
You can call QWidget::mapFromGlobal() to translate it to widget
coordinates.
@@ -197,10 +197,23 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QCursor::setPos(int x, int y)
+ \fn QPoint QCursor::pos()
+
+ Returns the position of the cursor (hot spot) of
+ the primary screen in global screen coordinates.
+
+ You can call QWidget::mapFromGlobal() to translate it to widget
+ coordinates.
+
+ \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen()
+*/
- Moves the cursor (hot spot) to the global screen position (\a x,
- \a y).
+
+/*!
+ \fn void QCursor::setPos(QScreen *screen, int x, int y)
+
+ Moves the cursor (hot spot) of the \a screen to the global
+ screen position (\a x, \a y).
You can call QWidget::mapToGlobal() to translate widget
coordinates to global screen coordinates.
@@ -209,6 +222,18 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn void QCursor::setPos(int x, int y)
+
+ Moves the cursor (hot spot) of the primary screen
+ to the global screen position (\a x, \a y).
+
+ You can call QWidget::mapToGlobal() to translate widget
+ coordinates to global screen coordinates.
+
+ \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen()
+*/
+
+/*!
\fn void QCursor::setPos (const QPoint &p)
\overload
@@ -217,6 +242,15 @@ QT_BEGIN_NAMESPACE
\a p.
*/
+/*!
+ \fn void QCursor::setPos (QScreen *screen,const QPoint &p)
+
+ \overload
+
+ Moves the cursor (hot spot) to the global screen position of the
+ \a screen at point \a p.
+*/
+
/*****************************************************************************
QCursor stream functions
*****************************************************************************/
diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h
index 00b709b308..4820bcee9b 100644
--- a/src/gui/kernel/qcursor.h
+++ b/src/gui/kernel/qcursor.h
@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
class QVariant;
+class QScreen;
/*
### The fake cursor has to go first with old qdoc.
@@ -101,8 +102,11 @@ public:
QPoint hotSpot() const;
static QPoint pos();
+ static QPoint pos(const QScreen *screen);
static void setPos(int x, int y);
+ static void setPos(QScreen *screen, int x, int y);
inline static void setPos(const QPoint &p) { setPos(p.x(), p.y()); }
+ inline static void setPos(QScreen *screen, const QPoint &p) { setPos(screen, p.x(), p.y()); }
#ifdef qdoc
HCURSOR_or_HANDLE handle() const;
diff --git a/src/gui/kernel/qcursor_qpa.cpp b/src/gui/kernel/qcursor_qpa.cpp
index 7ba2e1c580..1c719c839e 100644
--- a/src/gui/kernel/qcursor_qpa.cpp
+++ b/src/gui/kernel/qcursor_qpa.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include <qcursor.h>
+#include <qscreen.h>
#include <private/qcursor_p.h>
#include <qplatformcursor_qpa.h>
#include <private/qguiapplication_p.h>
@@ -110,27 +111,34 @@ void QCursorData::update()
QPoint QCursor::pos()
{
+ return QCursor::pos(QGuiApplication::primaryScreen());
+}
+
+QPoint QCursor::pos(const QScreen *screen)
+{
+ if (screen)
+ if (const QPlatformCursor *cursor = screen->handle()->cursor())
+ return cursor->pos();
return QGuiApplicationPrivate::lastCursorPosition.toPoint();
}
-void QCursor::setPos(int x, int y)
+void QCursor::setPos(QScreen *screen, int x, int y)
{
- QPoint target(x, y);
-
- // Need to check, since some X servers generate null mouse move
- // events, causing looping in applications which call setPos() on
- // every mouse move event.
- //
- if (pos() == target)
- return;
-
- QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances();
- int cursorCount = cursors.count();
- for (int i = 0; i < cursorCount; ++i) {
- const QWeakPointer<QPlatformCursor> &cursor(cursors.at(i));
- if (cursor)
- cursor.data()->setPos(target);
+ if (screen) {
+ if (QPlatformCursor *cursor = screen->handle()->cursor()) {
+ const QPoint pos = QPoint(x, y);
+ // Need to check, since some X servers generate null mouse move
+ // events, causing looping in applications which call setPos() on
+ // every mouse move event.
+ if (pos != cursor->pos())
+ cursor->setPos(pos);
+ }
}
}
+void QCursor::setPos(int x, int y)
+{
+ QCursor::setPos(QGuiApplication::primaryScreen(), x, y);
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index f5aea654fc..42ce3745de 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -978,10 +978,9 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers);
ev.setTimestamp(e->timestamp);
#ifndef QT_NO_CURSOR
- QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances();
- for (int i = 0; i < cursors.count(); ++i)
- if (cursors.at(i))
- cursors.at(i).data()->pointerEvent(ev);
+ if (const QScreen *screen = window->screen())
+ if (QPlatformCursor *cursor = screen->handle()->cursor())
+ cursor->pointerEvent(ev);
#endif
QGuiApplication::sendSpontaneousEvent(window, &ev);
if (!e->synthetic && !ev.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
@@ -1814,16 +1813,11 @@ void QGuiApplication::changeOverrideCursor(const QCursor &cursor)
#ifndef QT_NO_CURSOR
-static void applyCursor(QWindow *w, const QCursor &c)
-{
- QCursor cc = c;
- QList<QWeakPointer<QPlatformCursor> > cursors = QPlatformCursorPrivate::getInstances();
- int cursorCount = cursors.count();
- for (int i = 0; i < cursorCount; ++i) {
- const QWeakPointer<QPlatformCursor> &cursor(cursors.at(i));
- if (cursor)
- cursor.data()->changeCursor(&cc, w);
- }
+static inline void applyCursor(QWindow *w, QCursor c)
+{
+ if (const QScreen *screen = w->screen())
+ if (QPlatformCursor *cursor = screen->handle()->cursor())
+ cursor->changeCursor(&c, w);
}
static inline void applyCursor(const QList<QWindow *> &l, const QCursor &c)
diff --git a/src/gui/kernel/qplatformcursor_qpa.cpp b/src/gui/kernel/qplatformcursor_qpa.cpp
index fd7bcdcf18..a4e998ddbc 100644
--- a/src/gui/kernel/qplatformcursor_qpa.cpp
+++ b/src/gui/kernel/qplatformcursor_qpa.cpp
@@ -43,13 +43,22 @@
#include <QPainter>
#include <QBitmap>
#include <QGuiApplication>
+#include <QScreen>
+#include <QPlatformScreen>
#include <private/qguiapplication_p.h>
#include <QDebug>
QT_BEGIN_NAMESPACE
-QList <QWeakPointer<QPlatformCursor> > QPlatformCursorPrivate::instances;
+QList<QPlatformCursor *> QPlatformCursorPrivate::getInstances()
+{
+ QList<QPlatformCursor *> result;
+ foreach (const QScreen *screen, QGuiApplicationPrivate::screen_list)
+ if (QPlatformCursor *cursor = screen->handle()->cursor())
+ result.push_back(cursor);
+ return result;
+}
/*!
\class QPlatformCursor
@@ -93,10 +102,8 @@ QList <QWeakPointer<QPlatformCursor> > QPlatformCursorPrivate::instances;
Constructs a QPlatformCursor for the given \a screen.
*/
-QPlatformCursor::QPlatformCursor(QPlatformScreen *scr )
- : screen(scr)
+QPlatformCursor::QPlatformCursor()
{
- QPlatformCursorPrivate::instances.append(this);
}
QPoint QPlatformCursor::pos() const
diff --git a/src/gui/kernel/qplatformcursor_qpa.h b/src/gui/kernel/qplatformcursor_qpa.h
index a8cbb282fa..e29cf87d03 100644
--- a/src/gui/kernel/qplatformcursor_qpa.h
+++ b/src/gui/kernel/qplatformcursor_qpa.h
@@ -74,13 +74,12 @@ class QPlatformCursor;
class Q_GUI_EXPORT QPlatformCursorPrivate {
public:
- static QList<QWeakPointer<QPlatformCursor> > getInstances() { return instances; }
- static QList<QWeakPointer<QPlatformCursor> > instances;
+ static QList<QPlatformCursor *> getInstances();
};
class Q_GUI_EXPORT QPlatformCursor : public QObject {
public:
- QPlatformCursor(QPlatformScreen *);
+ QPlatformCursor();
// input methods
virtual void pointerEvent(const QMouseEvent & event) { Q_UNUSED(event); }
@@ -88,11 +87,8 @@ public:
virtual QPoint pos() const;
virtual void setPos(const QPoint &pos);
-protected:
- QPlatformScreen* screen; // Where to request an update
-
private:
- Q_DECLARE_PRIVATE(QPlatformCursor);
+ Q_DECLARE_PRIVATE(QPlatformCursor)
friend void qt_qpa_set_cursor(QWidget * w, bool force);
friend class QApplicationPrivate;
};
diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp
index c832d853f4..022f198073 100644
--- a/src/gui/kernel/qplatformscreen_qpa.cpp
+++ b/src/gui/kernel/qplatformscreen_qpa.cpp
@@ -41,6 +41,7 @@
#include "qplatformscreen_qpa.h"
#include <QtGui/qguiapplication.h>
+#include <QtGui/qplatformcursor_qpa.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/private/qplatformscreen_qpa_p.h>
#include <QtGui/qplatformintegration_qpa.h>
@@ -250,4 +251,14 @@ QPlatformScreenPageFlipper *QPlatformScreen::pageFlipper() const
return 0;
}
+/*!
+ Reimplement this function in subclass to return the cursor of the screen.
+
+ The default implementation returns 0.
+*/
+QPlatformCursor *QPlatformScreen::cursor() const
+{
+ return 0;
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qplatformscreen_qpa.h b/src/gui/kernel/qplatformscreen_qpa.h
index 7d74698074..b6eb91f9b2 100644
--- a/src/gui/kernel/qplatformscreen_qpa.h
+++ b/src/gui/kernel/qplatformscreen_qpa.h
@@ -63,6 +63,7 @@ class QPlatformBackingStore;
class QPlatformOpenGLContext;
class QPlatformScreenPrivate;
class QPlatformWindow;
+class QPlatformCursor;
class QPlatformScreenPageFlipper;
class QScreen;
class QSurfaceFormat;
@@ -103,6 +104,7 @@ public:
virtual QString name() const { return QString(); }
virtual QPlatformScreenPageFlipper *pageFlipper() const;
+ virtual QPlatformCursor *cursor() const;
protected:
QScopedPointer<QPlatformScreenPrivate> d_ptr;