diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:08:55 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:14:54 +0200 |
commit | aadfe7d634de04519102c5827ca885dc2e2199c9 (patch) | |
tree | d92db346ca95332b177036a53f1f6beb2e24fb74 /src/gui/kernel/qguiapplication.cpp | |
parent | 4b6c1448047362b8c38d265e6414f0e3e59b8d37 (diff) | |
parent | a732e16d5fd9dbf8a0289fec9f948b12e9ba2c19 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/gui/kernel/qguiapplication.cpp
src/platformsupport/input/libinput/qlibinputpointer.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
src/plugins/platforms/cocoa/qcocoawindow.h
src/testlib/qtestsystem.h
Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
Diffstat (limited to 'src/gui/kernel/qguiapplication.cpp')
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 88d04f978e..35332831d4 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -988,6 +988,34 @@ QList<QScreen *> QGuiApplication::screens() } /*! + Returns the screen at \a point, or \c nullptr if outside of any screen. + + The \a point is in relation to the virtualGeometry() of each set of virtual + siblings. If the point maps to more than one set of virtual siblings the first + match is returned. + + \since 5.10 +*/ +QScreen *QGuiApplication::screenAt(const QPoint &point) +{ + QVarLengthArray<const QScreen *, 8> visitedScreens; + for (const QScreen *screen : QGuiApplication::screens()) { + if (visitedScreens.contains(screen)) + continue; + + // The virtual siblings include the screen itself, so iterate directly + for (QScreen *sibling : screen->virtualSiblings()) { + if (sibling->geometry().contains(point)) + return sibling; + + visitedScreens.append(sibling); + } + } + + return nullptr; +} + +/*! \fn void QGuiApplication::screenAdded(QScreen *screen) This signal is emitted whenever a new screen \a screen has been added to the system. @@ -1050,36 +1078,9 @@ qreal QGuiApplication::devicePixelRatio() const */ QWindow *QGuiApplication::topLevelAt(const QPoint &pos) { - const QList<QScreen *> screens = QGuiApplication::screens(); - if (!screens.isEmpty()) { - const QList<QScreen *> primaryScreens = screens.first()->virtualSiblings(); - QScreen *windowScreen = nullptr; - - // Find the window on the primary virtual desktop first - for (QScreen *screen : primaryScreens) { - if (screen->geometry().contains(pos)) { - windowScreen = screen; - break; - } - } - - // If the window is not found on primary virtual desktop, find it on all screens - // except the first which was for sure in the previous loop. Some other screens - // may repeat. Find only when there is more than one virtual desktop. - if (!windowScreen && screens.count() != primaryScreens.count()) { - for (int i = 1; i < screens.size(); ++i) { - QScreen *screen = screens.at(i); - if (screen->geometry().contains(pos)) { - windowScreen = screen; - break; - } - } - } - - if (windowScreen) { - const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen); - return windowScreen->handle()->topLevelAt(devicePosition); - } + if (QScreen *windowScreen = screenAt(pos)) { + const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen); + return windowScreen->handle()->topLevelAt(devicePosition); } return nullptr; } @@ -2419,7 +2420,7 @@ void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate:: if (e->window.isNull()) return; - QNativeGestureEvent ev(e->type, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue); + QNativeGestureEvent ev(e->type, e->device, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue); ev.setTimestamp(e->timestamp); QGuiApplication::sendSpontaneousEvent(e->window, &ev); } |