- 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>
*/
/*!
- \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.
*/
/*!
- \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.
*/
/*!
+ \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
\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
*****************************************************************************/
class QVariant;
+class QScreen;
/*
### The fake cursor has to go first with old qdoc.
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;
****************************************************************************/
#include <qcursor.h>
+#include <qscreen.h>
#include <private/qcursor_p.h>
#include <qplatformcursor_qpa.h>
#include <private/qguiapplication_p.h>
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
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)) {
#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)
#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
Constructs a QPlatformCursor for the given \a screen.
*/
-QPlatformCursor::QPlatformCursor(QPlatformScreen *scr )
- : screen(scr)
+QPlatformCursor::QPlatformCursor()
{
- QPlatformCursorPrivate::instances.append(this);
}
QPoint QPlatformCursor::pos() const
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); }
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;
};
#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>
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
class QPlatformOpenGLContext;
class QPlatformScreenPrivate;
class QPlatformWindow;
+class QPlatformCursor;
class QPlatformScreenPageFlipper;
class QScreen;
class QSurfaceFormat;
virtual QString name() const { return QString(); }
virtual QPlatformScreenPageFlipper *pageFlipper() const;
+ virtual QPlatformCursor *cursor() const;
protected:
QScopedPointer<QPlatformScreenPrivate> d_ptr;
class QCocoaCursor : public QPlatformCursor
{
public:
- explicit QCocoaCursor(QPlatformScreen *);
+ QCocoaCursor();
virtual void changeCursor(QCursor * widgetCursor, QWindow * widget);
virtual QPoint pos() const;
QT_BEGIN_NAMESPACE
-QCocoaCursor::QCocoaCursor(QPlatformScreen *s) :
- QPlatformCursor(s)
+QCocoaCursor::QCocoaCursor()
{
// release cursors
QHash<Qt::CursorShape, NSCursor *>::const_iterator i = m_cursors.constBegin();
int depth() const { return m_depth; }
QImage::Format format() const { return m_format; }
QSizeF physicalSize() const { return m_physicalSize; }
+ QPlatformCursor *cursor() const { return m_cursor; }
public:
NSScreen *m_screen;
const qreal inch = 25.4;
m_physicalSize = QSizeF(m_geometry.size()) * inch / dpi;
- m_cursor = new QCocoaCursor(this);
+ m_cursor = new QCocoaCursor;
};
QCocoaScreen::~QCocoaScreen()
QT_BEGIN_NAMESPACE
QDirectFBCursor::QDirectFBCursor(QPlatformScreen *screen)
- : QPlatformCursor(screen)
+ : m_screen(screen)
{
m_image.reset(new QPlatformCursorImage(0, 0, 0, 0, 0, 0));
}
}
DFBResult res;
- IDirectFBDisplayLayer *layer = toDfbLayer(screen);
+ IDirectFBDisplayLayer *layer = toDfbLayer(m_screen);
IDirectFBSurface* surface(QDirectFbConvenience::dfbSurfaceForPlatformPixmap(map.handle()));
res = layer->SetCooperativeLevel(layer, DLSCL_ADMINISTRATIVE);
private:
QScopedPointer<QPlatformCursorImage> m_image;
+ QPlatformScreen *m_screen;
};
QT_END_NAMESPACE
int depth() const { return m_depth; }
QImage::Format format() const { return m_format; }
QSizeF physicalSize() const { return m_physicalSize; }
+ QPlatformCursor *cursor() const { return m_cursor.data(); }
// DirectFb helpers
IDirectFBDisplayLayer *dfbLayer() const;
QT_BEGIN_NAMESPACE
QKmsCursor::QKmsCursor(QKmsScreen *screen)
- : QPlatformCursor(screen), m_screen(screen),
+ : m_screen(screen),
m_graphicsBufferManager(screen->device()->gbmDevice())
{
gbm_bo *bo = gbm_bo_create(m_graphicsBufferManager, 64, 64,
return m_physicalSize;
}
+QPlatformCursor *QKmsScreen::cursor() const
+{
+ return m_cursor;
+}
+
GLuint QKmsScreen::framebufferObject() const
{
return m_bufferManager.framebufferObject();
int depth() const;
QImage::Format format() const;
QSizeF physicalSize() const;
+ QPlatformCursor *cursor() const;
GLuint framebufferObject() const;
quint32 crtcId() const { return m_crtcId; }
\sa QWindowsWindowCursor
*/
-QWindowsCursor::QWindowsCursor(QPlatformScreen *s) :
- QPlatformCursor(s)
-{
-}
-
HCURSOR QWindowsCursor::createPixmapCursor(const QPixmap &pixmap, int hotX, int hotY)
{
HCURSOR cur = 0;
class QWindowsCursor : public QPlatformCursor
{
public:
- explicit QWindowsCursor(QPlatformScreen *);
+ QWindowsCursor() {}
virtual void changeCursor(QCursor * widgetCursor, QWindow * widget);
virtual QPoint pos() const { return mousePosition(); }
return dbg;
}
+// Return the cursor to be shared by all screens (virtual desktop).
+static inline QSharedPointer<QWindowsCursor> sharedCursor()
+{
+ if (const QScreen *primaryScreen = QGuiApplication::primaryScreen())
+ return static_cast<const QWindowsScreen *>(primaryScreen->handle())->windowsCursor();
+ return QSharedPointer<QWindowsCursor>(new QWindowsCursor);
+}
+
/*!
\class QWindowsScreen
\brief Windows screen.
*/
QWindowsScreen::QWindowsScreen(const QWindowsScreenData &data) :
- m_data(data), m_cursor(this)
+ m_data(data), m_cursor(sharedCursor())
{
}
#include <QtCore/QList>
#include <QtCore/QPair>
+#include <QtCore/QSharedPointer>
#include <QtGui/QPlatformScreen>
QT_BEGIN_NAMESPACE
class QWindowsScreen : public QPlatformScreen
{
public:
+ typedef QSharedPointer<QWindowsCursor> WindowsCursorPtr;
+
explicit QWindowsScreen(const QWindowsScreenData &data);
static QWindowsScreen *screenOf(const QWindow *w = 0);
inline void handleChanges(const QWindowsScreenData &newData);
- const QWindowsCursor &cursor() const { return m_cursor; }
- QWindowsCursor &cursor() { return m_cursor; }
+ QPlatformCursor *cursor() const { return m_cursor.data(); }
+ const WindowsCursorPtr &windowsCursor() const { return m_cursor; }
const QWindowsScreenData &data() const { return m_data; }
private:
QWindowsScreenData m_data;
- QWindowsCursor m_cursor;
+ const WindowsCursorPtr m_cursor;
};
class QWindowsScreenManager
m_windowState(aWindow->windowState()),
m_opacity(1.0),
m_mouseGrab(false),
- m_cursor(QWindowsScreen::screenOf(aWindow)->cursor().standardWindowCursor()),
+ m_cursor(QWindowsScreen::screenOf(aWindow)->windowsCursor()->standardWindowCursor()),
m_dropTarget(0),
m_savedStyle(0)
{
};
QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
- : QXcbObject(conn), QPlatformCursor(screen), m_screen(screen)
+ : QXcbObject(conn), m_screen(screen)
{
if (cursorCount++)
return;
return QSizeF(m_screen->width_in_millimeters, m_screen->height_in_millimeters);
}
+QPlatformCursor *QXcbScreen::cursor() const
+{
+ return m_cursor;
+}
+
int QXcbScreen::screenNumber() const
{
return m_number;
int depth() const;
QImage::Format format() const;
QSizeF physicalSize() const;
+ QPlatformCursor *cursor() const;
int screenNumber() const;
QT_BEGIN_NAMESPACE
-QXlibCursor::QXlibCursor(QXlibScreen *screen)
- : QPlatformCursor(screen)
+QXlibCursor::QXlibCursor(QXlibScreen *screen) : m_screen(screen)
{
}
return cursor;
}
-QXlibScreen * QXlibCursor::testLiteScreen() const
-{
- return static_cast<QXlibScreen *>(screen);
-}
-
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
-class QXlibCursor : QPlatformCursor
+class QXlibCursor : public QPlatformCursor
{
public:
QXlibCursor(QXlibScreen *screen);
Cursor createCursorBitmap(QCursor * cursor);
Cursor createCursorShape(int cshape);
- QXlibScreen *testLiteScreen() const;
+ QXlibScreen *testLiteScreen() const { return m_screen; }
QMap<int, Cursor> cursorMap;
+ QXlibScreen *m_screen;
};
QT_END_NAMESPACE
delete mDisplay;
}
+QPlatformCursor *QXlibScreen::cursor() const
+{
+ return mCursor;
+}
+
Window QXlibScreen::rootWindow()
{
return RootWindow(mDisplay->nativeDisplay(), mScreen);
int depth() const { return mDepth; }
QImage::Format format() const { return mFormat; }
QSizeF physicalSize() const { return mPhysicalSize; }
+ QPlatformCursor *cursor() const;
Window rootWindow();
unsigned long blackPixel();
}
#ifndef QT_NO_CURSOR
-static void applyCursor(QWidget *w, const QCursor &c)
+static inline void applyCursor(QWidget *w, 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->window()->windowHandle());
- }
+ if (QWindow *window = w->windowHandle())
+ if (const QScreen *screen = window->screen())
+ if (QPlatformCursor *cursor = screen->handle()->cursor())
+ cursor->changeCursor(&c, window);
}
void qt_qpa_set_cursor(QWidget *w, bool force)
QPointF newMouseScenePos = view.mapToScene(mouseViewPos);
qreal slack = 1;
- QEXPECT_FAIL("", "QTBUG-22455", Abort);
- QVERIFY(qAbs(newMouseScenePos.x() - mouseScenePos.x()) < slack);
- QVERIFY(qAbs(newMouseScenePos.y() - mouseScenePos.y()) < slack);
+
+ const qreal dx = qAbs(newMouseScenePos.x() - mouseScenePos.x());
+ const qreal dy = qAbs(newMouseScenePos.y() - mouseScenePos.y());
+ const QByteArray message = QString::fromLatin1("QTBUG-22455, distance: dx=%1, dy=%2 slack=%3 (%4).").
+ arg(dx).arg(dy).arg(slack).arg(qApp->style()->metaObject()->className()).toLocal8Bit();
+ // This is highly unstable (observed to pass on Windows and some Linux configurations).
+#ifdef Q_OS_MAC
+ QEXPECT_FAIL("", message.constData(), Abort);
+#endif
+ QVERIFY2(dx < slack && dy < slack, message.constData());
#endif
}
QCOMPARE(hasFocus, focus);
bool isUnderMouse = option.state & QStyle::State_MouseOver;
#ifndef Q_OS_WINCE
-# if !defined(Q_OS_MAC) && !defined(Q_OS_WIN)
- QEXPECT_FAIL("all", "QTBUG-22457", Abort);
-# endif
QCOMPARE(isUnderMouse, underMouse);
#endif
// if (layoutDirection != Qt::LeftToRight)
QTest::mouseClick(menu, Qt::LeftButton, 0, QPoint(3, 3), 10);
QTest::qWait(100);
-#ifndef Q_OS_MAC
- QEXPECT_FAIL("", "QTBUG-22565", Abort);
-#endif
QVERIFY(menu->isTearOffMenuVisible());
QPointer<QMenu> torn = 0;
foreach (QWidget *w, QApplication::allWidgets()) {
#ifdef Q_OS_WINCE_WM
QSKIP("Mouse move related signals for Windows Mobile unavailable");
#endif
- // ### fixme: Check platforms
- QSKIP("QTBUG-20753 QCursor::setPos() / QTest::mouseMove() doesn't work on qpa");
-
Menu258920 menu;
// For styles which inherit from QWindowsStyle, styleHint(QStyle::SH_Menu_MouseTracking) is true.
menu.setMouseTracking(true);