summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qapplication.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-05-16 20:43:34 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-06-08 20:29:49 +0200
commit44fb925f50471ebc23dcccfaa4e9d9873b05d205 (patch)
treee4e212052b66242ff94aa98f6df7b15dbeb945f7 /src/widgets/kernel/qapplication.cpp
parenta061a646429c6e9d695458fc0ecb0021a30e12ee (diff)
Phase 2 of removing QDesktopWidget
Remove QDestopWidget public header, simplify the implementation that maintains a Qt::Desktop type QWidget for each QScreen, and turn QWidget's initial target screen into a QScreen pointer. QApplication::desktop() now takes an optional QScreen pointer, and returns a QWidget pointer, so that applications and widgets can get access to the root widget for a specific screen without having to resort to private APIs. QDesktopWidgetPrivate implementations to look up a screen for an index, widget, or point are now all inline functions that thinly wrap QGuiApplication::screens/screenAt calls. We should consider adding those as convenience APIs to QScreen instead. Note that QWidget::screen is assumed to return a valid pointer; there is code that handles the case that it returns nullptr (but also code that trusts that it never is nullptr), so this needs to be defined, verified with tests, and asserted. We can then simplify the code further. Change-Id: Ifc89be65a0dce265b6729feaf54121c35137cb94 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/widgets/kernel/qapplication.cpp')
-rw-r--r--src/widgets/kernel/qapplication.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp
index 0e96e8bc69..1af94efdf9 100644
--- a/src/widgets/kernel/qapplication.cpp
+++ b/src/widgets/kernel/qapplication.cpp
@@ -42,7 +42,7 @@
#include "qapplication.h"
#include "qclipboard.h"
#include "qcursor.h"
-#include "qdesktopwidget.h"
+#include "qdesktopwidget_p.h"
#include "qdir.h"
#include "qevent.h"
#include "qfile.h"
@@ -2521,22 +2521,30 @@ void QApplicationPrivate::sendSyntheticEnterLeave(QWidget *widget)
/*!
\internal
- Returns the desktop widget (also called the root window).
+ Returns the desktop widget (also called the root window) for \a screen.
+
+ If \a screen is nullptr, then the widget that represents the entire virtual
+ desktop is returned, and its geometry will be the union of all screens.
+
+ Use the desktop widget for a specific screen as the parent of a new toplevel
+ widget to position the widget on a specific screen.
The desktop may be composed of multiple screens, so it would be incorrect,
for example, to attempt to \e center some widget in the desktop's geometry.
- QDesktopWidget has various functions for obtaining useful geometries upon
- the desktop, such as QDesktopWidget::screenGeometry() and
- QDesktopWidget::availableGeometry().
+ Use QScreen::geometry() and QScreen::availableGeometry() to get the dimensions
+ of a specific screen instead.
*/
-QDesktopWidget *QApplication::desktop()
+QWidget *QApplication::desktop(QScreen *screen)
{
CHECK_QAPP_INSTANCE(nullptr)
if (!qt_desktopWidget || // not created yet
!(qt_desktopWidget->windowType() == Qt::Desktop)) { // reparented away
qt_desktopWidget = new QDesktopWidget();
}
- return qt_desktopWidget;
+ if (!screen)
+ return qt_desktopWidget;
+ QDesktopWidgetPrivate *dwp = static_cast<QDesktopWidgetPrivate*>(qt_widget_private(qt_desktopWidget));
+ return dwp->widgetForScreen(screen);
}
/*