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>
This commit is contained in:
parent
1606a0e508
commit
b50f0244c8
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user