summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qdesktopwidget.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp
index e586be206e..a1c2aebbe6 100644
--- a/src/widgets/kernel/qdesktopwidget.cpp
+++ b/src/widgets/kernel/qdesktopwidget.cpp
@@ -239,12 +239,25 @@ int QDesktopWidget::screenNumber(const QWidget *w) const
int QDesktopWidget::screenNumber(const QPoint &p) const
{
- QList<QScreen *> screens = QGuiApplication::screens();
-
- for (int i = 0; i < screens.size(); ++i)
- if (screens.at(i)->geometry().contains(p))
- return i;
-
+ const QList<QScreen *> screens = QGuiApplication::screens();
+ if (!screens.isEmpty()) {
+ const QList<QScreen *> primaryScreens = screens.first()->virtualSiblings();
+ // Find the screen index on the primary virtual desktop first
+ foreach (QScreen *screen, primaryScreens) {
+ if (screen->geometry().contains(p))
+ return screens.indexOf(screen);
+ }
+ // If the screen index is not found on primary virtual desktop, find
+ // the screen index 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 (screens.count() != primaryScreens.count()) {
+ for (int i = 1; i < screens.size(); ++i) {
+ if (screens[i]->geometry().contains(p))
+ return i;
+ }
+ }
+ }
return primaryScreen(); //even better would be closest screen
}