summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorBłażej Szczygieł <spaz16@wp.pl>2016-01-05 15:25:12 +0100
committerBłażej Szczygieł <spaz16@wp.pl>2016-01-07 11:02:28 +0000
commit7e28079484ec12ce0609419262b869354e7678a7 (patch)
treebd0989225e7b57138adc4b5983cdac210528d589 /src/gui/kernel
parenteb0b03c579cfd90ebfeeaa115955a0a924c9ce0f (diff)
QtGui: Fix obtaining the top level window at a point
Find the top level window on the primary virtual desktop first to avoid obtaining a window which doesn't belong to the primary virtual desktop when screen geometry is similar. Change-Id: I78fdfa0b5146d0ba9b912338adeb612c102c4ac3 Reviewed-by: Adam Majer <adamm@zombino.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 00245b25b0..00e3e2fcf4 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -964,18 +964,38 @@ qreal QGuiApplication::devicePixelRatio() const
*/
QWindow *QGuiApplication::topLevelAt(const QPoint &pos)
{
- QList<QScreen *> screens = QGuiApplication::screens();
- QList<QScreen *>::const_iterator screen = screens.constBegin();
- QList<QScreen *>::const_iterator end = screens.constEnd();
-
- while (screen != end) {
- if ((*screen)->geometry().contains(pos)) {
- const QPoint devicePosition = QHighDpi::toNativePixels(pos, *screen);
- return (*screen)->handle()->topLevelAt(devicePosition);
+ const QList<QScreen *> screens = QGuiApplication::screens();
+ if (!screens.isEmpty()) {
+ const QList<QScreen *> primaryScreens = screens.first()->virtualSiblings();
+ QScreen *windowScreen = Q_NULLPTR;
+
+ // Find the window on the primary virtual desktop first
+ foreach (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[i];
+ if (screen->geometry().contains(pos)) {
+ windowScreen = screen;
+ break;
+ }
+ }
+ }
+
+ if (windowScreen) {
+ const QPoint devicePosition = QHighDpi::toNativePixels(pos, windowScreen);
+ return windowScreen->handle()->topLevelAt(devicePosition);
}
- ++screen;
}
- return 0;
+ return Q_NULLPTR;
}
/*!