From ad8a48e8f1b336099eab2a00c1c1e59abad8e717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 10 Sep 2017 14:58:49 +0200 Subject: Add QGuiApplication::screenAt() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtGui] It's now possible to retrieve the screen at a given point via QGuiApplication::screenAt(). Change-Id: Ic09514ec731d8cce5d453833e98fcd118a70600e Reviewed-by: Gatis Paeglis Reviewed-by: Błażej Szczygieł --- src/widgets/kernel/qdesktopwidget.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index 6077ac38db..1b9cf88efe 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -352,26 +352,8 @@ int QDesktopWidget::screenNumber(const QPoint &p) const int QDesktopWidgetPrivate::screenNumber(const QPoint &p) { - const QList screens = QGuiApplication::screens(); - if (!screens.isEmpty()) { - const QList 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 + QScreen *screen = QGuiApplication::screenAt(p); + return screen ? QGuiApplication::screens().indexOf(screen) : primaryScreen(); } void QDesktopWidget::resizeEvent(QResizeEvent *) -- cgit v1.2.3