summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBłażej Szczygieł <spaz16@wp.pl>2016-01-01 13:56:04 +0100
committerBłażej Szczygieł <spaz16@wp.pl>2016-01-06 16:02:20 +0000
commitb50f0244c8f1b8e229a71018f39ac373d0ba6a1e (patch)
tree8f017d3c6af7167bab79c53f37897009783e1f52 /src
parent1606a0e508b8ecdcbdff953ef55136c8ff59ba79 (diff)
QDesktopWidget::screenNumber(QPoint): fix handling of virtual desktops
On X11, QXcbVirtualDesktop represents an X11 screen while QScreen represents an X11 output. In the case that there are multiple screens (possibly with multiple outputs), calculate the screen number correctly: Find the screen index on the primary virtual desktop first to avoid obtaining a screen index which doesn't belong to the primary virtual desktop when screen geometry is similar. Change-Id: I4cbb29b7aa7cd2125759ffbbbe3db4e934feaeae Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
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
}