| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtWaylandCompositor module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | #include <QtCore/QDir> |
| 30 | |
| 31 | #include <QtQml/qqmlextensionplugin.h> |
| 32 | |
| 33 | #include <QtQuick/QQuickItem> |
| 34 | |
| 35 | #include <QtWaylandCompositor/QWaylandQuickCompositor> |
| 36 | #include <QtWaylandCompositor/QWaylandQuickItem> |
| 37 | #include <QtWaylandCompositor/private/qwaylandquickhardwarelayer_p.h> |
| 38 | #include <QtWaylandCompositor/QWaylandQuickSurface> |
| 39 | #include <QtWaylandCompositor/QWaylandClient> |
| 40 | #include <QtWaylandCompositor/QWaylandQuickOutput> |
| 41 | #include <QtWaylandCompositor/QWaylandCompositorExtension> |
| 42 | #include <QtWaylandCompositor/QWaylandQuickExtension> |
| 43 | #include <QtWaylandCompositor/QWaylandSeat> |
| 44 | #if QT_CONFIG(draganddrop) |
| 45 | #include <QtWaylandCompositor/QWaylandDrag> |
| 46 | #endif |
| 47 | #include <QtWaylandCompositor/QWaylandKeymap> |
| 48 | #include <QtWaylandCompositor/QWaylandQuickShellSurfaceItem> |
| 49 | #include <QtWaylandCompositor/QWaylandResource> |
| 50 | |
| 51 | #include <QtWaylandCompositor/QWaylandQtWindowManager> |
| 52 | #include <QtWaylandCompositor/QWaylandWlScaler> |
| 53 | #include <QtWaylandCompositor/QWaylandWlShell> |
| 54 | #include <QtWaylandCompositor/QWaylandTextInputManager> |
| 55 | #include <QtWaylandCompositor/QWaylandXdgShellV5> |
| 56 | #include <QtWaylandCompositor/QWaylandXdgShellV6> |
| 57 | #include <QtWaylandCompositor/QWaylandXdgShell> |
| 58 | #include <QtWaylandCompositor/QWaylandXdgDecorationManagerV1> |
| 59 | #include <QtWaylandCompositor/QWaylandIdleInhibitManagerV1> |
| 60 | #include <QtWaylandCompositor/QWaylandQuickXdgOutputV1> |
| 61 | #include <QtWaylandCompositor/QWaylandIviApplication> |
| 62 | #include <QtWaylandCompositor/QWaylandIviSurface> |
| 63 | |
| 64 | #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> |
| 65 | #include "qwaylandmousetracker_p.h" |
| 66 | |
| 67 | QT_BEGIN_NAMESPACE |
| 68 | |
| 69 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CONTAINER_CLASS(QWaylandQuickCompositor) |
| 70 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandQtWindowManager) |
| 71 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandIdleInhibitManagerV1) |
| 72 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandIviApplication) |
| 73 | #if QT_DEPRECATED_SINCE(5, 13) |
| 74 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandWlScaler) |
| 75 | #endif |
| 76 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandWlShell) |
| 77 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgShellV5) |
| 78 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgShellV6) |
| 79 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgShell) |
| 80 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgDecorationManagerV1) |
| 81 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandXdgOutputManagerV1) |
| 82 | Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandTextInputManager) |
| 83 | |
| 84 | class QmlUrlResolver |
| 85 | { |
| 86 | public: |
| 87 | QmlUrlResolver(bool useResource, const QDir &qmlDir, const QString &qrcPath) |
| 88 | : m_useResource(useResource) |
| 89 | , m_qmlDir(qmlDir) |
| 90 | , m_qrcPath(qrcPath) |
| 91 | { } |
| 92 | |
| 93 | QUrl get(const QString &fileName) |
| 94 | { |
| 95 | return m_useResource ? QUrl(m_qrcPath + fileName) : |
| 96 | QUrl::fromLocalFile(localfile: m_qmlDir.filePath(fileName)); |
| 97 | } |
| 98 | private: |
| 99 | bool m_useResource; |
| 100 | const QDir m_qmlDir; |
| 101 | const QString m_qrcPath; |
| 102 | }; |
| 103 | |
| 104 | |
| 105 | //![class decl] |
| 106 | class QWaylandCompositorPlugin : public QQmlExtensionPlugin |
| 107 | { |
| 108 | Q_OBJECT |
| 109 | Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) |
| 110 | public: |
| 111 | void registerTypes(const char *uri) override |
| 112 | { |
| 113 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWayland.Compositor" )); |
| 114 | defineModule(uri); |
| 115 | |
| 116 | bool useResource = true; |
| 117 | QDir qmlDir(baseUrl().toLocalFile()); |
| 118 | if (qmlDir.exists(QStringLiteral("WaylandCursorItem.qml" ))) |
| 119 | useResource = false; |
| 120 | |
| 121 | QmlUrlResolver resolver(useResource, qmlDir, QStringLiteral("qrc:/QtWayland/Compositor/" )); |
| 122 | |
| 123 | qmlRegisterType(url: resolver.get(QStringLiteral("WaylandOutputWindow.qml" )), uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandOutputWindow" ); |
| 124 | qmlRegisterType(url: resolver.get(QStringLiteral("WaylandCursorItem.qml" )), uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandCursorItem" ); |
| 125 | } |
| 126 | |
| 127 | static void defineModule(const char *uri) |
| 128 | { |
| 129 | // This is needed so to guarantee that the import is available with the current |
| 130 | // Qt minor version even if no new types have been added since the last release. |
| 131 | qmlRegisterModule(uri, versionMajor: 1, QT_VERSION_MINOR); |
| 132 | |
| 133 | qmlRegisterType<QWaylandQuickCompositorQuickExtensionContainer>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandCompositor" ); |
| 134 | qmlRegisterType<QWaylandQuickItem>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandQuickItem" ); |
| 135 | qmlRegisterType<QWaylandQuickItem, 13>(uri, versionMajor: 1, versionMinor: 13, qmlName: "WaylandQuickItem" ); |
| 136 | #if QT_CONFIG(opengl) |
| 137 | qmlRegisterType<QWaylandQuickHardwareLayer>(uri, versionMajor: 1, versionMinor: 2, qmlName: "WaylandHardwareLayer" ); |
| 138 | #endif |
| 139 | qmlRegisterType<QWaylandMouseTracker>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandMouseTracker" ); |
| 140 | qmlRegisterType<QWaylandQuickOutput>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandOutput" ); |
| 141 | qmlRegisterType<QWaylandQuickSurface>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandSurface" ); |
| 142 | qmlRegisterType<QWaylandQuickSurface, 13>(uri, versionMajor: 1, versionMinor: 13, qmlName: "WaylandSurface" ); |
| 143 | qmlRegisterType<QWaylandKeymap>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandKeymap" ); |
| 144 | |
| 145 | qmlRegisterUncreatableType<QWaylandCompositorExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandExtension" , reason: QObject::tr(s: "Cannot create instance of WaylandExtension" )); |
| 146 | qmlRegisterUncreatableType<QWaylandClient>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandClient" , reason: QObject::tr(s: "Cannot create instance of WaylandClient" )); |
| 147 | qmlRegisterUncreatableType<QWaylandOutput>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandOutputBase" , reason: QObject::tr(s: "Cannot create instance of WaylandOutputBase, use WaylandOutput instead" )); |
| 148 | qmlRegisterUncreatableType<QWaylandSeat>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandSeat" , reason: QObject::tr(s: "Cannot create instance of WaylandSeat" )); |
| 149 | #if QT_CONFIG(draganddrop) |
| 150 | qmlRegisterUncreatableType<QWaylandDrag>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandDrag" , reason: QObject::tr(s: "Cannot create instance of WaylandDrag" )); |
| 151 | #endif |
| 152 | qmlRegisterUncreatableType<QWaylandCompositor>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandCompositorBase" , reason: QObject::tr(s: "Cannot create instance of WaylandCompositorBase, use WaylandCompositor instead" )); |
| 153 | qmlRegisterUncreatableType<QWaylandSurface>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandSurfaceBase" , reason: QObject::tr(s: "Cannot create instance of WaylandSurfaceBase, use WaylandSurface instead" )); |
| 154 | qmlRegisterUncreatableType<QWaylandShell>(uri, versionMajor: 1, versionMinor: 0, qmlName: "Shell" , reason: QObject::tr(s: "Cannot create instance of Shell" )); |
| 155 | qmlRegisterUncreatableType<QWaylandShellSurface>(uri, versionMajor: 1, versionMinor: 0, qmlName: "ShellSurface" , reason: QObject::tr(s: "Cannot create instance of ShellSurface" )); |
| 156 | qmlRegisterUncreatableType<QWaylandResource>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WaylandResource" , reason: QObject::tr(s: "Cannot create instance of WaylandResource" )); |
| 157 | |
| 158 | //This should probably be somewhere else |
| 159 | qmlRegisterType<QWaylandQtWindowManagerQuickExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "QtWindowManager" ); |
| 160 | qmlRegisterType<QWaylandIviApplicationQuickExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "IviApplication" ); |
| 161 | qmlRegisterType<QWaylandIviSurface>(uri, versionMajor: 1, versionMinor: 0, qmlName: "IviSurface" ); |
| 162 | qmlRegisterType<QWaylandWlShellQuickExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WlShell" ); |
| 163 | qmlRegisterType<QWaylandWlShellSurface>(uri, versionMajor: 1, versionMinor: 0, qmlName: "WlShellSurface" ); |
| 164 | qmlRegisterType<QWaylandQuickShellSurfaceItem>(uri, versionMajor: 1, versionMinor: 0, qmlName: "ShellSurfaceItem" ); |
| 165 | #if QT_DEPRECATED_SINCE(5, 15) |
| 166 | qmlRegisterUncreatableType<QWaylandXdgShellV5>(uri, versionMajor: 1, versionMinor: 0, qmlName: "XdgShellV5Base" , reason: QObject::tr(s: "Cannot create instance of XdgShellV5Base" )); |
| 167 | qmlRegisterType<QWaylandXdgShellV5QuickExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "XdgShellV5" ); |
| 168 | qmlRegisterType<QWaylandXdgSurfaceV5>(uri, versionMajor: 1, versionMinor: 0, qmlName: "XdgSurfaceV5" ); |
| 169 | qmlRegisterType<QWaylandXdgPopupV5>(uri, versionMajor: 1, versionMinor: 0, qmlName: "XdgPopupV5" ); |
| 170 | #endif |
| 171 | qmlRegisterType<QWaylandTextInputManagerQuickExtension>(uri, versionMajor: 1, versionMinor: 0, qmlName: "TextInputManager" ); |
| 172 | |
| 173 | #if QT_DEPRECATED_SINCE(5, 15) |
| 174 | qmlRegisterType<QWaylandXdgShellV6QuickExtension>(uri, versionMajor: 1, versionMinor: 1, qmlName: "XdgShellV6" ); |
| 175 | qmlRegisterType<QWaylandXdgSurfaceV6>(uri, versionMajor: 1, versionMinor: 1, qmlName: "XdgSurfaceV6" ); |
| 176 | qmlRegisterUncreatableType<QWaylandXdgToplevelV6>(uri, versionMajor: 1, versionMinor: 1, qmlName: "XdgToplevelV6" , reason: QObject::tr(s: "Cannot create instance of XdgShellToplevelV6" )); |
| 177 | qmlRegisterUncreatableType<QWaylandXdgPopupV6>(uri, versionMajor: 1, versionMinor: 1, qmlName: "XdgPopupV6" , reason: QObject::tr(s: "Cannot create instance of XdgShellPopupV6" )); |
| 178 | #endif |
| 179 | |
| 180 | qmlRegisterType<QWaylandXdgShellQuickExtension>(uri, versionMajor: 1, versionMinor: 3, qmlName: "XdgShell" ); |
| 181 | qmlRegisterType<QWaylandXdgSurface>(uri, versionMajor: 1, versionMinor: 3, qmlName: "XdgSurface" ); |
| 182 | qmlRegisterUncreatableType<QWaylandXdgToplevel>(uri, versionMajor: 1, versionMinor: 3, qmlName: "XdgToplevel" , reason: QObject::tr(s: "Cannot create instance of XdgShellToplevel" )); |
| 183 | qmlRegisterUncreatableType<QWaylandXdgPopup>(uri, versionMajor: 1, versionMinor: 3, qmlName: "XdgPopup" , reason: QObject::tr(s: "Cannot create instance of XdgShellPopup" )); |
| 184 | |
| 185 | qmlRegisterType<QWaylandXdgDecorationManagerV1QuickExtension>(uri, versionMajor: 1, versionMinor: 3, qmlName: "XdgDecorationManagerV1" ); |
| 186 | |
| 187 | #if QT_DEPRECATED_SINCE(5, 13) |
| 188 | qmlRegisterType<QWaylandWlScalerQuickExtension>(uri, versionMajor: 1, versionMinor: 13, qmlName: "WlScaler" ); |
| 189 | #endif |
| 190 | |
| 191 | qmlRegisterType<QWaylandIdleInhibitManagerV1QuickExtension>(uri, versionMajor: 1, versionMinor: 14, qmlName: "IdleInhibitManagerV1" ); |
| 192 | |
| 193 | qmlRegisterType<QWaylandXdgOutputManagerV1QuickExtension>(uri, versionMajor: 1, versionMinor: 14, qmlName: "XdgOutputManagerV1" ); |
| 194 | qmlRegisterType<QWaylandQuickXdgOutputV1>(uri, versionMajor: 1, versionMinor: 14, qmlName: "XdgOutputV1" ); |
| 195 | } |
| 196 | }; |
| 197 | //![class decl] |
| 198 | |
| 199 | QT_END_NAMESPACE |
| 200 | |
| 201 | #include "qwaylandquickcompositorplugin.moc" |
| 202 | |