diff options
author | David Redondo <qt@david-redondo.de> | 2023-12-04 11:47:19 +0100 |
---|---|---|
committer | David Redondo <qt@david-redondo.de> | 2023-12-08 14:53:37 +0100 |
commit | 706dafe347528dbcbaaf3b4d75fa78bd633d876b (patch) | |
tree | ea9a39483e4fe69dc2d5fbff26a719733d064de6 | |
parent | 1c42b1e8c754b45dfa9e183ae37a3bc823f82463 (diff) |
Make some QScreen native interfaces public
[ChangeLog][QtGui][QScreen] The QAndroidScreen, QWaylandScreen and
QWaylandWindow native interfaces are now available on QScreen to
provide a handle to the underlying platform screen.
Task-number: QTBUG-113795
Change-Id: I83d70046678dfb79ee08544ddfc1820f3ff2d118
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/gui/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gui/kernel/qplatformscreen_p.h | 33 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.cpp | 15 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qscreen_platform.h | 61 | ||||
-rw-r--r-- | src/gui/platform/android/qandroidnativeinterface.cpp | 16 | ||||
-rw-r--r-- | src/gui/platform/unix/qunixnativeinterface.cpp | 17 | ||||
-rw-r--r-- | src/gui/platform/windows/qwindowsnativeinterface.cpp | 16 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformscreen.h | 9 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowsscreen.h | 5 |
10 files changed, 123 insertions, 53 deletions
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index b86dbd2ae2..a44e36d748 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -131,7 +131,7 @@ qt_internal_add_module(Gui kernel/qplatformwindow.cpp kernel/qplatformwindow.h kernel/qplatformwindow_p.h kernel/qpointingdevice.cpp kernel/qpointingdevice.h kernel/qpointingdevice_p.h kernel/qrasterwindow.cpp kernel/qrasterwindow.h - kernel/qscreen.cpp kernel/qscreen.h kernel/qscreen_p.h + kernel/qscreen.cpp kernel/qscreen.h kernel/qscreen_p.h kernel/qscreen_platform.h kernel/qsessionmanager.cpp kernel/qsessionmanager.h kernel/qsessionmanager_p.h kernel/qstylehints.cpp kernel/qstylehints.h kernel/qstylehints_p.h kernel/qsurface.cpp kernel/qsurface.h diff --git a/src/gui/kernel/qplatformscreen_p.h b/src/gui/kernel/qplatformscreen_p.h index 2cbc75af77..345a90845c 100644 --- a/src/gui/kernel/qplatformscreen_p.h +++ b/src/gui/kernel/qplatformscreen_p.h @@ -20,14 +20,6 @@ #include <QtCore/qpointer.h> #include <QtCore/qnativeinterface.h> -#if defined(Q_OS_WIN32) -#include <qwindowdefs_win.h> -#endif - -#if QT_CONFIG(wayland) -struct wl_output; -#endif - QT_BEGIN_NAMESPACE class QScreen; @@ -75,31 +67,6 @@ struct Q_GUI_EXPORT QWebOSScreen virtual void addFlipListener(void (*callback)()) = 0; }; #endif - -#if defined(Q_OS_WIN32) || defined(Q_QDOC) -struct Q_GUI_EXPORT QWindowsScreen -{ - QT_DECLARE_NATIVE_INTERFACE(QWindowsScreen, 1, QScreen) - virtual HMONITOR handle() const = 0; -}; -#endif - -#if QT_CONFIG(wayland) || defined(Q_QDOC) -struct Q_GUI_EXPORT QWaylandScreen -{ - QT_DECLARE_NATIVE_INTERFACE(QWaylandScreen, 1, QScreen) - virtual wl_output *output() const = 0; -}; -#endif - -#if defined(Q_OS_ANDROID) || defined(Q_QDOC) -struct Q_GUI_EXPORT QAndroidScreen -{ - QT_DECLARE_NATIVE_INTERFACE(QAndroidScreen, 1, QScreen) - virtual int displayId() const = 0; -}; -#endif - } // QNativeInterface::Private QT_END_NAMESPACE diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index c5863d1463..aab39dd235 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -703,8 +703,23 @@ QPixmap QScreen::grabWindow(WId window, int x, int y, int width, int height) result.setDevicePixelRatio(result.devicePixelRatio() * factor); return result; } + +/*! + \fn template <typename QNativeInterface> QNativeInterface *QScreen::nativeInterface() const + + Returns a native interface of the given type for the screen. + + This function provides access to platform specific functionality + of QScreen, as defined in the QNativeInterface namespace: + + \annotatedlist native-interfaces-qscreen + + If the requested interface is not available a \nullptr is returned. + */ + void *QScreen::resolveInterface(const char *name, int revision) const { + using namespace QNativeInterface; using namespace QNativeInterface::Private; auto *platformScreen = handle(); diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h index d2fc74fbda..9442e7525b 100644 --- a/src/gui/kernel/qscreen.h +++ b/src/gui/kernel/qscreen.h @@ -147,5 +147,7 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QScreen *); QT_END_NAMESPACE +#include <QtGui/qscreen_platform.h> + #endif // QSCREEN_H diff --git a/src/gui/kernel/qscreen_platform.h b/src/gui/kernel/qscreen_platform.h new file mode 100644 index 0000000000..6f40e9273f --- /dev/null +++ b/src/gui/kernel/qscreen_platform.h @@ -0,0 +1,61 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#ifndef QSCREEN_PLATFORM_H +#define QSCREEN_PLATFORM_H + +// +// W A R N I N G +// ------------- +// +// This file is part of the native interface APIs. Usage of +// this API may make your code source and binary incompatible +// with future versions of Qt. +// + +#include <QtGui/qtguiglobal.h> + +#include <QtCore/qnativeinterface.h> +#include <QtGui/qguiapplication.h> + +#if defined(Q_OS_WIN32) +#include <QtGui/qwindowdefs_win.h> +#endif + +#if QT_CONFIG(wayland) +struct wl_output; +#endif + +QT_BEGIN_NAMESPACE + +namespace QNativeInterface { + +#if defined(Q_OS_WIN32) || defined(Q_QDOC) +struct Q_GUI_EXPORT QWindowsScreen +{ + QT_DECLARE_NATIVE_INTERFACE(QWindowsScreen, 1, QScreen) + virtual HMONITOR handle() const = 0; +}; +#endif + +#if QT_CONFIG(wayland) || defined(Q_QDOC) +struct Q_GUI_EXPORT QWaylandScreen +{ + QT_DECLARE_NATIVE_INTERFACE(QWaylandScreen, 1, QScreen) + virtual wl_output *output() const = 0; +}; +#endif + +#if defined(Q_OS_ANDROID) || defined(Q_QDOC) +struct Q_GUI_EXPORT QAndroidScreen +{ + QT_DECLARE_NATIVE_INTERFACE(QAndroidScreen, 1, QScreen) + virtual int displayId() const = 0; +}; +#endif + +} // namespace QNativeInterface + +QT_END_NAMESPACE + +#endif diff --git a/src/gui/platform/android/qandroidnativeinterface.cpp b/src/gui/platform/android/qandroidnativeinterface.cpp index 1bc718cbf1..b20df90a07 100644 --- a/src/gui/platform/android/qandroidnativeinterface.cpp +++ b/src/gui/platform/android/qandroidnativeinterface.cpp @@ -35,6 +35,20 @@ QOffscreenSurface *QNativeInterface::QAndroidOffscreenSurface::fromNative(ANati &QAndroidOffScreenIntegration::createOffscreenSurface>(nativeSurface); } -QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QAndroidScreen); +/*! + \class QNativeInterface::QAndroidScreen + \since 6.7 + \brief Native interface to a screen. + + Accessed through QScreen::nativeInterface(). + \inmodule QtGui + \ingroup native-interfaces + \ingroup native-interfaces-qscreen +*/ +/*! + \fn int QNativeInterface::QAndroidScreen::displayId() const; + \return The Id of the underlying Android display. +*/ +QT_DEFINE_NATIVE_INTERFACE(QAndroidScreen); QT_END_NAMESPACE diff --git a/src/gui/platform/unix/qunixnativeinterface.cpp b/src/gui/platform/unix/qunixnativeinterface.cpp index cf212c1740..09561d9ada 100644 --- a/src/gui/platform/unix/qunixnativeinterface.cpp +++ b/src/gui/platform/unix/qunixnativeinterface.cpp @@ -280,15 +280,20 @@ QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QEvdevKeyMapper); QT_DEFINE_NATIVE_INTERFACE(QWaylandApplication); /*! - \class QNativeInterface::Private::QWaylandScreen - \since 6.5 - \internal - \brief Native interface to QPlatformScreen. + \class QNativeInterface::QWaylandScreen + \since 6.7 + \brief Native interface to a screen on Wayland. + + Accessed through QScreen::nativeInterface(). \inmodule QtGui \ingroup native-interfaces + \ingroup native-interfaces-qscreen */ - -QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWaylandScreen); +/*! + \fn wl_output *QNativeInterface::QWaylandScreen::output() const + \return the underlying wl_output of this QScreen. +*/ +QT_DEFINE_NATIVE_INTERFACE(QWaylandScreen); /*! \class QNativeInterface::QWaylandWindow diff --git a/src/gui/platform/windows/qwindowsnativeinterface.cpp b/src/gui/platform/windows/qwindowsnativeinterface.cpp index 86c6593f5d..7ebddb5b9d 100644 --- a/src/gui/platform/windows/qwindowsnativeinterface.cpp +++ b/src/gui/platform/windows/qwindowsnativeinterface.cpp @@ -89,14 +89,20 @@ QOpenGLContext *QNativeInterface::QWGLContext::fromNative(HGLRC context, HWND wi QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWindowsApplication); /*! - \class QNativeInterface::Private::QWindowsScreen - \since 6.5 - \internal - \brief Native interface to QScreen, to be retrieved from QPlatformIntegration. + \class QNativeInterface::QWindowsScreen + \since 6.7 + \brief Native interface to a screen. + + Accessed through QScreen::nativeInterface(). \inmodule QtGui \ingroup native-interfaces + \ingroup native-interfaces-qscreen */ -QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWindowsScreen); +/*! + * \fn HWMONITOR QNativeInterface::QWindowsScreen::handle() const; + * \return The underlying HWMONITOR of the screen. + */ +QT_DEFINE_NATIVE_INTERFACE(QWindowsScreen); /*! \enum QNativeInterface::Private::QWindowsApplication::TouchWindowTouchType diff --git a/src/plugins/platforms/android/qandroidplatformscreen.h b/src/plugins/platforms/android/qandroidplatformscreen.h index 84efc43630..d850d0db09 100644 --- a/src/plugins/platforms/android/qandroidplatformscreen.h +++ b/src/plugins/platforms/android/qandroidplatformscreen.h @@ -11,15 +11,16 @@ #include <QWaitCondition> #include <QtCore/QJniObject> #include <qpa/qplatformscreen.h> -#include <qpa/qplatformscreen_p.h> +#include <QtGui/qscreen_platform.h> QT_BEGIN_NAMESPACE class QAndroidPlatformWindow; -class QAndroidPlatformScreen: public QObject, - public QPlatformScreen, - public QNativeInterface::Private::QAndroidScreen + +class QAndroidPlatformScreen : public QObject, + public QPlatformScreen, + public QNativeInterface::QAndroidScreen { Q_OBJECT public: diff --git a/src/plugins/platforms/windows/qwindowsscreen.h b/src/plugins/platforms/windows/qwindowsscreen.h index 8675a7dfac..0467ab2a0c 100644 --- a/src/plugins/platforms/windows/qwindowsscreen.h +++ b/src/plugins/platforms/windows/qwindowsscreen.h @@ -9,7 +9,7 @@ #include <QtCore/qlist.h> #include <QtCore/qscopedpointer.h> #include <qpa/qplatformscreen.h> -#include <qpa/qplatformscreen_p.h> +#include <QtGui/qscreen_platform.h> QT_BEGIN_NAMESPACE @@ -41,8 +41,7 @@ struct QWindowsScreenData std::optional<int> deviceIndex = std::nullopt; }; -class QWindowsScreen : public QPlatformScreen - , public QNativeInterface::Private::QWindowsScreen +class QWindowsScreen : public QPlatformScreen, public QNativeInterface::QWindowsScreen { public: #ifndef QT_NO_CURSOR |