diff options
Diffstat (limited to 'src/compositor/compositor_api')
64 files changed, 2577 insertions, 2910 deletions
diff --git a/src/compositor/compositor_api/compositor_api.pri b/src/compositor/compositor_api/compositor_api.pri index 8dbe12ac1..d8cfcaad3 100644 --- a/src/compositor/compositor_api/compositor_api.pri +++ b/src/compositor/compositor_api/compositor_api.pri @@ -27,8 +27,7 @@ HEADERS += \ compositor_api/qwaylandview_p.h \ compositor_api/qwaylandresource.h \ compositor_api/qwaylandsurfacegrabber.h \ - compositor_api/qwaylandoutputmode_p.h \ - compositor_api/qwaylandquickchildren.h + compositor_api/qwaylandoutputmode_p.h SOURCES += \ compositor_api/qwaylandcompositor.cpp \ @@ -55,7 +54,7 @@ qtConfig(im) { compositor_api/qwaylandinputmethodcontrol.cpp } -QT += core-private +QT += core-private gui-private qtConfig(draganddrop) { HEADERS += \ @@ -64,23 +63,31 @@ qtConfig(draganddrop) { compositor_api/qwaylanddrag.cpp } -qtHaveModule(quick):qtConfig(opengl) { - DEFINES += QT_WAYLAND_COMPOSITOR_QUICK - +qtConfig(wayland-compositor-quick) { SOURCES += \ + compositor_api/qwaylandmousetracker.cpp \ compositor_api/qwaylandquickcompositor.cpp \ compositor_api/qwaylandquicksurface.cpp \ compositor_api/qwaylandquickoutput.cpp \ - compositor_api/qwaylandquickitem.cpp \ - compositor_api/qwaylandquickhardwarelayer.cpp + compositor_api/qwaylandquickitem.cpp HEADERS += \ + compositor_api/qwaylandcompositorquickextensions_p.h \ + compositor_api/qwaylandmousetracker_p.h \ + compositor_api/qwaylandquickchildren.h \ compositor_api/qwaylandquickcompositor.h \ compositor_api/qwaylandquicksurface.h \ + compositor_api/qwaylandquicksurface_p.h \ compositor_api/qwaylandquickoutput.h \ compositor_api/qwaylandquickitem.h \ - compositor_api/qwaylandquickitem_p.h \ - compositor_api/qwaylandquickhardwarelayer_p.h + compositor_api/qwaylandquickitem_p.h + + qtConfig(opengl) { + SOURCES += \ + compositor_api/qwaylandquickhardwarelayer.cpp + HEADERS += \ + compositor_api/qwaylandquickhardwarelayer_p.h + } QT += qml qml-private quick quick-private } diff --git a/src/compositor/compositor_api/qwaylandbufferref.cpp b/src/compositor/compositor_api/qwaylandbufferref.cpp index ab34d1253..556bc0925 100644 --- a/src/compositor/compositor_api/qwaylandbufferref.cpp +++ b/src/compositor/compositor_api/qwaylandbufferref.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QAtomicInt> @@ -43,8 +7,34 @@ #include "qwaylandbufferref.h" #include "wayland_wrapper/qwlclientbuffer_p.h" +#include <type_traits> + QT_BEGIN_NAMESPACE +#define CHECK1(l, r, op) \ + static_assert(std::is_same_v< \ + bool, \ + decltype(std::declval<QWaylandBufferRef l >() op \ + std::declval<QWaylandBufferRef r >()) \ + >) +#define CHECK2(l, r) \ + CHECK1(l, r, ==); \ + CHECK1(l, r, !=) +#define CHECK(l, r) \ + CHECK2(l, r); \ + CHECK2(l &, r); \ + CHECK2(l &, r &); \ + CHECK2(l, r &) + +CHECK(, ); +CHECK(const, ); +CHECK(const, const); +CHECK(, const); + +#undef CHECK +#undef CHECK2 +#undef CHECK1 + class QWaylandBufferRefPrivate { public: @@ -124,22 +114,22 @@ QWaylandBufferRef &QWaylandBufferRef::operator=(const QWaylandBufferRef &ref) } /*! - * Returns true if this QWaylandBufferRef references the same buffer as \a ref. - * Otherwise returns false. + \fn bool QWaylandBufferRef::operator==(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) + + Returns \c true if \a lhs references the same buffer as \a rhs. + Otherwise returns \c{false}. */ -bool QWaylandBufferRef::operator==(const QWaylandBufferRef &ref) +bool operator==(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) noexcept { - return d->buffer == ref.d->buffer; + return lhs.d->buffer == rhs.d->buffer; } /*! - * Returns false if this QWaylandBufferRef references the same buffer as \a ref. - * Otherwise returns true. + \fn bool QWaylandBufferRef::operator!=(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) + + Returns \c false if \a lhs references the same buffer as \a rhs. + Otherwise returns \c {true}. */ -bool QWaylandBufferRef::operator!=(const QWaylandBufferRef &ref) -{ - return d->buffer != ref.d->buffer; -} /*! * Returns true if this QWaylandBufferRef does not reference a buffer. @@ -170,6 +160,19 @@ bool QWaylandBufferRef::hasContent() const { return QtWayland::ClientBuffer::hasContent(d->buffer); } +/*! + * Returns true if this QWaylandBufferRef references a buffer that has protected content. Otherwise returns false. + * + * \note This is an enabler which presumes support in the client buffer integration. None of the + * client buffer integrations included with Qt currently support protected content buffers. + * + * \since 6.2 + * \sa hasContent() + */ +bool QWaylandBufferRef::hasProtectedContent() const +{ + return QtWayland::ClientBuffer::hasProtectedContent(d->buffer); +} /*! * Returns true if this QWaylandBufferRef references a buffer that diff --git a/src/compositor/compositor_api/qwaylandbufferref.h b/src/compositor/compositor_api/qwaylandbufferref.h index e84d7f3a2..a917726f0 100644 --- a/src/compositor/compositor_api/qwaylandbufferref.h +++ b/src/compositor/compositor_api/qwaylandbufferref.h @@ -1,54 +1,17 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDBUFFERREF_H #define QWAYLANDBUFFERREF_H #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> -#include <QImage> +#include <QtGui/QImage> #if QT_CONFIG(opengl) #include <QtGui/qopengl.h> #endif #include <QtWaylandCompositor/QWaylandSurface> -#include <QtWaylandCompositor/qtwaylandcompositorglobal.h> struct wl_resource; @@ -61,7 +24,7 @@ namespace QtWayland class ClientBuffer; } -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandBufferRef +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandBufferRef { public: QWaylandBufferRef(); @@ -72,9 +35,12 @@ public: bool isNull() const; bool hasBuffer() const; bool hasContent() const; + bool hasProtectedContent() const; bool isDestroyed() const; +#if QT_WAYLANDCOMPOSITOR_REMOVED_SINCE(6, 3) bool operator==(const QWaylandBufferRef &ref); bool operator!=(const QWaylandBufferRef &ref); +#endif struct wl_resource *wl_buffer() const; @@ -116,6 +82,12 @@ private: class QWaylandBufferRefPrivate *const d; friend class QWaylandBufferRefPrivate; friend class QWaylandSurfacePrivate; + + friend Q_WAYLANDCOMPOSITOR_EXPORT + bool operator==(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) noexcept; + friend inline + bool operator!=(const QWaylandBufferRef &lhs, const QWaylandBufferRef &rhs) noexcept + { return !(lhs == rhs); } }; QT_END_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandclient.cpp b/src/compositor/compositor_api/qwaylandclient.cpp index 7f0b225b2..9c8bc704f 100644 --- a/src/compositor/compositor_api/qwaylandclient.cpp +++ b/src/compositor/compositor_api/qwaylandclient.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandclient.h" #include <QtCore/private/qobject_p.h> @@ -44,7 +8,7 @@ #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> -#include <wayland-server.h> +#include <wayland-server-core.h> #include <wayland-util.h> QT_BEGIN_NAMESPACE @@ -85,10 +49,13 @@ public: QWaylandClient *parent = nullptr; }; Listener listener; + + QWaylandClient::TextInputProtocols mTextInputProtocols = QWaylandClient::NoProtocol; }; /*! * \qmltype WaylandClient + * \instantiates QWaylandClient * \inqmlmodule QtWayland.Compositor * \since 5.8 * \brief Represents a client connecting to the WaylandCompositor. @@ -167,7 +134,7 @@ QWaylandClient *QWaylandClient::fromWlClient(QWaylandCompositor *compositor, wl_ } /*! - * \qmlproperty WaylandCompositor QtWaylandCompositor::WaylandClient::compositor + * \qmlproperty WaylandCompositor QtWayland.Compositor::WaylandClient::compositor * * This property holds the compositor of this WaylandClient. */ @@ -195,7 +162,7 @@ wl_client *QWaylandClient::client() const } /*! - * \qmlproperty int QtWaylandCompositor::WaylandClient::userId + * \qmlproperty int QtWayland.Compositor::WaylandClient::userId * * This property holds the user id of this WaylandClient. */ @@ -214,7 +181,7 @@ qint64 QWaylandClient::userId() const } /*! - * \qmlproperty int QtWaylandCompositor::WaylandClient::groupId + * \qmlproperty int QtWayland.Compositor::WaylandClient::groupId * \readonly * * This property holds the group id of this WaylandClient. @@ -233,7 +200,7 @@ qint64 QWaylandClient::groupId() const } /*! - * \qmlproperty int QtWaylandCompositor::WaylandClient::processId + * \qmlproperty int QtWayland.Compositor::WaylandClient::processId * \readonly * * This property holds the process id of this WaylandClient. @@ -252,7 +219,7 @@ qint64 QWaylandClient::processId() const } /*! - * \qmlmethod void QtWaylandCompositor::WaylandClient::kill(signal) + * \qmlmethod void QtWayland.Compositor::WaylandClient::kill(signal) * * Kills the client with the specified \a signal. */ @@ -268,7 +235,7 @@ void QWaylandClient::kill(int signal) } /*! - * \qmlmethod void QtWaylandCompositor::WaylandClient::close() + * \qmlmethod void QtWayland.Compositor::WaylandClient::close() * * Closes the client */ @@ -282,4 +249,20 @@ void QWaylandClient::close() d->compositor->destroyClient(this); } +QWaylandClient::TextInputProtocols QWaylandClient::textInputProtocols() const +{ + Q_D(const QWaylandClient); + return d->mTextInputProtocols; +} + +void QWaylandClient::setTextInputProtocols(TextInputProtocols p) +{ + Q_D(QWaylandClient); + if (d->mTextInputProtocols != p) + d->mTextInputProtocols = p; +} + QT_END_NAMESPACE + +#include "moc_qwaylandclient.cpp" + diff --git a/src/compositor/compositor_api/qwaylandclient.h b/src/compositor/compositor_api/qwaylandclient.h index bff1bcd24..fd6172a4f 100644 --- a/src/compositor/compositor_api/qwaylandclient.h +++ b/src/compositor/compositor_api/qwaylandclient.h @@ -1,48 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDCLIENT_H #define QWAYLANDCLIENT_H #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> -#include <QObject> +#include <QtCore/QObject> #include <signal.h> @@ -53,7 +18,7 @@ QT_BEGIN_NAMESPACE class QWaylandClientPrivate; class QWaylandCompositor; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandClient : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandClient : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandClient) @@ -62,9 +27,30 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandClient : public QObject Q_PROPERTY(qint64 userId READ userId CONSTANT) Q_PROPERTY(qint64 groupId READ groupId CONSTANT) Q_PROPERTY(qint64 processId READ processId CONSTANT) + Q_MOC_INCLUDE("qwaylandcompositor.h") + + QML_NAMED_ELEMENT(WaylandClient) + QML_ADDED_IN_VERSION(1, 0) + QML_UNCREATABLE("") public: ~QWaylandClient() override; + enum TextInputProtocol { + NoProtocol = 0, + QtTextInputMethodV1 = 1, + TextInputV2 = 2, + TextInputV3 = 4, + + TextInputV4 = TextInputV3, // TextInputV4 was an experimental API that is now deprecated + + QtTextInputMethod = QtTextInputMethodV1, + TextInput = TextInputV2 + }; + Q_DECLARE_FLAGS(TextInputProtocols, TextInputProtocol) + + TextInputProtocols textInputProtocols() const; + void setTextInputProtocols(TextInputProtocols p); + static QWaylandClient *fromWlClient(QWaylandCompositor *compositor, wl_client *wlClient); QWaylandCompositor *compositor() const; diff --git a/src/compositor/compositor_api/qwaylandcompositor.cpp b/src/compositor/compositor_api/qwaylandcompositor.cpp index 52ffb9166..b3433f426 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandcompositor.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qtwaylandcompositorglobal_p.h" #include "qwaylandcompositor.h" @@ -72,12 +36,12 @@ #include "extensions/qwaylandqtwindowmanager.h" -#include "qwaylandxkb_p.h" #include "qwaylandsharedmemoryformathelper_p.h" #include <QtCore/QCoreApplication> #include <QtCore/QStringList> #include <QtCore/QSocketNotifier> +#include <QStandardPaths> #include <QtGui/QDesktopServices> #include <QtGui/QScreen> @@ -96,9 +60,19 @@ QT_BEGIN_NAMESPACE -Q_LOGGING_CATEGORY(qLcWaylandCompositor, "qt.waylandcompositor") -Q_LOGGING_CATEGORY(qLcWaylandCompositorHardwareIntegration, "qt.waylandcompositor.hardwareintegration") -Q_LOGGING_CATEGORY(qLcWaylandCompositorInputMethods, "qt.waylandcompositor.inputmethods") +// These logging categories are public symbols. To remain binary-compatible we cannot hide them in +// a namespace like we do for all Qt-internal logging categories. +#define Q_PUBLIC_LOGGING_CATEGORY(name, ...) \ + const QLoggingCategory &name() \ + { \ + static const QLoggingCategory category(__VA_ARGS__); \ + return category; \ + } + +Q_PUBLIC_LOGGING_CATEGORY(qLcWaylandCompositor, "qt.waylandcompositor") +Q_PUBLIC_LOGGING_CATEGORY(qLcWaylandCompositorHardwareIntegration, "qt.waylandcompositor.hardwareintegration") +Q_PUBLIC_LOGGING_CATEGORY(qLcWaylandCompositorInputMethods, "qt.waylandcompositor.inputmethods") +Q_PUBLIC_LOGGING_CATEGORY(qLcWaylandCompositorTextInput, "qt.waylandcompositor.textinput") namespace QtWayland { @@ -125,16 +99,27 @@ public: QWaylandKeyboardPrivate *keyb = QWaylandKeyboardPrivate::get(seat->keyboard()); +#if defined(Q_OS_QNX) + // The QNX platform plugin delivers scan codes that haven't been adjusted to be + // xkbcommon compatible. xkbcommon requires that the scan codes be bumped up by + // 8 because that's how evdev/XKB deliver scan codes. You might think that it + // would've been better to remove this (odd) requirement from xkbcommon on QNX + // but it turns out that conforming to it has much less impact. + static int offset = QGuiApplication::platformName() == QStringLiteral("qnx") ? 8 : 0; + ke->nativeScanCode += offset; +#endif uint32_t code = ke->nativeScanCode; + if (code == 0) + code = seat->keyboard()->keyToScanCode(ke->key); bool isDown = ke->keyType == QEvent::KeyPress; #if QT_CONFIG(xkbcommon) - QString text; - Qt::KeyboardModifiers modifiers = QWaylandXkb::modifiers(keyb->xkbState()); + xkb_state *xkbState = keyb->xkbState(); - const xkb_keysym_t sym = xkb_state_key_get_one_sym(keyb->xkbState(), code); - int qtkey; - std::tie(qtkey, text) = QWaylandXkb::keysymToQtKey(sym, modifiers); + const xkb_keysym_t sym = xkb_state_key_get_one_sym(xkbState, code); + Qt::KeyboardModifiers modifiers = QXkbCommon::modifiers(xkbState, sym); + int qtkey = QXkbCommon::keysymToQtKey(sym, modifiers, xkbState, code); + QString text = QXkbCommon::lookupString(xkbState, code); ke->key = qtkey; ke->modifiers = modifiers; @@ -160,14 +145,29 @@ public: QWaylandCompositorPrivate::QWaylandCompositorPrivate(QWaylandCompositor *compositor) { + // Create XDG_RUNTIME_DIR, if it does not already exist + QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + if (QGuiApplication::platformNativeInterface()) display = static_cast<wl_display*>(QGuiApplication::platformNativeInterface()->nativeResourceForIntegration("server_wl_display")); - if (!display) + + if (!display) { display = wl_display_create(); + ownsDisplay = true; + } + eventHandler.reset(new QtWayland::WindowSystemEventHandler(compositor)); timer.start(); QWindowSystemInterfacePrivate::installWindowSystemEventHandler(eventHandler.data()); + +#if QT_CONFIG(xkbcommon) + mXkbContext.reset(xkb_context_new(XKB_CONTEXT_NO_FLAGS)); + if (!mXkbContext) { + qWarning("Failed to create a XKB context: keymap will not be supported"); + return; + } +#endif } void QWaylandCompositorPrivate::init() @@ -179,8 +179,10 @@ void QWaylandCompositorPrivate::init() const int socketArg = arguments.indexOf(QLatin1String("--wayland-socket-name")); if (socketArg != -1 && socketArg + 1 < arguments.size()) socket_name = arguments.at(socketArg + 1).toLocal8Bit(); + if (socket_name.isEmpty()) + socket_name = qgetenv("WAYLAND_DISPLAY"); } - wl_compositor::init(display, 3); + wl_compositor::init(display, 4); wl_subcompositor::init(display, 1); #if QT_CONFIG(wayland_datadevice) @@ -189,41 +191,44 @@ void QWaylandCompositorPrivate::init() buffer_manager = new QtWayland::BufferManager(q); wl_display_init_shm(display); - QVector<wl_shm_format> formats = QWaylandSharedMemoryFormatHelper::supportedWaylandFormats(); - foreach (wl_shm_format format, formats) - wl_display_add_shm_format(display, format); + + for (QWaylandCompositor::ShmFormat format : shmFormats) + wl_display_add_shm_format(display, wl_shm_format(format)); if (!socket_name.isEmpty()) { if (wl_display_add_socket(display, socket_name.constData())) - qFatal("Fatal: Failed to open server socket\n"); + qFatal("Fatal: Failed to open server socket: \"%s\". XDG_RUNTIME_DIR is: \"%s\"\n", socket_name.constData(), getenv("XDG_RUNTIME_DIR")); } else { const char *autoSocketName = wl_display_add_socket_auto(display); if (!autoSocketName) - qFatal("Fatal: Failed to open server socket\n"); + qFatal("Fatal: Failed to open default server socket. XDG_RUNTIME_DIR is: \"%s\"\n", getenv("XDG_RUNTIME_DIR")); socket_name = autoSocketName; emit q->socketNameChanged(socket_name); } -#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10) connectToExternalSockets(); -#endif loop = wl_display_get_event_loop(display); int fd = wl_event_loop_get_fd(loop); QSocketNotifier *sockNot = new QSocketNotifier(fd, QSocketNotifier::Read, q); - QObject::connect(sockNot, SIGNAL(activated(int)), q, SLOT(processWaylandEvents())); + QObject::connect(sockNot, SIGNAL(activated(QSocketDescriptor)), q, SLOT(processWaylandEvents())); QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher; QObject::connect(dispatcher, SIGNAL(aboutToBlock()), q, SLOT(processWaylandEvents())); + QObject::connect(static_cast<QGuiApplication *>(QGuiApplication::instance()), + &QGuiApplication::applicationStateChanged, + q, + &QWaylandCompositor::applicationStateChanged); + initializeHardwareIntegration(); initializeSeats(); initialized = true; - Q_FOREACH (QPointer<QObject> object, polish_objects) { + for (const QPointer<QObject> &object : std::exchange(polish_objects, {})) { if (object) { QEvent polishEvent(QEvent::Polish); QCoreApplication::sendEvent(object.data(), &polishEvent); @@ -235,20 +240,22 @@ void QWaylandCompositorPrivate::init() QWaylandCompositorPrivate::~QWaylandCompositorPrivate() { - qDeleteAll(clients); + // Take copies, since the lists will get modified as elements are deleted + const auto clientsToDelete = clients; + qDeleteAll(clientsToDelete); - qDeleteAll(outputs); + const auto outputsToDelete = outputs; + qDeleteAll(outputsToDelete); #if QT_CONFIG(wayland_datadevice) delete data_device_manager; #endif -#if QT_CONFIG(opengl) // Some client buffer integrations need to clean up before the destroying the wl_display - client_buffer_integration.reset(); -#endif + qDeleteAll(client_buffer_integrations); - wl_display_destroy(display); + if (ownsDisplay) + wl_display_destroy(display); } void QWaylandCompositorPrivate::preInit() @@ -290,21 +297,19 @@ void QWaylandCompositorPrivate::addPolishObject(QObject *object) if (initialized) { QCoreApplication::postEvent(object, new QEvent(QEvent::Polish)); } else { - polish_objects.append(object); + polish_objects.push_back(object); } } -#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10) void QWaylandCompositorPrivate::connectToExternalSockets() { // Clear out any backlog of user-supplied external socket descriptors - for (int fd : qAsConst(externally_added_socket_fds)) { + for (int fd : std::as_const(externally_added_socket_fds)) { if (wl_display_add_socket_fd(display, fd) != 0) qWarning() << "Failed to integrate user-supplied socket fd into the Wayland event loop"; } externally_added_socket_fds.clear(); } -#endif void QWaylandCompositorPrivate::compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) { @@ -353,9 +358,28 @@ QWaylandSurface *QWaylandCompositorPrivate::createDefaultSurface() return new QWaylandSurface(); } +class SharedMemoryClientBufferIntegration : public QtWayland::ClientBufferIntegration +{ +public: + void initializeHardware(wl_display *display) override; + QtWayland::ClientBuffer *createBufferFor(wl_resource *buffer) override; +}; + +void SharedMemoryClientBufferIntegration::initializeHardware(wl_display *) +{ +} + +QtWayland::ClientBuffer *SharedMemoryClientBufferIntegration::createBufferFor(wl_resource *buffer) +{ + if (wl_shm_buffer_get(buffer)) + return new QtWayland::SharedMemoryBuffer(buffer); + return nullptr; +} void QWaylandCompositorPrivate::initializeHardwareIntegration() { + client_buffer_integrations.prepend(new SharedMemoryClientBufferIntegration); // TODO: clean up the opengl dependency + #if QT_CONFIG(opengl) Q_Q(QWaylandCompositor); if (use_hw_integration_extension) @@ -364,16 +388,14 @@ void QWaylandCompositorPrivate::initializeHardwareIntegration() loadClientBufferIntegration(); loadServerBufferIntegration(); - if (client_buffer_integration) - client_buffer_integration->initializeHardware(display); - if (server_buffer_integration) - server_buffer_integration->initializeHardware(q); + for (auto *integration : std::as_const(client_buffer_integrations)) + integration->initializeHardware(display); #endif } void QWaylandCompositorPrivate::initializeSeats() { - for (QWaylandSeat *seat : qAsConst(seats)) + for (QWaylandSeat *seat : std::as_const(seats)) seat->initialize(); } @@ -382,33 +404,47 @@ void QWaylandCompositorPrivate::loadClientBufferIntegration() #if QT_CONFIG(opengl) Q_Q(QWaylandCompositor); QStringList keys = QtWayland::ClientBufferIntegrationFactory::keys(); - QString targetKey; + QStringList targetKeys; QByteArray clientBufferIntegration = qgetenv("QT_WAYLAND_HARDWARE_INTEGRATION"); if (clientBufferIntegration.isEmpty()) clientBufferIntegration = qgetenv("QT_WAYLAND_CLIENT_BUFFER_INTEGRATION"); - if (keys.contains(QString::fromLocal8Bit(clientBufferIntegration.constData()))) { - targetKey = QString::fromLocal8Bit(clientBufferIntegration.constData()); - } else if (keys.contains(QString::fromLatin1("wayland-egl"))) { - targetKey = QString::fromLatin1("wayland-egl"); - } else if (!keys.isEmpty()) { - targetKey = keys.first(); + + for (auto b : clientBufferIntegration.split(';')) { + QString s = QString::fromLocal8Bit(b); + if (keys.contains(s)) + targetKeys.append(s); } - if (!targetKey.isEmpty()) { - client_buffer_integration.reset(QtWayland::ClientBufferIntegrationFactory::create(targetKey, QStringList())); - if (client_buffer_integration) { - client_buffer_integration->setCompositor(q); - if (hw_integration) - hw_integration->setClientBufferIntegration(targetKey); + if (targetKeys.isEmpty()) { + if (keys.contains(QString::fromLatin1("wayland-egl"))) { + targetKeys.append(QString::fromLatin1("wayland-egl")); + } else if (!keys.isEmpty()) { + targetKeys.append(keys.first()); + } + } + + QString hwIntegrationName; + + for (auto targetKey : std::as_const(targetKeys)) { + auto *integration = QtWayland::ClientBufferIntegrationFactory::create(targetKey, QStringList()); + if (integration) { + integration->setCompositor(q); + client_buffer_integrations.append(integration); + if (hwIntegrationName.isEmpty()) + hwIntegrationName = targetKey; } } - //BUG: if there is no client buffer integration, bad things will happen when opengl is used + + if (hw_integration && !hwIntegrationName.isEmpty()) + hw_integration->setClientBufferIntegrationName(hwIntegrationName); + #endif } void QWaylandCompositorPrivate::loadServerBufferIntegration() { #if QT_CONFIG(opengl) + Q_Q(QWaylandCompositor); QStringList keys = QtWayland::ServerBufferIntegrationFactory::keys(); QString targetKey; QByteArray serverBufferIntegration = qgetenv("QT_WAYLAND_SERVER_BUFFER_INTEGRATION"); @@ -417,14 +453,41 @@ void QWaylandCompositorPrivate::loadServerBufferIntegration() } if (!targetKey.isEmpty()) { server_buffer_integration.reset(QtWayland::ServerBufferIntegrationFactory::create(targetKey, QStringList())); - if (hw_integration) - hw_integration->setServerBufferIntegration(targetKey); + if (server_buffer_integration) { + qCDebug(qLcWaylandCompositorHardwareIntegration) + << "Loaded server buffer integration:" << targetKey; + if (!server_buffer_integration->initializeHardware(q)) { + qCWarning(qLcWaylandCompositorHardwareIntegration) + << "Failed to initialize hardware for server buffer integration:" << targetKey; + server_buffer_integration.reset(); + } + } else { + qCWarning(qLcWaylandCompositorHardwareIntegration) + << "Failed to load server buffer integration:" << targetKey; + } } + + if (server_buffer_integration && hw_integration) + hw_integration->setServerBufferIntegrationName(targetKey); #endif } +QWaylandSeat *QWaylandCompositorPrivate::seatFor(QInputEvent *inputEvent) +{ + QWaylandSeat *dev = nullptr; + for (int i = 0; i < seats.size(); i++) { + QWaylandSeat *candidate = seats.at(i); + if (candidate->isOwner(inputEvent)) { + dev = candidate; + break; + } + } + return dev; +} + /*! \qmltype WaylandCompositor + \instantiates QWaylandCompositor \inqmlmodule QtWayland.Compositor \since 5.8 \brief Manages the Wayland display server. @@ -456,35 +519,37 @@ void QWaylandCompositorPrivate::loadServerBufferIntegration() */ /*! - \qmlsignal void QtWaylandCompositor::WaylandCompositor::surfaceRequested(WaylandClient client, int id, int version) + \qmlsignal void QtWayland.Compositor::WaylandCompositor::surfaceRequested(WaylandClient client, int id, int version) - This signal is emitted when a client has created a surface. - The slot connecting to this signal may create and initialize - a WaylandSurface instance in the scope of the slot. - Otherwise a default surface is created. + This signal is emitted when a \a client has created a surface with id \a id. + The interface \a version is also available. + + The slot connecting to this signal may create and initialize a WaylandSurface + instance in the scope of the slot. Otherwise a default surface is created. */ /*! \fn void QWaylandCompositor::surfaceRequested(QWaylandClient *client, uint id, int version) - This signal is emitted when a client has created a surface. - The slot connecting to this signal may create and initialize - a QWaylandSurface instance in the scope of the slot. - Otherwise a default surface is created. + This signal is emitted when a \a client has created a surface with id \a id. + The interface \a version is also available. + + The slot connecting to this signal may create and initialize a QWaylandSurface + instance in the scope of the slot. Otherwise a default surface is created. Connections to this signal must be of Qt::DirectConnection connection type. */ /*! - \qmlsignal void QtWaylandCompositor::WaylandCompositor::surfaceCreated(QWaylandSurface *surface) + \qmlsignal void QtWayland.Compositor::WaylandCompositor::surfaceCreated(WaylandSurface surface) - This signal is emitted when a new WaylandSurface instance has been created. + This signal is emitted when a new WaylandSurface instance \a surface has been created. */ /*! \fn void QWaylandCompositor::surfaceCreated(QWaylandSurface *surface) - This signal is emitted when a new QWaylandSurface instance has been created. + This signal is emitted when a new QWaylandSurface instance \a surface has been created. */ /*! @@ -523,7 +588,7 @@ void QWaylandCompositor::create() } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandCompositor::created + * \qmlproperty bool QtWayland.Compositor::WaylandCompositor::created * * This property is true if WaylandCompositor has been initialized, * otherwise it's false. @@ -542,7 +607,7 @@ bool QWaylandCompositor::isCreated() const } /*! - * \qmlproperty string QtWaylandCompositor::WaylandCompositor::socketName + * \qmlproperty string QtWayland.Compositor::WaylandCompositor::socketName * * This property holds the socket name used by WaylandCompositor to communicate with * clients. It must be set before the component is completed. @@ -585,10 +650,10 @@ QByteArray QWaylandCompositor::socketName() const } /*! - * \qmlmethod QtWaylandCompositor::WaylandCompositor::addSocketDescriptor(fd) + * \qmlmethod QtWayland.Compositor::WaylandCompositor::addSocketDescriptor(fd) * \since 5.12 * - * Listen for client connections on a file descriptor referring to a + * Listen for client connections on a file descriptor, \a fd, referring to a * server socket already bound and listening. * * Does not take ownership of the file descriptor; it must be closed @@ -600,7 +665,7 @@ QByteArray QWaylandCompositor::socketName() const */ /*! - * Listen for client connections on a file descriptor referring to a + * Listen for client connections on a file descriptor, \a fd, referring to a * server socket already bound and listening. * * Does not take ownership of the file descriptor; it must be closed @@ -614,15 +679,10 @@ QByteArray QWaylandCompositor::socketName() const */ void QWaylandCompositor::addSocketDescriptor(int fd) { -#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10) Q_D(QWaylandCompositor); d->externally_added_socket_fds.append(fd); if (isCreated()) d->connectToExternalSockets(); -#else - Q_UNUSED(fd); - qWarning() << "QWaylandCompositor::addSocketDescriptor() does nothing on libwayland versions prior to 1.10.0"; -#endif } /*! @@ -653,7 +713,7 @@ QList<QWaylandClient *>QWaylandCompositor::clients() const } /*! - * \qmlmethod QtWaylandCompositor::WaylandCompositor::destroyClientForSurface(surface) + * \qmlmethod QtWayland.Compositor::WaylandCompositor::destroyClientForSurface(surface) * * Destroys the client for the WaylandSurface \a surface. */ @@ -667,7 +727,7 @@ void QWaylandCompositor::destroyClientForSurface(QWaylandSurface *surface) } /*! - * \qmlmethod QtWaylandCompositor::WaylandCompositor::destroyClient(client) + * \qmlmethod QtWayland.Compositor::WaylandCompositor::destroyClient(client) * * Destroys the given WaylandClient \a client. */ @@ -694,7 +754,7 @@ QList<QWaylandSurface *> QWaylandCompositor::surfacesForClient(QWaylandClient* c { Q_D(const QWaylandCompositor); QList<QWaylandSurface *> surfs; - foreach (QWaylandSurface *surface, d->all_surfaces) { + for (QWaylandSurface *surface : d->all_surfaces) { if (surface->client() == client) surfs.append(surface); } @@ -716,7 +776,7 @@ QList<QWaylandSurface *> QWaylandCompositor::surfaces() const QWaylandOutput *QWaylandCompositor::outputFor(QWindow *window) const { Q_D(const QWaylandCompositor); - foreach (QWaylandOutput *output, d->outputs) { + for (QWaylandOutput *output : d->outputs) { if (output->window() == window) return output; } @@ -725,7 +785,7 @@ QWaylandOutput *QWaylandCompositor::outputFor(QWindow *window) const } /*! - * \qmlproperty WaylandOutput QtWaylandCompositor::WaylandCompositor::defaultOutput + * \qmlproperty WaylandOutput QtWayland.Compositor::WaylandCompositor::defaultOutput * * This property contains the first in the list of outputs added to the * WaylandCompositor, or null if no outputs have been added. @@ -826,7 +886,7 @@ QWaylandTouch *QWaylandCompositor::createTouchDevice(QWaylandSeat *seat) } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandCompositor::retainedSelection + * \qmlproperty bool QtWayland.Compositor::WaylandCompositor::retainedSelection * * This property holds whether retained selection is enabled. */ @@ -872,7 +932,7 @@ void QWaylandCompositor::overrideSelection(const QMimeData *data) } /*! - * \qmlproperty WaylandSeat QtWaylandCompositor::WaylandCompositor::defaultSeat + * \qmlproperty WaylandSeat QtWayland.Compositor::WaylandCompositor::defaultSeat * * This property contains the default seat for this * WaylandCompositor. @@ -893,27 +953,17 @@ QWaylandSeat *QWaylandCompositor::defaultSeat() const } /*! - * \internal - * - * Currently, Qt only supports a single seat, so this exists for - * future proofing the APIs. + * Select the seat for a given input event \a inputEvent. + * Currently, Qt only supports a single seat. */ QWaylandSeat *QWaylandCompositor::seatFor(QInputEvent *inputEvent) { Q_D(QWaylandCompositor); - QWaylandSeat *dev = nullptr; - for (int i = 0; i < d->seats.size(); i++) { - QWaylandSeat *candidate = d->seats.at(i); - if (candidate->isOwner(inputEvent)) { - dev = candidate; - break; - } - } - return dev; + return d->seatFor(inputEvent); } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandCompositor::useHardwareIntegrationExtension + * \qmlproperty bool QtWayland.Compositor::WaylandCompositor::useHardwareIntegrationExtension * * This property holds whether the hardware integration extension should be enabled for * this WaylandCompositor. @@ -998,4 +1048,67 @@ void QWaylandCompositor::grabSurface(QWaylandSurfaceGrabber *grabber, const QWay } } +/*! + * \qmlproperty list<enum> QtWayland.Compositor::WaylandCompositor::additionalShmFormats + * + * This property holds the list of additional wl_shm formats advertised as supported by the + * compositor. + * + * By default, only the required ShmFormat_ARGB8888 and ShmFormat_XRGB8888 are listed and this + * list will empty. Additional formats may require conversion internally and can thus affect + * performance. + * + * This property must be set before the compositor component is completed. Subsequent changes + * will have no effect. + * + * \since 6.0 + */ + +/*! + * \property QWaylandCompositor::additionalShmFormats + * + * This property holds the list of additional wl_shm formats advertised as supported by the + * compositor. + * + * By default, only the required ShmFormat_ARGB8888 and ShmFormat_XRGB8888 are listed and this + * list will empty. + * + * This property must be set before the compositor is \l{create()}{created}. Subsequent changes + * will have no effect. + * + * \since 6.0 + */ +void QWaylandCompositor::setAdditionalShmFormats(const QVector<ShmFormat> &additionalShmFormats) +{ + Q_D(QWaylandCompositor); + if (d->initialized) + qCWarning(qLcWaylandCompositorHardwareIntegration) << "Setting QWaylandCompositor::additionalShmFormats after initialization has no effect"; + + d->shmFormats = additionalShmFormats; + emit additionalShmFormatsChanged(); +} + +QVector<QWaylandCompositor::ShmFormat> QWaylandCompositor::additionalShmFormats() const +{ + Q_D(const QWaylandCompositor); + return d->shmFormats; +} + +void QWaylandCompositor::applicationStateChanged(Qt::ApplicationState state) +{ +#if QT_CONFIG(xkbcommon) + if (state == Qt::ApplicationInactive) { + auto *seat = defaultSeat(); + if (seat != nullptr) { + QWaylandKeyboardPrivate *keyb = QWaylandKeyboardPrivate::get(seat->keyboard()); + keyb->resetKeyboardState(); + } + } +#else + Q_UNUSED(state); +#endif +} + QT_END_NAMESPACE + +#include "moc_qwaylandcompositor.cpp" diff --git a/src/compositor/compositor_api/qwaylandcompositor.h b/src/compositor/compositor_api/qwaylandcompositor.h index c343d6f84..58b053d4e 100644 --- a/src/compositor/compositor_api/qwaylandcompositor.h +++ b/src/compositor/compositor_api/qwaylandcompositor.h @@ -1,53 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDCOMPOSITOR_H #define QWAYLANDCOMPOSITOR_H #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> #include <QtWaylandCompositor/qwaylandcompositorextension.h> #include <QtWaylandCompositor/QWaylandOutput> -#include <QObject> -#include <QImage> -#include <QRect> -#include <QLoggingCategory> +#include <QtCore/QObject> +#include <QtGui/QImage> +#include <QtCore/QRect> +#include <QtCore/QLoggingCategory> struct wl_display; @@ -62,7 +27,6 @@ class QWaylandCompositorPrivate; class QWaylandClient; class QWaylandSurface; class QWaylandSeat; -class QWaylandGlobalInterface; class QWaylandView; class QWaylandPointer; class QWaylandKeyboard; @@ -70,11 +34,12 @@ class QWaylandTouch; class QWaylandSurfaceGrabber; class QWaylandBufferRef; -Q_WAYLAND_COMPOSITOR_EXPORT Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositor) -Q_WAYLAND_COMPOSITOR_EXPORT Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositorHardwareIntegration) -Q_DECLARE_LOGGING_CATEGORY(qLcWaylandCompositorInputMethods) +Q_WAYLANDCOMPOSITOR_EXPORT const QLoggingCategory &qLcWaylandCompositor(); +Q_WAYLANDCOMPOSITOR_EXPORT const QLoggingCategory &qLcWaylandCompositorHardwareIntegration(); +const QLoggingCategory &qLcWaylandCompositorInputMethods(); +const QLoggingCategory &qLcWaylandCompositorTextInput(); -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandCompositor : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositor : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandCompositor) @@ -84,8 +49,32 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandCompositor : public QWaylandObject Q_PROPERTY(QWaylandOutput *defaultOutput READ defaultOutput WRITE setDefaultOutput NOTIFY defaultOutputChanged) Q_PROPERTY(bool useHardwareIntegrationExtension READ useHardwareIntegrationExtension WRITE setUseHardwareIntegrationExtension NOTIFY useHardwareIntegrationExtensionChanged) Q_PROPERTY(QWaylandSeat *defaultSeat READ defaultSeat NOTIFY defaultSeatChanged) - + Q_PROPERTY(QVector<ShmFormat> additionalShmFormats READ additionalShmFormats WRITE setAdditionalShmFormats NOTIFY additionalShmFormatsChanged REVISION(6, 0)) + Q_MOC_INCLUDE("qwaylandseat.h") + QML_NAMED_ELEMENT(WaylandCompositorBase) + QML_UNCREATABLE("Cannot create instance of WaylandCompositorBase, use WaylandCompositor instead") + QML_ADDED_IN_VERSION(1, 0) public: + // Duplicates subset of supported values wl_shm_format enum + enum ShmFormat { + ShmFormat_ARGB8888 = 0, + ShmFormat_XRGB8888 = 1, + ShmFormat_C8 = 0x20203843, + ShmFormat_XRGB4444 = 0x32315258, + ShmFormat_ARGB4444 = 0x32315241, + ShmFormat_XRGB1555 = 0x35315258, + ShmFormat_RGB565 = 0x36314752, + ShmFormat_RGB888 = 0x34324752, + ShmFormat_XBGR8888 = 0x34324258, + ShmFormat_ABGR8888 = 0x34324241, + ShmFormat_BGR888 = 0x34324742, + ShmFormat_XRGB2101010 = 0x30335258, + ShmFormat_XBGR2101010 = 0x30334258, + ShmFormat_ARGB2101010 = 0x30335241, + ShmFormat_ABGR2101010 = 0x30334241 + }; + Q_ENUM(ShmFormat) + QWaylandCompositor(QObject *parent = nullptr); ~QWaylandCompositor() override; @@ -126,11 +115,17 @@ public: bool useHardwareIntegrationExtension() const; void setUseHardwareIntegrationExtension(bool use); + QVector<ShmFormat> additionalShmFormats() const; + void setAdditionalShmFormats(const QVector<ShmFormat> &additionalShmFormats); + virtual void grabSurface(QWaylandSurfaceGrabber *grabber, const QWaylandBufferRef &buffer); public Q_SLOTS: void processWaylandEvents(); +private Q_SLOTS: + void applicationStateChanged(Qt::ApplicationState state); + Q_SIGNALS: void createdChanged(); void socketNameChanged(const QByteArray &socketName); @@ -149,6 +144,8 @@ Q_SIGNALS: void outputAdded(QWaylandOutput *output); void outputRemoved(QWaylandOutput *output); + void additionalShmFormatsChanged(); + protected: virtual void retainedSelectionReceived(QMimeData *mimeData); virtual QWaylandSeat *createSeat(); diff --git a/src/compositor/compositor_api/qwaylandcompositor_p.h b/src/compositor/compositor_api/qwaylandcompositor_p.h index cdf4be6b4..a8da8b8c4 100644 --- a/src/compositor/compositor_api/qwaylandcompositor_p.h +++ b/src/compositor/compositor_api/qwaylandcompositor_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDCOMPOSITOR_P_H #define QWAYLANDCOMPOSITOR_P_H @@ -60,6 +24,14 @@ #include <QtWaylandCompositor/private/qwayland-server-wayland.h> +#include <QtCore/qpointer.h> + +#include <vector> + +#if QT_CONFIG(xkbcommon) +#include <QtGui/private/qxkbcommon_p.h> +#endif + QT_BEGIN_NAMESPACE namespace QtWayland { @@ -73,7 +45,7 @@ namespace QtWayland { class QWindowSystemEventHandler; class QWaylandSurface; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandCompositorPrivate : public QObjectPrivate, public QtWaylandServer::wl_compositor, public QtWaylandServer::wl_subcompositor +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandCompositorPrivate : public QObjectPrivate, public QtWaylandServer::wl_compositor, public QtWaylandServer::wl_subcompositor { public: static QWaylandCompositorPrivate *get(QWaylandCompositor *compositor) { return compositor->d_func(); } @@ -81,6 +53,10 @@ public: QWaylandCompositorPrivate(QWaylandCompositor *compositor); ~QWaylandCompositorPrivate() override; +#if QT_CONFIG(xkbcommon) + struct xkb_context *xkbContext() const { return mXkbContext.get(); } +#endif + void preInit(); void init(); @@ -89,7 +65,7 @@ public: QWaylandOutput *defaultOutput() const { return outputs.size() ? outputs.first() : nullptr; } - inline QtWayland::ClientBufferIntegration *clientBufferIntegration() const; + inline const QList<QtWayland::ClientBufferIntegration *> clientBufferIntegrations() const; inline QtWayland::ServerBufferIntegration *serverBufferIntegration() const; #if QT_CONFIG(wayland_datadevice) @@ -113,9 +89,9 @@ public: inline void addOutput(QWaylandOutput *output); inline void removeOutput(QWaylandOutput *output); -#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10) void connectToExternalSockets(); -#endif + + virtual QWaylandSeat *seatFor(QInputEvent *inputEvent); protected: void compositor_create_surface(wl_compositor::Resource *resource, uint32_t id) override; @@ -133,10 +109,10 @@ protected: void loadServerBufferIntegration(); QByteArray socket_name; -#if WAYLAND_VERSION_MAJOR >= 1 && (WAYLAND_VERSION_MAJOR != 1 || WAYLAND_VERSION_MINOR >= 10) QList<int> externally_added_socket_fds; -#endif struct wl_display *display = nullptr; + bool ownsDisplay = false; + QVector<QWaylandCompositor::ShmFormat> shmFormats; QList<QWaylandSeat *> seats; QList<QWaylandOutput *> outputs; @@ -157,28 +133,28 @@ protected: #if QT_CONFIG(opengl) bool use_hw_integration_extension = true; QScopedPointer<QtWayland::HardwareIntegration> hw_integration; - QScopedPointer<QtWayland::ClientBufferIntegration> client_buffer_integration; QScopedPointer<QtWayland::ServerBufferIntegration> server_buffer_integration; #endif + QList<QtWayland::ClientBufferIntegration*> client_buffer_integrations; QScopedPointer<QWindowSystemEventHandler> eventHandler; bool retainSelection = false; bool preInitialized = false; bool initialized = false; - QList<QPointer<QObject> > polish_objects; + std::vector<QPointer<QObject> > polish_objects; + +#if QT_CONFIG(xkbcommon) + QXkbCommon::ScopedXKBContext mXkbContext; +#endif Q_DECLARE_PUBLIC(QWaylandCompositor) Q_DISABLE_COPY(QWaylandCompositorPrivate) }; -QtWayland::ClientBufferIntegration * QWaylandCompositorPrivate::clientBufferIntegration() const +const QList<QtWayland::ClientBufferIntegration *> QWaylandCompositorPrivate::clientBufferIntegrations() const { -#if QT_CONFIG(opengl) - return client_buffer_integration.data(); -#else - return 0; -#endif + return client_buffer_integrations; } QtWayland::ServerBufferIntegration * QWaylandCompositorPrivate::serverBufferIntegration() const diff --git a/src/compositor/compositor_api/qwaylandcompositorquickextensions.cpp b/src/compositor/compositor_api/qwaylandcompositorquickextensions.cpp new file mode 100644 index 000000000..43fb3b2f9 --- /dev/null +++ b/src/compositor/compositor_api/qwaylandcompositorquickextensions.cpp @@ -0,0 +1,10 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "qwaylandcompositorquickextensions_p.h" + +QT_BEGIN_NAMESPACE + +QT_END_NAMESPACE + +#include "moc_qwaylandcompositorquickextensions_p.cpp" diff --git a/src/compositor/compositor_api/qwaylandcompositorquickextensions_p.h b/src/compositor/compositor_api/qwaylandcompositorquickextensions_p.h new file mode 100644 index 000000000..7e59a5d6e --- /dev/null +++ b/src/compositor/compositor_api/qwaylandcompositorquickextensions_p.h @@ -0,0 +1,94 @@ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef QWAYLANDCOMPOSITORQUICKEXTENSIONS_P_H +#define QWAYLANDCOMPOSITORQUICKEXTENSIONS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQml/qqml.h> +#include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qwaylandquickextension.h> + +#include <QtWaylandCompositor/qwaylandcompositor.h> +#include <QtWaylandCompositor/qwaylandquickcompositor.h> +#include <QtWaylandCompositor/qwaylandqtwindowmanager.h> +#include <QtWaylandCompositor/qwaylandtextinputmanager.h> +#include <QtCore/private/qglobal_p.h> +#include <QtWaylandCompositor/qwaylandtextinputmanagerv3.h> +#include <QtWaylandCompositor/qwaylandqttextinputmethodmanager.h> +#include <QtWaylandCompositor/qwaylandidleinhibitv1.h> + +QT_BEGIN_NAMESPACE + +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickCompositorQuickExtensionContainer : public QWaylandQuickCompositor +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty<QWaylandCompositorExtension> extensions READ extensions) + Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) + Q_CLASSINFO("DefaultProperty", "data") + QML_NAMED_ELEMENT(WaylandCompositor) + QML_ADDED_IN_VERSION(1, 0) +public: + QQmlListProperty<QObject> data() + { + return QQmlListProperty<QObject>(this, &m_objects); + } + + QQmlListProperty<QWaylandCompositorExtension> extensions() + { + return QQmlListProperty<QWaylandCompositorExtension>(this, this, + &append_extension, + &countFunction, + &atFunction, + &clearFunction); + } + + static qsizetype countFunction(QQmlListProperty<QWaylandCompositorExtension> *list) + { + return static_cast<QWaylandQuickCompositorQuickExtensionContainer *>(list->data)->extension_vector.size(); + } + + static QWaylandCompositorExtension *atFunction(QQmlListProperty<QWaylandCompositorExtension> *list, qsizetype index) + { + return static_cast<QWaylandQuickCompositorQuickExtensionContainer *>(list->data)->extension_vector.at(index); + } + + static void append_extension(QQmlListProperty<QWaylandCompositorExtension> *list, QWaylandCompositorExtension *extension) + { + QWaylandQuickCompositorQuickExtensionContainer *quickExtObj = static_cast<QWaylandQuickCompositorQuickExtensionContainer *>(list->data); + extension->setExtensionContainer(quickExtObj); + } + + static void clearFunction(QQmlListProperty<QWaylandCompositorExtension> *list) + { + static_cast<QWaylandQuickCompositorQuickExtensionContainer *>(list->data)->extension_vector.clear(); + } + +private: + QList<QObject *> m_objects; +}; + + +// Note: These have to be in a header with a Q_OBJECT macro, otherwise we won't run moc on it +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(QWaylandQtWindowManager, QtWindowManager, 1, 0) +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(QWaylandIdleInhibitManagerV1, + IdleInhibitManagerV1, 1, 0) +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(QWaylandTextInputManager, TextInputManager, 1, 0) +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(QWaylandTextInputManagerV3, TextInputManagerV3, + 1, 0) +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_NAMED_ELEMENT(QWaylandQtTextInputMethodManager, + QtTextInputMethodManager, 1, 0) + +QT_END_NAMESPACE + +#endif // QWAYLANDCOMPOSITORQUICKEXTENSIONS_P_H diff --git a/src/compositor/compositor_api/qwaylanddestroylistener.cpp b/src/compositor/compositor_api/qwaylanddestroylistener.cpp index 982666ab8..26c2ff69e 100644 --- a/src/compositor/compositor_api/qwaylanddestroylistener.cpp +++ b/src/compositor/compositor_api/qwaylanddestroylistener.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylanddestroylistener.h" #include "qwaylanddestroylistener_p.h" @@ -73,3 +37,5 @@ void QWaylandDestroyListenerPrivate::handler(wl_listener *listener, void *data) } QT_END_NAMESPACE + +#include "moc_qwaylanddestroylistener.cpp" diff --git a/src/compositor/compositor_api/qwaylanddestroylistener.h b/src/compositor/compositor_api/qwaylanddestroylistener.h index 5f87ccd17..e1307b2ca 100644 --- a/src/compositor/compositor_api/qwaylanddestroylistener.h +++ b/src/compositor/compositor_api/qwaylanddestroylistener.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDDESTROYLISTENER_H #define QWAYLANDDESTROYLISTENER_H @@ -50,7 +14,7 @@ QT_BEGIN_NAMESPACE class QWaylandDestroyListenerPrivate; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandDestroyListener : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandDestroyListener : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandDestroyListener) diff --git a/src/compositor/compositor_api/qwaylanddestroylistener_p.h b/src/compositor/compositor_api/qwaylanddestroylistener_p.h index 7c6001c36..baefc8171 100644 --- a/src/compositor/compositor_api/qwaylanddestroylistener_p.h +++ b/src/compositor/compositor_api/qwaylanddestroylistener_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QTWAYLAND_QWLLISTENER_H #define QTWAYLAND_QWLLISTENER_H @@ -55,7 +19,7 @@ #include <QtCore/private/qobject_p.h> -#include <wayland-server.h> +#include <wayland-server-core.h> QT_BEGIN_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylanddrag.cpp b/src/compositor/compositor_api/qwaylanddrag.cpp index d79e4fa30..2cd391218 100644 --- a/src/compositor/compositor_api/qwaylanddrag.cpp +++ b/src/compositor/compositor_api/qwaylanddrag.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylanddrag.h" @@ -140,3 +104,5 @@ void QWaylandDrag::cancelDrag() } QT_END_NAMESPACE + +#include "moc_qwaylanddrag.cpp" diff --git a/src/compositor/compositor_api/qwaylanddrag.h b/src/compositor/compositor_api/qwaylanddrag.h index 5efe7b25c..599b79c98 100644 --- a/src/compositor/compositor_api/qwaylanddrag.h +++ b/src/compositor/compositor_api/qwaylanddrag.h @@ -1,46 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDDRAG_H #define QWAYLANDDRAG_H #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> #include <QtCore/QObject> #include <QtCore/QPointF> @@ -53,14 +18,18 @@ class QWaylandDragPrivate; class QWaylandSurface; class QWaylandSeat; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandDrag : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandDrag : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandDrag) Q_PROPERTY(QWaylandSurface *icon READ icon NOTIFY iconChanged) Q_PROPERTY(bool visible READ visible NOTIFY iconChanged) + Q_MOC_INCLUDE("qwaylandsurface.h") + QML_NAMED_ELEMENT(WaylandDrag) + QML_ADDED_IN_VERSION(1, 0) + QML_UNCREATABLE("") public: explicit QWaylandDrag(QWaylandSeat *seat); diff --git a/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp b/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp index a443502fa..e9a962d28 100644 --- a/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp +++ b/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandinputmethodcontrol.h" #include "qwaylandinputmethodcontrol_p.h" @@ -45,6 +9,8 @@ #include "qwaylandsurface.h" #include "qwaylandview.h" #include "qwaylandtextinput.h" +#include "qwaylandtextinputv3.h" +#include "qwaylandqttextinputmethod.h" #include <QtGui/QInputMethodEvent> @@ -53,11 +19,21 @@ QWaylandInputMethodControl::QWaylandInputMethodControl(QWaylandSurface *surface) { connect(d_func()->compositor, &QWaylandCompositor::defaultSeatChanged, this, &QWaylandInputMethodControl::defaultSeatChanged); - QWaylandTextInput *textInput = d_func()->textInput(); - if (textInput) { - connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); - connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); - connect(textInput, &QWaylandTextInput::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); + + updateTextInput(); + + QWaylandTextInputV3 *textInputV3 = d_func()->textInputV3(); + if (textInputV3) { + connect(textInputV3, &QWaylandTextInputV3::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputV3, &QWaylandTextInputV3::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + connect(textInputV3, &QWaylandTextInputV3::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); + } + + QWaylandQtTextInputMethod *textInputMethod = d_func()->textInputMethod(); + if (textInputMethod) { + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); } } @@ -66,10 +42,16 @@ QVariant QWaylandInputMethodControl::inputMethodQuery(Qt::InputMethodQuery query Q_D(const QWaylandInputMethodControl); QWaylandTextInput *textInput = d->textInput(); - - if (textInput && textInput->focus() == d->surface) { + if (textInput != nullptr && textInput->focus() == d->surface) return textInput->inputMethodQuery(query, argument); - } + + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + if (textInputV3 != nullptr && textInputV3->focus() == d->surface) + return textInputV3->inputMethodQuery(query, argument); + + QWaylandQtTextInputMethod *textInputMethod = d_func()->textInputMethod(); + if (textInputMethod && textInputMethod->focusedSurface() == d->surface) + return textInputMethod->inputMethodQuery(query, argument); return QVariant(); } @@ -78,9 +60,12 @@ void QWaylandInputMethodControl::inputMethodEvent(QInputMethodEvent *event) { Q_D(QWaylandInputMethodControl); - QWaylandTextInput *textInput = d->textInput(); - if (textInput) { + if (QWaylandTextInput *textInput = d->textInput()) { textInput->sendInputMethodEvent(event); + } else if (QWaylandTextInputV3 *textInputV3 = d->textInputV3()) { + textInputV3->sendInputMethodEvent(event); + } else if (QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod()) { + textInputMethod->sendInputMethodEvent(event); } else { event->ignore(); } @@ -131,7 +116,22 @@ void QWaylandInputMethodControl::setSurface(QWaylandSurface *surface) d->surface = surface; QWaylandTextInput *textInput = d->textInput(); - setEnabled(textInput && textInput->isSurfaceEnabled(d->surface)); + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod(); + setEnabled((textInput && textInput->isSurfaceEnabled(d->surface)) + || (textInputV3 && textInputV3->isSurfaceEnabled(d->surface)) + || (textInputMethod && textInputMethod->isSurfaceEnabled(d->surface))); +} + +void QWaylandInputMethodControl::updateTextInput() +{ + QWaylandTextInput *textInput = d_func()->textInput(); + + if (textInput) { + connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled, Qt::UniqueConnection); + connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled, Qt::UniqueConnection); + connect(textInput, &QWaylandTextInput::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod, Qt::UniqueConnection); + } } void QWaylandInputMethodControl::defaultSeatChanged() @@ -139,14 +139,32 @@ void QWaylandInputMethodControl::defaultSeatChanged() Q_D(QWaylandInputMethodControl); disconnect(d->textInput(), nullptr, this, nullptr); + disconnect(d->textInputV3(), nullptr, this, nullptr); + disconnect(d->textInputMethod(), nullptr, this, nullptr); d->seat = d->compositor->defaultSeat(); QWaylandTextInput *textInput = d->textInput(); + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod(); + + if (textInput) { + connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } + + if (textInputV3) { + connect(textInputV3, &QWaylandTextInputV3::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputV3, &QWaylandTextInputV3::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } - connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); - connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + if (textInputMethod) { + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } - setEnabled(textInput && textInput->isSurfaceEnabled(d->surface)); + setEnabled((textInput && textInput->isSurfaceEnabled(d->surface)) + || (textInputV3 && textInputV3->isSurfaceEnabled(d->surface)) + || (textInputMethod && textInputMethod->isSurfaceEnabled(d->surface))); } QWaylandInputMethodControlPrivate::QWaylandInputMethodControlPrivate(QWaylandSurface *surface) @@ -156,7 +174,23 @@ QWaylandInputMethodControlPrivate::QWaylandInputMethodControlPrivate(QWaylandSur { } +QWaylandQtTextInputMethod *QWaylandInputMethodControlPrivate::textInputMethod() const +{ + if (!surface->client() || !surface->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) + return nullptr; + return QWaylandQtTextInputMethod::findIn(seat); +} + QWaylandTextInput *QWaylandInputMethodControlPrivate::textInput() const { + if (!surface->client() || !surface->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) + return nullptr; return QWaylandTextInput::findIn(seat); } + +QWaylandTextInputV3 *QWaylandInputMethodControlPrivate::textInputV3() const +{ + return QWaylandTextInputV3::findIn(seat); +} + +#include "moc_qwaylandinputmethodcontrol.cpp" diff --git a/src/compositor/compositor_api/qwaylandinputmethodcontrol.h b/src/compositor/compositor_api/qwaylandinputmethodcontrol.h index ae4bd5344..3b4d74870 100644 --- a/src/compositor/compositor_api/qwaylandinputmethodcontrol.h +++ b/src/compositor/compositor_api/qwaylandinputmethodcontrol.h @@ -1,47 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDINPUTMETHODCONTROL_H #define QWAYLANDINPUTMETHODCONTROL_H #include <QtGui/qtguiglobal.h> -#include <QObject> +#include <QtCore/QObject> QT_BEGIN_NAMESPACE @@ -49,6 +13,7 @@ class QWaylandCompositor; class QWaylandInputMethodControlPrivate; class QWaylandSurface; class QInputMethodEvent; +class QWaylandTextInput; class QWaylandInputMethodControl : public QObject { @@ -68,6 +33,7 @@ public: void setEnabled(bool enabled); void setSurface(QWaylandSurface *surface); + void updateTextInput(); Q_SIGNALS: void enabledChanged(bool enabled); diff --git a/src/compositor/compositor_api/qwaylandinputmethodcontrol_p.h b/src/compositor/compositor_api/qwaylandinputmethodcontrol_p.h index 337cf0087..36a0db0c4 100644 --- a/src/compositor/compositor_api/qwaylandinputmethodcontrol_p.h +++ b/src/compositor/compositor_api/qwaylandinputmethodcontrol_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDINPUTMETHODCONTROL_P_H #define QWAYLANDINPUTMETHODCONTROL_P_H @@ -62,8 +26,10 @@ class QWaylandCompositor; class QWaylandSeat; class QWaylandSurface; class QWaylandTextInput; +class QWaylandTextInputV3; +class QWaylandQtTextInputMethod; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandInputMethodControlPrivate : public QObjectPrivate +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandInputMethodControlPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QWaylandInputMethodControl) @@ -71,6 +37,8 @@ public: explicit QWaylandInputMethodControlPrivate(QWaylandSurface *surface); QWaylandTextInput *textInput() const; + QWaylandTextInputV3 *textInputV3() const; + QWaylandQtTextInputMethod *textInputMethod() const; QWaylandCompositor *compositor = nullptr; QWaylandSeat *seat = nullptr; diff --git a/src/compositor/compositor_api/qwaylandkeyboard.cpp b/src/compositor/compositor_api/qwaylandkeyboard.cpp index 68d855a66..8af7fbd8c 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard.cpp +++ b/src/compositor/compositor_api/qwaylandkeyboard.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qtwaylandcompositorglobal_p.h" #include "qwaylandkeyboard.h" @@ -49,12 +13,13 @@ #include <QtCore/QFile> #include <QtCore/QStandardPaths> +#include <QKeyEvent> #include <fcntl.h> #include <unistd.h> #if QT_CONFIG(xkbcommon) #include <sys/mman.h> #include <sys/types.h> -#include <qwaylandxkb_p.h> +#include <xkbcommon/xkbcommon-names.h> #endif QT_BEGIN_NAMESPACE @@ -67,12 +32,11 @@ QWaylandKeyboardPrivate::QWaylandKeyboardPrivate(QWaylandSeat *seat) QWaylandKeyboardPrivate::~QWaylandKeyboardPrivate() { #if QT_CONFIG(xkbcommon) - if (xkb_context) { + if (xkbContext()) { if (keymap_area) munmap(keymap_area, keymap_size); - close(keymap_fd); - xkb_context_unref(xkb_context); - xkb_state_unref(xkb_state); + if (keymap_fd >= 0) + close(keymap_fd); } #endif } @@ -137,14 +101,14 @@ void QWaylandKeyboardPrivate::keyboard_bind_resource(wl_keyboard::Resource *reso send_repeat_info(resource->handle, repeatRate, repeatDelay); #if QT_CONFIG(xkbcommon) - if (xkb_context) { + if (xkbContext()) { send_keymap(resource->handle, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size); } else #endif { int null_fd = open("/dev/null", O_RDONLY); - send_keymap(resource->handle, 0 /* WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP */, + send_keymap(resource->handle, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, null_fd, 0); close(null_fd); } @@ -164,11 +128,8 @@ void QWaylandKeyboardPrivate::keyboard_release(wl_keyboard::Resource *resource) void QWaylandKeyboardPrivate::keyEvent(uint code, uint32_t state) { -#if QT_CONFIG(xkbcommon) - uint key = toWaylandXkbV1Key(code); -#else - uint key = code; -#endif + uint key = toWaylandKey(code); + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { keys << key; } else { @@ -180,30 +141,18 @@ void QWaylandKeyboardPrivate::sendKeyEvent(uint code, uint32_t state) { uint32_t time = compositor()->currentTimeMsecs(); uint32_t serial = compositor()->nextSerial(); -#if QT_CONFIG(xkbcommon) - uint key = toWaylandXkbV1Key(code); -#else - uint key = code; -#endif + uint key = toWaylandKey(code); if (focusResource) send_key(focusResource->handle, serial, time, key, state); } -void QWaylandKeyboardPrivate::modifiers(uint32_t serial, uint32_t mods_depressed, - uint32_t mods_latched, uint32_t mods_locked, uint32_t group) -{ - if (focusResource) { - send_modifiers(focusResource->handle, serial, mods_depressed, mods_latched, mods_locked, group); - } -} - #if QT_CONFIG(xkbcommon) void QWaylandKeyboardPrivate::maybeUpdateXkbScanCodeTable() { if (!scanCodesByQtKey.isEmpty() || !xkbState()) return; - if (xkb_keymap *keymap = xkb_state_get_keymap(xkb_state)) { + if (xkb_keymap *keymap = xkb_state_get_keymap(xkbState())) { xkb_keymap_key_for_each(keymap, [](xkb_keymap *keymap, xkb_keycode_t keycode, void *d){ auto *scanCodesByQtKey = static_cast<QMap<ScanCodeKey, uint>*>(d); uint numLayouts = xkb_keymap_num_layouts_for_key(keymap, keycode); @@ -214,11 +163,27 @@ void QWaylandKeyboardPrivate::maybeUpdateXkbScanCodeTable() continue; Qt::KeyboardModifiers mods = {}; - int qtKey = QWaylandXkb::keysymToQtKey(syms[0], mods).first; + int qtKey = QXkbCommon::keysymToQtKey(syms[0], mods, nullptr, 0, false, false); if (qtKey != 0) scanCodesByQtKey->insert({layout, qtKey}, keycode); } }, &scanCodesByQtKey); + + shiftIndex = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_SHIFT); + controlIndex = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CTRL); + altIndex = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_ALT); + } +} + +void QWaylandKeyboardPrivate::resetKeyboardState() +{ + if (!xkbContext()) + return; + + while (!keys.isEmpty()) { + uint32_t code = fromWaylandKey(keys.first()); + keyEvent(code, WL_KEYBOARD_KEY_STATE_RELEASED); + updateModifierState(code, WL_KEYBOARD_KEY_STATE_RELEASED); } } #endif @@ -226,15 +191,15 @@ void QWaylandKeyboardPrivate::maybeUpdateXkbScanCodeTable() void QWaylandKeyboardPrivate::updateModifierState(uint code, uint32_t state) { #if QT_CONFIG(xkbcommon) - if (!xkb_context) + if (!xkbContext()) return; - xkb_state_update_key(xkb_state, code, state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); + xkb_state_update_key(xkbState(), code, state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); - uint32_t modsDepressed = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_DEPRESSED); - uint32_t modsLatched = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_LATCHED); - uint32_t modsLocked = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_LOCKED); - uint32_t group = xkb_state_serialize_group(xkb_state, (xkb_state_component)XKB_STATE_EFFECTIVE); + uint32_t modsDepressed = xkb_state_serialize_mods(xkbState(), XKB_STATE_MODS_DEPRESSED); + uint32_t modsLatched = xkb_state_serialize_mods(xkbState(), XKB_STATE_MODS_LATCHED); + uint32_t modsLocked = xkb_state_serialize_mods(xkbState(), XKB_STATE_MODS_LOCKED); + uint32_t group = xkb_state_serialize_layout(xkbState(), XKB_STATE_LAYOUT_EFFECTIVE); if (this->modsDepressed == modsDepressed && this->modsLatched == modsLatched @@ -247,7 +212,19 @@ void QWaylandKeyboardPrivate::updateModifierState(uint code, uint32_t state) this->modsLocked = modsLocked; this->group = group; - modifiers(compositor()->nextSerial(), modsDepressed, modsLatched, modsLocked, group); + if (focusResource) { + send_modifiers(focusResource->handle, compositor()->nextSerial(), modsDepressed, + modsLatched, modsLocked, group); + + Qt::KeyboardModifiers currentState = Qt::NoModifier; + if (xkb_state_mod_index_is_active(xkbState(), shiftIndex, XKB_STATE_MODS_EFFECTIVE) == 1) + currentState |= Qt::ShiftModifier; + if (xkb_state_mod_index_is_active(xkbState(), controlIndex, XKB_STATE_MODS_EFFECTIVE) == 1) + currentState |= Qt::ControlModifier; + if (xkb_state_mod_index_is_active(xkbState(), altIndex, XKB_STATE_MODS_EFFECTIVE) == 1) + currentState |= Qt::AltModifier; + currentModifierState = currentState; + } #else Q_UNUSED(code); Q_UNUSED(state); @@ -266,15 +243,16 @@ void QWaylandKeyboardPrivate::maybeUpdateKeymap() pendingKeymap = false; #if QT_CONFIG(xkbcommon) - if (!xkb_context) + if (!xkbContext()) return; createXKBKeymap(); - foreach (Resource *res, resourceMap()) { + const auto resMap = resourceMap(); + for (Resource *res : resMap) { send_keymap(res->handle, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymap_fd, keymap_size); } - xkb_state_update_mask(xkb_state, 0, modsLatched, modsLocked, 0, 0, 0); + xkb_state_update_mask(xkbState(), 0, modsLatched, modsLocked, 0, 0, 0); if (focusResource) send_modifiers(focusResource->handle, compositor()->nextSerial(), @@ -285,6 +263,36 @@ void QWaylandKeyboardPrivate::maybeUpdateKeymap() #endif } +// In all current XKB keymaps there's a constant offset of 8 (for historical +// reasons) from hardware/evdev scancodes to XKB keycodes. On X11, we pass +// XKB keycodes (as sent by X server) via QKeyEvent::nativeScanCode. eglfs+evdev +// adds 8 for consistency, see qtbase/05c07c7636012ebb4131ca099ca4ea093af76410. +// eglfs+libinput also adds 8, for the same reason. Wayland protocol uses +// hardware/evdev scancodes, thus we need to subtract 8 before sending the event +// out and add it when mapping back. +#define QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET 8 + +uint QWaylandKeyboardPrivate::fromWaylandKey(const uint key) +{ +#if QT_CONFIG(xkbcommon) + const uint offset = QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET; + return key + offset; +#else + return key; +#endif +} + +uint QWaylandKeyboardPrivate::toWaylandKey(const uint nativeScanCode) +{ +#if QT_CONFIG(xkbcommon) + const uint offset = QTWAYLANDKEYBOARD_XKB_HISTORICAL_OFFSET; + Q_ASSERT(nativeScanCode >= offset); + return nativeScanCode - offset; +#else + return nativeScanCode; +#endif +} + #if QT_CONFIG(xkbcommon) static int createAnonymousFile(size_t size) { @@ -316,18 +324,6 @@ static int createAnonymousFile(size_t size) return fd; } -void QWaylandKeyboardPrivate::initXKB() -{ - xkb_context = xkb_context_new(static_cast<xkb_context_flags>(0)); - if (!xkb_context) { - qWarning("Failed to create a XKB context: keymap will not be supported"); - return; - } - - createXKBKeymap(); -} - - void QWaylandKeyboardPrivate::createXKBState(xkb_keymap *keymap) { char *keymap_str = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_FORMAT_TEXT_V1); @@ -356,50 +352,53 @@ void QWaylandKeyboardPrivate::createXKBState(xkb_keymap *keymap) strcpy(keymap_area, keymap_str); free(keymap_str); - if (xkb_state) - xkb_state_unref(xkb_state); - xkb_state = xkb_state_new(keymap); -} - -uint QWaylandKeyboardPrivate::toWaylandXkbV1Key(const uint nativeScanCode) -{ - const uint offset = 8; - Q_ASSERT(nativeScanCode >= offset); - return nativeScanCode - offset; + mXkbState.reset(xkb_state_new(keymap)); + if (!mXkbState) + qWarning("Failed to create XKB state"); } void QWaylandKeyboardPrivate::createXKBKeymap() { - if (!xkb_context) + if (!xkbContext()) return; - auto keymap = seat->keymap(); - struct xkb_rule_names rule_names = { strdup(qPrintable(keymap->rules())), - strdup(qPrintable(keymap->model())), - strdup(qPrintable(keymap->layout())), - strdup(qPrintable(keymap->variant())), - strdup(qPrintable(keymap->options())) }; - struct xkb_keymap *xkbKeymap = xkb_keymap_new_from_names(xkb_context, &rule_names, static_cast<xkb_keymap_compile_flags>(0)); + QWaylandKeymap *keymap = seat->keymap(); + QByteArray rules = keymap->rules().toLocal8Bit(); + QByteArray model = keymap->model().toLocal8Bit(); + QByteArray layout = keymap->layout().toLocal8Bit(); + QByteArray variant = keymap->variant().toLocal8Bit(); + QByteArray options = keymap->options().toLocal8Bit(); + + if (!layout.isEmpty() && !layout.contains("us")) { + // This is needed for shortucts like "ctrl+c" to function even when + // user has selected only non-latin keyboard layouts, e.g. 'ru'. + layout.append(",us"); + variant.append(","); + } + struct xkb_rule_names rule_names = { + rules.constData(), + model.constData(), + layout.constData(), + variant.constData(), + options.constData() + }; + + QXkbCommon::ScopedXKBKeymap xkbKeymap(xkb_keymap_new_from_names(xkbContext(), &rule_names, + XKB_KEYMAP_COMPILE_NO_FLAGS)); if (xkbKeymap) { scanCodesByQtKey.clear(); - createXKBState(xkbKeymap); - xkb_keymap_unref(xkbKeymap); + createXKBState(xkbKeymap.get()); } else { qWarning("Failed to load the '%s' XKB keymap.", qPrintable(keymap->layout())); } - - free((char *)rule_names.rules); - free((char *)rule_names.model); - free((char *)rule_names.layout); - free((char *)rule_names.variant); - free((char *)rule_names.options); } -#endif +#endif // QT_CONFIG(xkbcommon) void QWaylandKeyboardPrivate::sendRepeatInfo() { - Q_FOREACH (Resource *resource, resourceMap()) { + const auto resMap = resourceMap(); + for (Resource *resource : resMap) { if (resource->version() >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) send_repeat_info(resource->handle, repeatRate, repeatDelay); } @@ -430,7 +429,7 @@ QWaylandKeyboard::QWaylandKeyboard(QWaylandSeat *seat, QObject *parent) connect(keymap, &QWaylandKeymap::rulesChanged, this, &QWaylandKeyboard::updateKeymap); connect(keymap, &QWaylandKeymap::modelChanged, this, &QWaylandKeyboard::updateKeymap); #if QT_CONFIG(xkbcommon) - d->initXKB(); + d->createXKBKeymap(); #endif } @@ -486,7 +485,7 @@ QWaylandClient *QWaylandKeyboard::focusClient() const /*! * Sends the current key modifiers to \a client with the given \a serial. */ -void QWaylandKeyboard::sendKeyModifiers(QWaylandClient *client, uint serial) +void QWaylandKeyboard::sendKeyModifiers(QWaylandClient *client, uint32_t serial) { Q_D(QWaylandKeyboard); QtWaylandServer::wl_keyboard::Resource *resource = d->resourceMap().value(client->client()); @@ -512,6 +511,38 @@ void QWaylandKeyboard::sendKeyReleaseEvent(uint code) d->sendKeyEvent(code, WL_KEYBOARD_KEY_STATE_RELEASED); } +void QWaylandKeyboardPrivate::checkAndRepairModifierState(QKeyEvent *ke) +{ +#if QT_CONFIG(xkbcommon) + if (ke->modifiers() != currentModifierState) { + if (focusResource && ke->key() != Qt::Key_Shift + && ke->key() != Qt::Key_Control && ke->key() != Qt::Key_Alt) { + // Only repair the state for non-modifier keys + // ### slightly awkward because the standard modifier handling + // is done by QtWayland::WindowSystemEventHandler after the + // key event is delivered + uint32_t mods = 0; + + if (shiftIndex == 0 && controlIndex == 0) + maybeUpdateXkbScanCodeTable(); + + if (ke->modifiers() & Qt::ShiftModifier) + mods |= 1 << shiftIndex; + if (ke->modifiers() & Qt::ControlModifier) + mods |= 1 << controlIndex; + if (ke->modifiers() & Qt::AltModifier) + mods |= 1 << altIndex; + qCDebug(qLcWaylandCompositor) << "Keyboard modifier state mismatch detected for event" << ke << "state:" << currentModifierState << "repaired:" << Qt::hex << mods; + send_modifiers(focusResource->handle, compositor()->nextSerial(), mods, + 0, 0, group); + currentModifierState = ke->modifiers(); + } + } +#else + Q_UNUSED(ke); +#endif +} + /*! * Returns the current repeat rate. */ @@ -603,3 +634,5 @@ uint QWaylandKeyboard::keyToScanCode(int qtKey) const } QT_END_NAMESPACE + +#include "moc_qwaylandkeyboard.cpp" diff --git a/src/compositor/compositor_api/qwaylandkeyboard.h b/src/compositor/compositor_api/qwaylandkeyboard.h index a443ed3a0..ebefcd2a2 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard.h +++ b/src/compositor/compositor_api/qwaylandkeyboard.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDKEYBOARD_H #define QWAYLANDKEYBOARD_H @@ -53,7 +17,7 @@ class QWaylandKeyboardPrivate; class QWaylandSeat; class QWaylandKeymap; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandKeyboard : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandKeyboard : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandKeyboard) diff --git a/src/compositor/compositor_api/qwaylandkeyboard_p.h b/src/compositor/compositor_api/qwaylandkeyboard_p.h index 87e89e85e..a91c60e43 100644 --- a/src/compositor/compositor_api/qwaylandkeyboard_p.h +++ b/src/compositor/compositor_api/qwaylandkeyboard_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QTWAYLAND_QWLKEYBOARD_P_H #define QTWAYLAND_QWLKEYBOARD_P_H @@ -51,6 +15,7 @@ // // We mean it. // +#include <QtWaylandCompositor/private/qwaylandcompositor_p.h> #include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h> #include <QtWaylandCompositor/qwaylandseat.h> @@ -60,16 +25,17 @@ #include <QtCore/private/qobject_p.h> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> -#include <QtCore/QVector> +#include <QtCore/QList> #if QT_CONFIG(xkbcommon) #include <xkbcommon/xkbcommon.h> +#include <QtGui/private/qxkbcommon_p.h> #endif QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandKeyboardPrivate : public QObjectPrivate +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandKeyboardPrivate : public QObjectPrivate , public QtWaylandServer::wl_keyboard { public: @@ -83,18 +49,21 @@ public: QWaylandCompositor *compositor() const { return seat->compositor(); } void focused(QWaylandSurface* surface); - void modifiers(uint32_t serial, uint32_t mods_depressed, - uint32_t mods_latched, uint32_t mods_locked, uint32_t group); #if QT_CONFIG(xkbcommon) - struct xkb_state *xkbState() const { return xkb_state; } + struct xkb_state *xkbState() const { return mXkbState.get(); } + struct xkb_context *xkbContext() const { + return QWaylandCompositorPrivate::get(seat->compositor())->xkbContext(); + } uint32_t xkbModsMask() const { return modsDepressed | modsLatched | modsLocked; } void maybeUpdateXkbScanCodeTable(); + void resetKeyboardState(); #endif void keyEvent(uint code, uint32_t state); void sendKeyEvent(uint code, uint32_t state); void updateModifierState(uint code, uint32_t state); + void checkAndRepairModifierState(QKeyEvent *ke); void maybeUpdateKeymap(); void checkFocusResource(Resource *resource); @@ -107,11 +76,11 @@ protected: private: #if QT_CONFIG(xkbcommon) - void initXKB(); void createXKBKeymap(); void createXKBState(xkb_keymap *keymap); #endif - static uint toWaylandXkbV1Key(const uint nativeScanCode); + static uint toWaylandKey(const uint nativeScanCode); + static uint fromWaylandKey(const uint key); void sendRepeatInfo(); @@ -121,12 +90,18 @@ private: Resource *focusResource = nullptr; QWaylandDestroyListener focusDestroyListener; - QVector<uint32_t> keys; + QList<uint32_t> keys; uint32_t modsDepressed = 0; uint32_t modsLatched = 0; uint32_t modsLocked = 0; uint32_t group = 0; + uint32_t shiftIndex = 0; + uint32_t controlIndex = 0; + uint32_t altIndex = 0; + + Qt::KeyboardModifiers currentModifierState; + bool pendingKeymap = false; #if QT_CONFIG(xkbcommon) size_t keymap_size; @@ -134,8 +109,7 @@ private: char *keymap_area = nullptr; using ScanCodeKey = std::pair<uint,int>; // group/layout and QtKey QMap<ScanCodeKey, uint> scanCodesByQtKey; - struct xkb_context *xkb_context = nullptr; - struct xkb_state *xkb_state = nullptr; + QXkbCommon::ScopedXKBState mXkbState; #endif quint32 repeatRate = 40; diff --git a/src/compositor/compositor_api/qwaylandkeymap.cpp b/src/compositor/compositor_api/qwaylandkeymap.cpp index e8664bb3d..160693532 100644 --- a/src/compositor/compositor_api/qwaylandkeymap.cpp +++ b/src/compositor/compositor_api/qwaylandkeymap.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandkeymap.h" #include "qwaylandkeymap_p.h" @@ -130,3 +94,5 @@ QWaylandKeymapPrivate::QWaylandKeymapPrivate(const QString &layout, const QStrin } QT_END_NAMESPACE + +#include "moc_qwaylandkeymap.cpp" diff --git a/src/compositor/compositor_api/qwaylandkeymap.h b/src/compositor/compositor_api/qwaylandkeymap.h index 8058e1440..a919160b2 100644 --- a/src/compositor/compositor_api/qwaylandkeymap.h +++ b/src/compositor/compositor_api/qwaylandkeymap.h @@ -1,63 +1,34 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDKEYMAP_H #define QWAYLANDKEYMAP_H #include <QtCore/QObject> #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> +#if QT_CONFIG(wayland_compositor_quick) #include <QtWaylandCompositor/qwaylandquickchildren.h> +#endif QT_BEGIN_NAMESPACE class QWaylandKeymapPrivate; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandKeymap : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandKeymap : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandKeymap) +#if QT_CONFIG(wayland_compositor_quick) Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(QWaylandKeymap) +#endif Q_PROPERTY(QString layout READ layout WRITE setLayout NOTIFY layoutChanged) Q_PROPERTY(QString variant READ variant WRITE setVariant NOTIFY variantChanged) Q_PROPERTY(QString options READ options WRITE setOptions NOTIFY optionsChanged) Q_PROPERTY(QString rules READ rules WRITE setRules NOTIFY rulesChanged) Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged) + QML_NAMED_ELEMENT(WaylandKeymap) + QML_ADDED_IN_VERSION(1, 0) public: QWaylandKeymap(const QString &layout = QString(), const QString &variant = QString(), const QString &options = QString(), const QString &model = QString(), const QString &rules = QString(), QObject *parent = nullptr); diff --git a/src/compositor/compositor_api/qwaylandkeymap_p.h b/src/compositor/compositor_api/qwaylandkeymap_p.h index dc863bdfd..a27500c46 100644 --- a/src/compositor/compositor_api/qwaylandkeymap_p.h +++ b/src/compositor/compositor_api/qwaylandkeymap_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDKEYMAP_P_H #define QWAYLANDKEYMAP_P_H @@ -56,7 +20,7 @@ QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandKeymapPrivate : public QObjectPrivate +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandKeymapPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QWaylandKeymap) public: diff --git a/src/compositor/compositor_api/qwaylandmousetracker.cpp b/src/compositor/compositor_api/qwaylandmousetracker.cpp new file mode 100644 index 000000000..efc539779 --- /dev/null +++ b/src/compositor/compositor_api/qwaylandmousetracker.cpp @@ -0,0 +1,143 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include "qwaylandmousetracker_p.h" + +#include <QtQuick/private/qquickitem_p.h> + +QT_BEGIN_NAMESPACE + +class QWaylandMouseTrackerPrivate : public QQuickItemPrivate +{ + Q_DECLARE_PUBLIC(QWaylandMouseTracker) +public: + QWaylandMouseTrackerPrivate() + { + QImage cursorImage(64,64,QImage::Format_ARGB32); + cursorImage.fill(Qt::transparent); + cursorPixmap = QPixmap::fromImage(cursorImage); + } + void handleMousePos(const QPointF &mousePos) + { + Q_Q(QWaylandMouseTracker); + bool xChanged = mousePos.x() != this->mousePos.x(); + bool yChanged = mousePos.y() != this->mousePos.y(); + if (xChanged || yChanged) { + this->mousePos = mousePos; + if (xChanged) + emit q->mouseXChanged(); + if (yChanged) + emit q->mouseYChanged(); + } + } + + void setHovered(bool hovered) + { + Q_Q(QWaylandMouseTracker); + if (this->hovered == hovered) + return; + this->hovered = hovered; + emit q->hoveredChanged(); + } + + QPointF mousePos; + bool windowSystemCursorEnabled = false; + QPixmap cursorPixmap; + bool hovered = false; +}; + +QWaylandMouseTracker::QWaylandMouseTracker(QQuickItem *parent) + : QQuickItem(*(new QWaylandMouseTrackerPrivate), parent) +{ + Q_D(QWaylandMouseTracker); + setFiltersChildMouseEvents(true); + setAcceptHoverEvents(true); + setAcceptedMouseButtons(Qt::AllButtons); +#if QT_CONFIG(cursor) + setCursor(QCursor(d->cursorPixmap)); +#endif +} + +qreal QWaylandMouseTracker::mouseX() const +{ + Q_D(const QWaylandMouseTracker); + return d->mousePos.x(); +} +qreal QWaylandMouseTracker::mouseY() const +{ + Q_D(const QWaylandMouseTracker); + return d->mousePos.y(); +} + +#if QT_CONFIG(cursor) +void QWaylandMouseTracker::setWindowSystemCursorEnabled(bool enable) +{ + Q_D(QWaylandMouseTracker); + if (d->windowSystemCursorEnabled != enable) { + d->windowSystemCursorEnabled = enable; + if (enable) { + unsetCursor(); + } else { + setCursor(QCursor(d->cursorPixmap)); + } + emit windowSystemCursorEnabledChanged(); + } +} + +bool QWaylandMouseTracker::windowSystemCursorEnabled() const +{ + Q_D(const QWaylandMouseTracker); + return d->windowSystemCursorEnabled; +} +#endif + +bool QWaylandMouseTracker::hovered() const +{ + Q_D(const QWaylandMouseTracker); + return d->hovered; +} + +bool QWaylandMouseTracker::childMouseEventFilter(QQuickItem *item, QEvent *event) +{ + Q_D(QWaylandMouseTracker); + if (event->type() == QEvent::MouseMove) { + QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); + d->handleMousePos(mapFromItem(item, mouseEvent->position())); + } else if (event->type() == QEvent::HoverMove) { + QHoverEvent *hoverEvent = static_cast<QHoverEvent *>(event); + d->handleMousePos(mapFromItem(item, hoverEvent->position())); + } + return false; +} + +void QWaylandMouseTracker::mouseMoveEvent(QMouseEvent *event) +{ + Q_D(QWaylandMouseTracker); + QQuickItem::mouseMoveEvent(event); + d->handleMousePos(event->position()); +} + +void QWaylandMouseTracker::hoverMoveEvent(QHoverEvent *event) +{ + Q_D(QWaylandMouseTracker); + QQuickItem::hoverMoveEvent(event); + d->handleMousePos(event->position()); +} + +void QWaylandMouseTracker::hoverEnterEvent(QHoverEvent *event) +{ + Q_D(QWaylandMouseTracker); + Q_UNUSED(event); + d->setHovered(true); +} + +void QWaylandMouseTracker::hoverLeaveEvent(QHoverEvent *event) +{ + Q_D(QWaylandMouseTracker); + Q_UNUSED(event); + d->setHovered(false); +} + +QT_END_NAMESPACE + +#include "moc_qwaylandmousetracker_p.cpp" diff --git a/src/compositor/compositor_api/qwaylandmousetracker_p.h b/src/compositor/compositor_api/qwaylandmousetracker_p.h new file mode 100644 index 000000000..efc49c3f5 --- /dev/null +++ b/src/compositor/compositor_api/qwaylandmousetracker_p.h @@ -0,0 +1,63 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef QWAYLANDMOUSETRACKER_P_H +#define QWAYLANDMOUSETRACKER_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtQuick/private/qquickmousearea_p.h> + +#include <QtWaylandCompositor/qtwaylandcompositorglobal.h> + +QT_BEGIN_NAMESPACE + +class QWaylandMouseTrackerPrivate; + +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandMouseTracker : public QQuickItem +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandMouseTracker) + Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged) + Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged) + Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) + + Q_PROPERTY(bool windowSystemCursorEnabled READ windowSystemCursorEnabled WRITE setWindowSystemCursorEnabled NOTIFY windowSystemCursorEnabledChanged) + QML_NAMED_ELEMENT(WaylandMouseTracker) + QML_ADDED_IN_VERSION(1, 0) +public: + QWaylandMouseTracker(QQuickItem *parent = nullptr); + + qreal mouseX() const; + qreal mouseY() const; + + void setWindowSystemCursorEnabled(bool enable); + bool windowSystemCursorEnabled() const; + bool hovered() const; + +Q_SIGNALS: + void mouseXChanged(); + void mouseYChanged(); + void windowSystemCursorEnabledChanged(); + void hoveredChanged(); + +protected: + bool childMouseEventFilter(QQuickItem *item, QEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void hoverMoveEvent(QHoverEvent *event) override; + void hoverEnterEvent(QHoverEvent *event) override; + void hoverLeaveEvent(QHoverEvent *event) override; +}; + +QT_END_NAMESPACE + +#endif /*QWAYLANDMOUSETRACKER_P_H*/ diff --git a/src/compositor/compositor_api/qwaylandoutput.cpp b/src/compositor/compositor_api/qwaylandoutput.cpp index 1f34f4eac..c19e2bd94 100644 --- a/src/compositor/compositor_api/qwaylandoutput.cpp +++ b/src/compositor/compositor_api/qwaylandoutput.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandoutput.h" #include "qwaylandoutput_p.h" @@ -47,6 +11,8 @@ #include <QtWaylandCompositor/private/qwaylandsurface_p.h> #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> #include <QtWaylandCompositor/private/qwaylandview_p.h> +#include <QtWaylandCompositor/private/qwaylandutils_p.h> +#include <QtWaylandCompositor/private/qwaylandxdgoutputv1_p.h> #include <QtCore/QCoreApplication> #include <QtCore/QtMath> @@ -161,6 +127,9 @@ void QWaylandOutputPrivate::sendGeometryInfo() if (resource->version() >= 2) send_done(resource->handle); } + + if (xdgOutput) + QWaylandXdgOutputV1Private::get(xdgOutput)->sendDone(); } void QWaylandOutputPrivate::sendMode(const Resource *resource, const QWaylandOutputMode &mode) @@ -184,6 +153,9 @@ void QWaylandOutputPrivate::sendModesInfo() if (resource->version() >= 2) send_done(resource->handle); } + + if (xdgOutput) + QWaylandXdgOutputV1Private::get(xdgOutput)->sendDone(); } void QWaylandOutputPrivate::handleWindowPixelSizeChanged() @@ -251,6 +223,7 @@ QWaylandOutput::QWaylandOutput() /*! \qmltype WaylandOutput + \instantiates QWaylandOutput \inqmlmodule QtWayland.Compositor \since 5.8 \brief Provides access to a displayable area managed by the compositor. @@ -260,6 +233,9 @@ QWaylandOutput::QWaylandOutput() a screen managed by the WaylandCompositor. The type corresponds to the \c wl_output interface in the Wayland protocol. + + \note If the compositor has multiple Wayland outputs, the \l Qt::AA_ShareOpenGLContexts + attribute must be set before the \l QGuiApplication object is constructed. */ /*! @@ -350,8 +326,8 @@ void QWaylandOutput::initialize() */ QWaylandOutput *QWaylandOutput::fromResource(wl_resource *resource) { - if (auto *r = QWaylandOutputPrivate::Resource::fromResource(resource)) - return static_cast<QWaylandOutputPrivate *>(r->output_object)->q_func(); + if (auto p = QtWayland::fromResource<QWaylandOutputPrivate *>(resource)) + return p->q_func(); return nullptr; } @@ -382,7 +358,7 @@ void QWaylandOutput::update() } /*! - * \qmlproperty WaylandCompositor QtWaylandCompositor::WaylandOutput::compositor + * \qmlproperty WaylandCompositor QtWayland.Compositor::WaylandOutput::compositor * * This property holds the compositor displaying content on this WaylandOutput. * @@ -422,7 +398,7 @@ void QWaylandOutput::setCompositor(QWaylandCompositor *compositor) } /*! - * \qmlproperty string QtWaylandCompositor::WaylandOutput::manufacturer + * \qmlproperty string QtWayland.Compositor::WaylandOutput::manufacturer * * This property holds a textual description of the manufacturer of this WaylandOutput. */ @@ -450,7 +426,7 @@ void QWaylandOutput::setManufacturer(const QString &manufacturer) } /*! - * \qmlproperty string QtWaylandCompositor::WaylandOutput::model + * \qmlproperty string QtWayland.Compositor::WaylandOutput::model * * This property holds a textual description of the model of this WaylandOutput. */ @@ -478,7 +454,7 @@ void QWaylandOutput::setModel(const QString &model) } /*! - * \qmlproperty point QtWaylandCompositor::WaylandOutput::position + * \qmlproperty point QtWayland.Compositor::WaylandOutput::position * * This property holds the position of this WaylandOutput in the compositor's coordinate system. */ @@ -530,7 +506,8 @@ void QWaylandOutput::addMode(const QWaylandOutputMode &mode, bool preferred) return; } - d->modes.append(mode); + if (d->modes.indexOf(mode) < 0) + d->modes.append(mode); if (preferred) d->preferredMode = d->modes.indexOf(mode); @@ -582,7 +559,7 @@ void QWaylandOutput::setCurrentMode(const QWaylandOutputMode &mode) } /*! - * \qmlproperty rect QtWaylandCompositor::WaylandOutput::geometry + * \qmlproperty rect QtWayland.Compositor::WaylandOutput::geometry * * This property holds the geometry of the WaylandOutput. */ @@ -601,7 +578,7 @@ QRect QWaylandOutput::geometry() const } /*! - * \qmlproperty rect QtWaylandCompositor::WaylandOutput::availableGeometry + * \qmlproperty rect QtWayland.Compositor::WaylandOutput::availableGeometry * * This property holds the geometry of the WaylandOutput available for displaying content. * The available geometry is in output coordinates space, starts from 0,0 and it's as big @@ -644,7 +621,7 @@ void QWaylandOutput::setAvailableGeometry(const QRect &availableGeometry) } /*! - * \qmlproperty size QtWaylandCompositor::WaylandOutput::physicalSize + * \qmlproperty size QtWayland.Compositor::WaylandOutput::physicalSize * * This property holds the physical size of the WaylandOutput in millimeters. * @@ -692,7 +669,7 @@ void QWaylandOutput::setPhysicalSize(const QSize &size) */ /*! - * \qmlproperty enum QtWaylandCompositor::WaylandOutput::subpixel + * \qmlproperty enum QtWayland.Compositor::WaylandOutput::subpixel * * This property holds the subpixel arrangement of this WaylandOutput. * @@ -749,7 +726,7 @@ void QWaylandOutput::setSubpixel(const Subpixel &subpixel) */ /*! - * \qmlproperty enum QtWaylandCompositor::WaylandOutput::transform + * \qmlproperty enum QtWayland.Compositor::WaylandOutput::transform * * This property holds the transformation that the QWaylandCompositor applies to a surface * to compensate for the orientation of the QWaylandOutput. @@ -795,7 +772,7 @@ void QWaylandOutput::setTransform(const Transform &transform) } /*! - * \qmlproperty int QtWaylandCompositor::WaylandOutput::scaleFactor + * \qmlproperty int QtWayland.Compositor::WaylandOutput::scaleFactor * * This property holds the factor by which the WaylandCompositor scales surface buffers * before they are displayed. It is used on high density output devices where unscaled content @@ -830,7 +807,8 @@ void QWaylandOutput::setScaleFactor(int scale) d->scaleFactor = scale; - Q_FOREACH (QWaylandOutputPrivate::Resource *resource, d->resourceMap().values()) { + const auto resMap = d->resourceMap(); + for (QWaylandOutputPrivate::Resource *resource : resMap) { if (resource->version() >= 2) { d->send_scale(resource->handle, scale); d->send_done(resource->handle); @@ -838,10 +816,13 @@ void QWaylandOutput::setScaleFactor(int scale) } Q_EMIT scaleFactorChanged(); + + if (d->xdgOutput) + QWaylandXdgOutputV1Private::get(d->xdgOutput)->sendDone(); } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandOutput::sizeFollowsWindow + * \qmlproperty bool QtWayland.Compositor::WaylandOutput::sizeFollowsWindow * * This property controls whether the size of the WaylandOutput matches the * size of its window. @@ -879,7 +860,7 @@ void QWaylandOutput::setSizeFollowsWindow(bool follow) } /*! - * \qmlproperty Window QtWaylandCompositor::WaylandOutput::window + * \qmlproperty Window QtWayland.Compositor::WaylandOutput::window * * This property holds the Window for this WaylandOutput. * diff --git a/src/compositor/compositor_api/qwaylandoutput.h b/src/compositor/compositor_api/qwaylandoutput.h index 31791a3c1..a45fa5756 100644 --- a/src/compositor/compositor_api/qwaylandoutput.h +++ b/src/compositor/compositor_api/qwaylandoutput.h @@ -1,53 +1,16 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDOUTPUT_H #define QWAYLANDOUTPUT_H +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> #include <QtWaylandCompositor/qwaylandcompositorextension.h> #include <QtWaylandCompositor/QWaylandOutputMode> #include <QtCore/QObject> - -#include <QObject> -#include <QRect> -#include <QSize> +#include <QtCore/QRect> +#include <QtCore/QSize> struct wl_resource; @@ -59,9 +22,8 @@ class QWindow; class QWaylandSurface; class QWaylandView; class QWaylandClient; -class QWaylandOutputSpace; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandOutput : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandOutput : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandOutput) @@ -77,8 +39,10 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandOutput : public QWaylandObject Q_PROPERTY(QWaylandOutput::Transform transform READ transform WRITE setTransform NOTIFY transformChanged) Q_PROPERTY(int scaleFactor READ scaleFactor WRITE setScaleFactor NOTIFY scaleFactorChanged) Q_PROPERTY(bool sizeFollowsWindow READ sizeFollowsWindow WRITE setSizeFollowsWindow NOTIFY sizeFollowsWindowChanged) - Q_ENUMS(Subpixel Transform) + QML_NAMED_ELEMENT(WaylandOutputBase) + QML_ADDED_IN_VERSION(1, 0) + QML_UNCREATABLE("Cannot create instance of WaylandOutputBase, use WaylandOutput instead") public: enum Subpixel { SubpixelUnknown = 0, diff --git a/src/compositor/compositor_api/qwaylandoutput_p.h b/src/compositor/compositor_api/qwaylandoutput_p.h index 4badd3797..f62def16c 100644 --- a/src/compositor/compositor_api/qwaylandoutput_p.h +++ b/src/compositor/compositor_api/qwaylandoutput_p.h @@ -1,43 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2016 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDOUTPUT_P_H #define QWAYLANDOUTPUT_P_H @@ -57,13 +21,15 @@ #include <QtWaylandCompositor/QWaylandOutput> #include <QtWaylandCompositor/QWaylandClient> #include <QtWaylandCompositor/QWaylandSurface> +#include <QtWaylandCompositor/QWaylandXdgOutputV1> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> +#include <QtCore/QList> #include <QtCore/QRect> -#include <QtCore/QVector> #include <QtCore/private/qobject_p.h> +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE @@ -87,13 +53,15 @@ struct QWaylandSurfaceViewMapper } QWaylandSurface *surface = nullptr; - QVector<QWaylandView *> views; + QList<QWaylandView *> views; bool has_entered = false; }; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandOutputPrivate : public QObjectPrivate, public QtWaylandServer::wl_output +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandOutputPrivate : public QObjectPrivate, public QtWaylandServer::wl_output { public: + Q_DECLARE_PUBLIC(QWaylandOutput) + QWaylandOutputPrivate(); ~QWaylandOutputPrivate() override; @@ -110,6 +78,8 @@ public: void handleWindowPixelSizeChanged(); + QPointer<QWaylandXdgOutputV1> xdgOutput; + protected: void output_bind_resource(Resource *resource) override; @@ -122,11 +92,11 @@ private: QString manufacturer; QString model; QPoint position; - QVector<QWaylandOutputMode> modes; + QList<QWaylandOutputMode> modes; int currentMode = -1; int preferredMode = -1; QRect availableGeometry; - QVector<QWaylandSurfaceViewMapper> surfaceViews; + QList<QWaylandSurfaceViewMapper> surfaceViews; QSize physicalSize; QWaylandOutput::Subpixel subpixel = QWaylandOutput::SubpixelUnknown; QWaylandOutput::Transform transform = QWaylandOutput::TransformNormal; @@ -135,8 +105,9 @@ private: bool initialized = false; QSize windowPixelSize; - Q_DECLARE_PUBLIC(QWaylandOutput) Q_DISABLE_COPY(QWaylandOutputPrivate) + + friend class QWaylandXdgOutputManagerV1Private; }; diff --git a/src/compositor/compositor_api/qwaylandoutputmode.cpp b/src/compositor/compositor_api/qwaylandoutputmode.cpp index 79a581609..04e738aec 100644 --- a/src/compositor/compositor_api/qwaylandoutputmode.cpp +++ b/src/compositor/compositor_api/qwaylandoutputmode.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandoutputmode.h" #include "qwaylandoutputmode_p.h" diff --git a/src/compositor/compositor_api/qwaylandoutputmode.h b/src/compositor/compositor_api/qwaylandoutputmode.h index b03457929..90238b121 100644 --- a/src/compositor/compositor_api/qwaylandoutputmode.h +++ b/src/compositor/compositor_api/qwaylandoutputmode.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDOUTPUTMODE_H #define QWAYLANDOUTPUTMODE_H @@ -45,7 +9,7 @@ QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandOutputMode +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandOutputMode { public: explicit QWaylandOutputMode(); diff --git a/src/compositor/compositor_api/qwaylandoutputmode_p.h b/src/compositor/compositor_api/qwaylandoutputmode_p.h index d6e061a04..232399c2c 100644 --- a/src/compositor/compositor_api/qwaylandoutputmode_p.h +++ b/src/compositor/compositor_api/qwaylandoutputmode_p.h @@ -1,46 +1,11 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDOUTPUTMODE_P_H #define QWAYLANDOUTPUTMODE_P_H #include <QtWaylandCompositor/QWaylandOutput> +#include <QtCore/private/qglobal_p.h> // // W A R N I N G @@ -55,7 +20,7 @@ QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandOutputModePrivate +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandOutputModePrivate { public: QWaylandOutputModePrivate() {} diff --git a/src/compositor/compositor_api/qwaylandpointer.cpp b/src/compositor/compositor_api/qwaylandpointer.cpp index 77e736a58..ee2c79a69 100644 --- a/src/compositor/compositor_api/qwaylandpointer.cpp +++ b/src/compositor/compositor_api/qwaylandpointer.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandpointer.h" #include "qwaylandpointer_p.h" @@ -100,9 +64,9 @@ void QWaylandPointerPrivate::sendLeave() uint32_t serial = compositor()->nextSerial(); for (auto resource : resourceMap().values(enteredSurface->waylandClient())) send_leave(resource->handle, serial, enteredSurface->resource()); - enteredSurface = nullptr; localPosition = QPointF(); enteredSurfaceDestroyListener.reset(); + enteredSurface = nullptr; } void QWaylandPointerPrivate::ensureEntered(QWaylandSurface *surface) @@ -124,11 +88,10 @@ void QWaylandPointerPrivate::pointer_release(wl_pointer::Resource *resource) void QWaylandPointerPrivate::pointer_set_cursor(wl_pointer::Resource *resource, uint32_t serial, wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) { - Q_UNUSED(resource); Q_UNUSED(serial); if (!surface) { - seat->cursorSurfaceRequest(nullptr, 0, 0); + seat->cursorSurfaceRequested(nullptr, 0, 0, QWaylandClient::fromWlClient(compositor(), resource->client())); return; } @@ -143,7 +106,7 @@ void QWaylandPointerPrivate::pointer_set_cursor(wl_pointer::Resource *resource, wl_resource *displayRes = wl_client_get_object(resource->client(), 1); if (s->setRole(&QWaylandPointerPrivate::s_role, displayRes, WL_DISPLAY_ERROR_INVALID_OBJECT)) { s->markAsCursorSurface(true); - seat->cursorSurfaceRequest(s, hotspot_x, hotspot_y); + seat->cursorSurfaceRequested(s, hotspot_x, hotspot_y, QWaylandClient::fromWlClient(compositor(), resource->client())); } } @@ -239,7 +202,7 @@ uint QWaylandPointer::sendMouseReleaseEvent(Qt::MouseButton button) /*! * Sets the current mouse focus to \a view and sends a mouse move event to it with the - * local position \a localPos and output space position \a outputSpacePos. + * local position \a localPos in surface coordinates and output space position \a outputSpacePos. */ void QWaylandPointer::sendMouseMoveEvent(QWaylandView *view, const QPointF &localPos, const QPointF &outputSpacePos) { @@ -253,7 +216,7 @@ void QWaylandPointer::sendMouseMoveEvent(QWaylandView *view, const QPointF &loca if (view) { // We adjust if the mouse position is on the edge // to work around Qt's event propagation - QSizeF size(view->surface()->size()); + QSizeF size(view->surface()->destinationSize()); if (d->localPosition.x() == size.width()) d->localPosition.rx() -= 0.01; if (d->localPosition.y() == size.height()) @@ -294,7 +257,7 @@ QWaylandView *QWaylandPointer::mouseFocus() const } /*! - * Returns the current local position of the QWaylandPointer. + * Returns the current local position of the QWaylandPointer in surface coordinates. */ QPointF QWaylandPointer::currentLocalPosition() const { @@ -402,7 +365,7 @@ uint32_t QWaylandPointer::toWaylandButton(Qt::MouseButton button) void QWaylandPointer::enteredSurfaceDestroyed(void *data) { Q_D(QWaylandPointer); - Q_UNUSED(data) + Q_UNUSED(data); d->enteredSurfaceDestroyListener.reset(); d->enteredSurface = nullptr; @@ -427,3 +390,5 @@ void QWaylandPointer::pointerFocusChanged(QWaylandView *newFocus, QWaylandView * } QT_END_NAMESPACE + +#include "moc_qwaylandpointer.cpp" diff --git a/src/compositor/compositor_api/qwaylandpointer.h b/src/compositor/compositor_api/qwaylandpointer.h index 409bcc83a..7d5a96b6e 100644 --- a/src/compositor/compositor_api/qwaylandpointer.h +++ b/src/compositor/compositor_api/qwaylandpointer.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDPOINTER_H #define QWAYLANDPOINTER_H @@ -53,7 +17,7 @@ class QWaylandView; class QWaylandOutput; class QWaylandClient; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandPointer : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandPointer : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandPointer) diff --git a/src/compositor/compositor_api/qwaylandpointer_p.h b/src/compositor/compositor_api/qwaylandpointer_p.h index d45451cb9..71970351b 100644 --- a/src/compositor/compositor_api/qwaylandpointer_p.h +++ b/src/compositor/compositor_api/qwaylandpointer_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDPOINTER_P_H #define QWAYLANDPOINTER_P_H @@ -66,13 +30,15 @@ #include <QtWaylandCompositor/QWaylandSurface> #include <QtWaylandCompositor/QWaylandSeat> +#include <QtCore/qpointer.h> + #include <stdint.h> QT_BEGIN_NAMESPACE class QWaylandView; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandPointerPrivate : public QObjectPrivate +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandPointerPrivate : public QObjectPrivate , public QtWaylandServer::wl_pointer { Q_DECLARE_PUBLIC(QWaylandPointer) diff --git a/src/compositor/compositor_api/qwaylandquickchildren.h b/src/compositor/compositor_api/qwaylandquickchildren.h index 7d821ab50..5024b322e 100644 --- a/src/compositor/compositor_api/qwaylandquickchildren.h +++ b/src/compositor/compositor_api/qwaylandquickchildren.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDQUICKCHILDREN_H #define QWAYLANDQUICKCHILDREN_H @@ -51,16 +15,15 @@ // We mean it. // -#ifdef QT_WAYLAND_COMPOSITOR_QUICK +#include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#if QT_CONFIG(wayland_compositor_quick) #include <QtQml/QQmlListProperty> -#include <QtCore/QVector> +#include <QtCore/QList> #endif -#include <QtCore/qglobal.h> - QT_BEGIN_NAMESPACE -#ifdef QT_WAYLAND_COMPOSITOR_QUICK +#if QT_CONFIG(wayland_compositor_quick) #define Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(className) \ Q_PROPERTY(QQmlListProperty<QObject> data READ data DESIGNABLE false) \ Q_CLASSINFO("DefaultProperty", "data") \ @@ -77,11 +40,11 @@ QT_BEGIN_NAMESPACE { \ static_cast<className *>(list->data)->m_children.append(object); \ } \ - static int countFunction(QQmlListProperty<QObject> *list) \ + static qsizetype countFunction(QQmlListProperty<QObject> *list) \ { \ return static_cast<className *>(list->data)->m_children.size(); \ } \ - static QObject *atFunction(QQmlListProperty<QObject> *list, int index) \ + static QObject *atFunction(QQmlListProperty<QObject> *list, qsizetype index) \ { \ return static_cast<className *>(list->data)->m_children.at(index); \ } \ @@ -90,7 +53,7 @@ QT_BEGIN_NAMESPACE static_cast<className *>(list->data)->m_children.clear(); \ } \ private: \ - QVector<QObject *> m_children; + QList<QObject *> m_children; #else #define Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(className) #endif diff --git a/src/compositor/compositor_api/qwaylandquickcompositor.cpp b/src/compositor/compositor_api/qwaylandquickcompositor.cpp index 8e8a903e3..43cc8c3e2 100644 --- a/src/compositor/compositor_api/qwaylandquickcompositor.cpp +++ b/src/compositor/compositor_api/qwaylandquickcompositor.cpp @@ -1,48 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtQml/QQmlEngine> #include <QQuickWindow> -#include <QOpenGLTextureBlitter> -#include <QOpenGLTexture> -#include <QOpenGLFramebufferObject> +#if QT_CONFIG(opengl) +# include <QOpenGLTextureBlitter> +# include <QOpenGLTexture> +# include <QOpenGLFramebufferObject> +#endif #include <QMatrix4x4> #include <QRunnable> @@ -53,6 +19,7 @@ #include "qwaylandquickitem.h" #include "qwaylandoutput.h" #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> +#include <QtWaylandCompositor/QWaylandViewporter> #include "qwaylandsurfacegrabber.h" QT_BEGIN_NAMESPACE @@ -60,8 +27,9 @@ QT_BEGIN_NAMESPACE class QWaylandQuickCompositorPrivate : public QWaylandCompositorPrivate { public: - QWaylandQuickCompositorPrivate(QWaylandCompositor *compositor) + explicit QWaylandQuickCompositorPrivate(QWaylandCompositor *compositor) : QWaylandCompositorPrivate(compositor) + , m_viewporter(new QWaylandViewporter(compositor)) { } protected: @@ -69,6 +37,8 @@ protected: { return new QWaylandQuickSurface(); } +private: + QScopedPointer<QWaylandViewporter> m_viewporter; }; QWaylandQuickCompositor::QWaylandQuickCompositor(QObject *parent) @@ -77,7 +47,7 @@ QWaylandQuickCompositor::QWaylandQuickCompositor(QObject *parent) } /*! - * \qmlproperty list QtWaylandCompositor::WaylandCompositor::extensions + * \qmlproperty list QtWayland.Compositor::WaylandCompositor::extensions * * A list of extensions that the compositor advertises to its clients. For * any Wayland extension the compositor should support, instantiate its component, @@ -86,15 +56,15 @@ QWaylandQuickCompositor::QWaylandQuickCompositor(QObject *parent) * For instance, the following code would allow the clients to request \c wl_shell * surfaces in the compositor using the \c wl_shell interface. * - * \code - * import QtWayland.Compositor 1.0 + * \qml + * import QtWayland.Compositor * * WaylandCompositor { * WlShell { * // ... * } * } - * \endcode + * \endqml */ void QWaylandQuickCompositor::create() @@ -124,6 +94,7 @@ void QWaylandQuickCompositor::grabSurface(QWaylandSurfaceGrabber *grabber, const return; } +#if QT_CONFIG(opengl) QWaylandQuickOutput *output = static_cast<QWaylandQuickOutput *>(defaultOutput()); if (!output) { emit grabber->failed(QWaylandSurfaceGrabber::RendererNotReady); @@ -164,7 +135,12 @@ void QWaylandQuickCompositor::grabSurface(QWaylandSurfaceGrabber *grabber, const GrabState *state = new GrabState; state->grabber = grabber; state->buffer = buffer; - static_cast<QQuickWindow *>(output->window())->scheduleRenderJob(state, QQuickWindow::NoStage); + static_cast<QQuickWindow *>(output->window())->scheduleRenderJob(state, QQuickWindow::AfterRenderingStage); +#else + emit grabber->failed(QWaylandSurfaceGrabber::UnknownBufferType); +#endif } QT_END_NAMESPACE + +#include "moc_qwaylandquickcompositor.cpp" diff --git a/src/compositor/compositor_api/qwaylandquickcompositor.h b/src/compositor/compositor_api/qwaylandquickcompositor.h index 440abecc7..921f1fefb 100644 --- a/src/compositor/compositor_api/qwaylandquickcompositor.h +++ b/src/compositor/compositor_api/qwaylandquickcompositor.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDQUICKCOMPOSITOR_H #define QWAYLANDQUICKCOMPOSITOR_H @@ -43,13 +7,15 @@ #include <QtWaylandCompositor/qwaylandcompositor.h> #include <QtQml/QQmlParserStatus> +QT_REQUIRE_CONFIG(wayland_compositor_quick); + QT_BEGIN_NAMESPACE class QQuickWindow; class QWaylandQuickCompositorPrivate; class QWaylandView; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickCompositor : public QWaylandCompositor, public QQmlParserStatus +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickCompositor : public QWaylandCompositor, public QQmlParserStatus { Q_INTERFACES(QQmlParserStatus) Q_OBJECT diff --git a/src/compositor/compositor_api/qwaylandquickhardwarelayer.cpp b/src/compositor/compositor_api/qwaylandquickhardwarelayer.cpp index 11dd7b47d..9cf36b36f 100644 --- a/src/compositor/compositor_api/qwaylandquickhardwarelayer.cpp +++ b/src/compositor/compositor_api/qwaylandquickhardwarelayer.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandquickhardwarelayer_p.h" @@ -115,7 +79,7 @@ QWaylandQuickHardwareLayer::~QWaylandQuickHardwareLayer() } /*! - * \qmlproperty int QtWaylandCompositor::WaylandHardwareLayer::stackingLevel + * \qmlproperty int QtWayland.Compositor::WaylandHardwareLayer::stackingLevel * * This property holds the stacking level of this hardware layer relative to other hardware layers, * and can be used to sort hardware layers. I.e. a layer with a higher level is rendered on top of @@ -170,9 +134,18 @@ void QWaylandQuickHardwareLayer::componentComplete() qWarning() << "No hardware layer integration. WaylandHarwareLayer has no effect."; } -void QWaylandQuickHardwareLayer::disableSceneGraphPainting() +void QWaylandQuickHardwareLayer::setSceneGraphPainting(bool enable) { - waylandItem()->setPaintEnabled(false); + waylandItem()->setPaintEnabled(enable); +} + +// This should be called if QWaylandQuickHardwareLayer used as a native instance, not a qml component. +void QWaylandQuickHardwareLayer::initialize() +{ + classBegin(); + componentComplete(); } QT_END_NAMESPACE + +#include "moc_qwaylandquickhardwarelayer_p.cpp" diff --git a/src/compositor/compositor_api/qwaylandquickhardwarelayer_p.h b/src/compositor/compositor_api/qwaylandquickhardwarelayer_p.h index 24cb709f4..d33a8c0d7 100644 --- a/src/compositor/compositor_api/qwaylandquickhardwarelayer_p.h +++ b/src/compositor/compositor_api/qwaylandquickhardwarelayer_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDQUICKHARDWARELAYER_P_H #define QWAYLANDQUICKHARDWARELAYER_P_H @@ -52,17 +16,20 @@ // #include <QtWaylandCompositor/QWaylandQuickItem> +#include <QtCore/private/qglobal_p.h> QT_BEGIN_NAMESPACE class QWaylandQuickHardwareLayerPrivate; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickHardwareLayer : public QObject, public QQmlParserStatus +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickHardwareLayer : public QObject, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) Q_DECLARE_PRIVATE(QWaylandQuickHardwareLayer) Q_PROPERTY(int stackingLevel READ stackingLevel WRITE setStackingLevel NOTIFY stackingLevelChanged) + QML_NAMED_ELEMENT(WaylandHardwareLayer) + QML_ADDED_IN_VERSION(1, 2) public: explicit QWaylandQuickHardwareLayer(QObject *parent = nullptr); ~QWaylandQuickHardwareLayer() override; @@ -75,7 +42,8 @@ public: void classBegin() override; void componentComplete() override; - void disableSceneGraphPainting(); + void setSceneGraphPainting(bool); + void initialize(); Q_SIGNALS: void stackingLevelChanged(); diff --git a/src/compositor/compositor_api/qwaylandquickitem.cpp b/src/compositor/compositor_api/qwaylandquickitem.cpp index 2b24c13b7..c643598be 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.cpp +++ b/src/compositor/compositor_api/qwaylandquickitem.cpp @@ -1,47 +1,13 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandquickitem.h" #include "qwaylandquickitem_p.h" #include "qwaylandquicksurface.h" #include "qwaylandinputmethodcontrol.h" #include "qwaylandtextinput.h" +#include "qwaylandtextinputv3.h" +#include "qwaylandqttextinputmethod.h" #include "qwaylandquickoutput.h" #include <QtWaylandCompositor/qwaylandcompositor.h> #include <QtWaylandCompositor/qwaylandseat.h> @@ -52,150 +18,253 @@ #include <QtWaylandCompositor/private/qwlclientbufferintegration_p.h> #include <QtWaylandCompositor/private/qwaylandsurface_p.h> +#if QT_CONFIG(opengl) +# include <QtOpenGL/QOpenGLTexture> +# include <QtGui/QOpenGLFunctions> +#endif + #include <QtGui/QKeyEvent> #include <QtGui/QGuiApplication> #include <QtGui/QScreen> -#include <QtGui/QOpenGLFunctions> -#include <QtGui/QOpenGLTexture> #include <QtQuick/QSGSimpleTextureNode> #include <QtQuick/QQuickWindow> +#include <QtQuick/qsgtexture.h> +#include <QtCore/QFile> #include <QtCore/QMutexLocker> #include <QtCore/QMutex> -#include <wayland-server.h> +#include <wayland-server-core.h> #include <QThread> +#if QT_CONFIG(opengl) +#include <QtGui/private/qshaderdescription_p.h> +#endif + #ifndef GL_TEXTURE_EXTERNAL_OES #define GL_TEXTURE_EXTERNAL_OES 0x8D65 #endif QT_BEGIN_NAMESPACE +#if QT_CONFIG(opengl) static const struct { const char * const vertexShaderSourceFile; const char * const fragmentShaderSourceFile; - GLenum textureTarget; int planeCount; bool canProvideTexture; QSGMaterial::Flags materialFlags; QSGMaterialType materialType; } bufferTypes[] = { // BufferFormatEgl_Null - { "", "", 0, 0, false, 0, {} }, + { "", "", 0, false, {}, {} }, - // BufferFormatEgl_RGB + // BufferFormatEgl_RGB (GL_TEXTURE_2D) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", - ":/qt-project.org/wayland/compositor/shaders/surface_rgbx.frag", - GL_TEXTURE_2D, 1, true, + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", + ":/qt-project.org/wayland/compositor/shaders/surface_rgbx.frag.qsb", + 1, true, QSGMaterial::Blending, {} }, - // BufferFormatEgl_RGBA + // BufferFormatEgl_RGBA (GL_TEXTURE_2D) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", - ":/qt-project.org/wayland/compositor/shaders/surface_rgba.frag", - GL_TEXTURE_2D, 1, true, + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", + ":/qt-project.org/wayland/compositor/shaders/surface_rgba.frag.qsb", + 1, true, QSGMaterial::Blending, {} }, - // BufferFormatEgl_EXTERNAL_OES + // BufferFormatEgl_EXTERNAL_OES (GL_TEXTURE_EXTERNAL_OES) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", ":/qt-project.org/wayland/compositor/shaders/surface_oes_external.frag", - GL_TEXTURE_EXTERNAL_OES, 1, false, + 1, false, QSGMaterial::Blending, {} }, - // BufferFormatEgl_Y_U_V + // BufferFormatEgl_Y_U_V (GL_TEXTURE_2D) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", - ":/qt-project.org/wayland/compositor/shaders/surface_y_u_v.frag", - GL_TEXTURE_2D, 3, false, + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", + ":/qt-project.org/wayland/compositor/shaders/surface_y_u_v.frag.qsb", + 3, false, QSGMaterial::Blending, {} }, - // BufferFormatEgl_Y_UV + // BufferFormatEgl_Y_UV (GL_TEXTURE_2D) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", - ":/qt-project.org/wayland/compositor/shaders/surface_y_uv.frag", - GL_TEXTURE_2D, 2, false, + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", + ":/qt-project.org/wayland/compositor/shaders/surface_y_uv.frag.qsb", + 2, false, QSGMaterial::Blending, {} }, - // BufferFormatEgl_Y_XUXV + // BufferFormatEgl_Y_XUXV (GL_TEXTURE_2D) { - ":/qt-project.org/wayland/compositor/shaders/surface.vert", - ":/qt-project.org/wayland/compositor/shaders/surface_y_xuxv.frag", - GL_TEXTURE_2D, 2, false, + ":/qt-project.org/wayland/compositor/shaders/surface.vert.qsb", + ":/qt-project.org/wayland/compositor/shaders/surface_y_xuxv.frag.qsb", + 2, false, QSGMaterial::Blending, {} } }; QWaylandBufferMaterialShader::QWaylandBufferMaterialShader(QWaylandBufferRef::BufferFormatEgl format) - : m_format(format) { - setShaderSourceFile(QOpenGLShader::Vertex, QString::fromLatin1(bufferTypes[format].vertexShaderSourceFile)); - setShaderSourceFile(QOpenGLShader::Fragment, QString::fromLatin1(bufferTypes[format].fragmentShaderSourceFile)); + Q_UNUSED(format); + setShaderFileName(VertexStage, QString::fromLatin1(bufferTypes[format].vertexShaderSourceFile)); + auto fragmentShaderSourceFile = QString::fromLatin1(bufferTypes[format].fragmentShaderSourceFile); + + if (format == QWaylandBufferRef::BufferFormatEgl_EXTERNAL_OES) + setupExternalOESShader(fragmentShaderSourceFile); + else + setShaderFileName(FragmentStage, fragmentShaderSourceFile); } -void QWaylandBufferMaterialShader::updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) +void QWaylandBufferMaterialShader::setupExternalOESShader(const QString &shaderFilename) { - QSGMaterialShader::updateState(state, newEffect, oldEffect); +#if QT_CONFIG(opengl) + QFile shaderFile(shaderFilename); + if (!shaderFile.open(QIODevice::ReadOnly)) { + qCWarning(qLcWaylandCompositor) << "Cannot find external OES shader file:" << shaderFilename; + return; + } + QByteArray FS = shaderFile.readAll(); + + static const char *FS_GLES_PREAMBLE = + "#extension GL_OES_EGL_image_external : require\n" + "precision highp float;\n"; + static const char *FS_GL_PREAMBLE = + "#version 120\n" + "#extension GL_OES_EGL_image_external : require\n"; + QByteArray fsGLES = FS_GLES_PREAMBLE + FS; + QByteArray fsGL = FS_GL_PREAMBLE + FS; + + QShaderDescription desc; + QShaderDescriptionPrivate *descData = QShaderDescriptionPrivate::get(&desc); + + QShaderDescription::InOutVariable texCoordInput; + texCoordInput.name = "v_texcoord"; + texCoordInput.type = QShaderDescription::Vec2; + texCoordInput.location = 0; + + descData->inVars = { texCoordInput }; + + QShaderDescription::InOutVariable fragColorOutput; + fragColorOutput.name = "gl_FragColor"; + fragColorOutput.type = QShaderDescription::Vec4; + fragColorOutput.location = 0; + + descData->outVars = { fragColorOutput }; + + QShaderDescription::BlockVariable matrixBlockVar; + matrixBlockVar.name = "qt_Matrix"; + matrixBlockVar.type = QShaderDescription::Mat4; + matrixBlockVar.offset = 0; + matrixBlockVar.size = 64; + + QShaderDescription::BlockVariable opacityBlockVar; + opacityBlockVar.name = "qt_Opacity"; + opacityBlockVar.type = QShaderDescription::Float; + opacityBlockVar.offset = 64; + opacityBlockVar.size = 4; + + QShaderDescription::UniformBlock ubufStruct; + ubufStruct.blockName = "buf"; + ubufStruct.structName = "ubuf"; + ubufStruct.size = 64 + 4; + ubufStruct.binding = 0; + ubufStruct.members = { matrixBlockVar, opacityBlockVar }; + + descData->uniformBlocks = { ubufStruct }; + + QShaderDescription::InOutVariable samplerTex0; + samplerTex0.name = "tex0"; + samplerTex0.type = QShaderDescription::SamplerExternalOES; + samplerTex0.binding = 1; + + descData->combinedImageSamplers = { samplerTex0 }; + + QShader shaderPack; + shaderPack.setStage(QShader::FragmentStage); + shaderPack.setDescription(desc); + shaderPack.setShader(QShaderKey(QShader::GlslShader, QShaderVersion(100, QShaderVersion::GlslEs)), QShaderCode(fsGLES)); + shaderPack.setShader(QShaderKey(QShader::GlslShader, QShaderVersion(120)), QShaderCode(fsGL)); + + setShader(FragmentStage, shaderPack); +#else + Q_UNUSED(shaderFilename); +#endif +} - QWaylandBufferMaterial *material = static_cast<QWaylandBufferMaterial *>(newEffect); - material->bind(); +bool QWaylandBufferMaterialShader::updateUniformData(RenderState &state, QSGMaterial *, QSGMaterial *) +{ + bool changed = false; + QByteArray *buf = state.uniformData(); + Q_ASSERT(buf->size() >= 68); - if (state.isMatrixDirty()) - program()->setUniformValue(m_id_matrix, state.combinedMatrix()); + if (state.isMatrixDirty()) { + const QMatrix4x4 m = state.combinedMatrix(); + memcpy(buf->data(), m.constData(), 64); + changed = true; + } - if (state.isOpacityDirty()) - program()->setUniformValue(m_id_opacity, state.opacity()); -} + if (state.isOpacityDirty()) { + const float opacity = state.opacity(); + memcpy(buf->data() + 64, &opacity, 4); + changed = true; + } -const char * const *QWaylandBufferMaterialShader::attributeNames() const -{ - static char const *const attr[] = { "qt_VertexPosition", "qt_VertexTexCoord", nullptr }; - return attr; + return changed; } -void QWaylandBufferMaterialShader::initialize() +void QWaylandBufferMaterialShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture, + QSGMaterial *newMaterial, QSGMaterial *) { - QSGMaterialShader::initialize(); + Q_UNUSED(state); - m_id_matrix = program()->uniformLocation("qt_Matrix"); - m_id_opacity = program()->uniformLocation("qt_Opacity"); - - for (int i = 0; i < bufferTypes[m_format].planeCount; i++) { - m_id_tex << program()->uniformLocation("tex" + QByteArray::number(i)); - program()->setUniformValue(m_id_tex[i], i); + QWaylandBufferMaterial *material = static_cast<QWaylandBufferMaterial *>(newMaterial); + switch (binding) { + case 1: + *texture = material->m_scenegraphTextures.at(0); + break; + case 2: + *texture = material->m_scenegraphTextures.at(1); + break; + case 3: + *texture = material->m_scenegraphTextures.at(2); + break; + default: + return; } - Q_ASSERT(m_id_tex.size() == bufferTypes[m_format].planeCount); + // This is for the shared memory case, and is a no-op for others, + // this is where the upload from the QImage happens when not yet done. + // ### or is this too late? (if buffer.image() disappears in the meantime then this is the wrong...) + if (*texture) + (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); } QWaylandBufferMaterial::QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format) : m_format(format) { - QOpenGLFunctions *gl = QOpenGLContext::currentContext()->functions(); - - gl->glBindTexture(bufferTypes[m_format].textureTarget, 0); setFlag(bufferTypes[m_format].materialFlags); } QWaylandBufferMaterial::~QWaylandBufferMaterial() { + qDeleteAll(m_scenegraphTextures); } -void QWaylandBufferMaterial::setTextureForPlane(int plane, QOpenGLTexture *texture) +void QWaylandBufferMaterial::setTextureForPlane(int plane, + QOpenGLTexture *texture, + QSGTexture *scenegraphTexture) { if (plane < 0 || plane >= bufferTypes[m_format].planeCount) { qWarning("plane index is out of range"); @@ -207,10 +276,15 @@ void QWaylandBufferMaterial::setTextureForPlane(int plane, QOpenGLTexture *textu ensureTextures(plane - 1); - if (m_textures.size() <= plane) + if (m_textures.size() <= plane) { m_textures << texture; - else + m_scenegraphTextures << scenegraphTexture; + } else { + delete m_scenegraphTextures[plane]; + m_textures[plane] = texture; + m_scenegraphTextures[plane] = scenegraphTexture; + } } void QWaylandBufferMaterial::bind() @@ -237,8 +311,9 @@ QSGMaterialType *QWaylandBufferMaterial::type() const return const_cast<QSGMaterialType *>(&bufferTypes[m_format].materialType); } -QSGMaterialShader *QWaylandBufferMaterial::createShader() const +QSGMaterialShader *QWaylandBufferMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const { + Q_UNUSED(renderMode); return new QWaylandBufferMaterialShader(m_format); } @@ -257,9 +332,40 @@ void QWaylandBufferMaterial::ensureTextures(int count) { for (int plane = m_textures.size(); plane < count; plane++) { m_textures << nullptr; + m_scenegraphTextures << nullptr; } } +void QWaylandBufferMaterial::setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref) +{ + m_bufferRef = ref; + for (int plane = 0; plane < bufferTypes[ref.bufferFormatEgl()].planeCount; plane++) { + if (auto texture = ref.toOpenGLTexture(plane)) { + QQuickWindow::CreateTextureOptions opt; + QWaylandQuickSurface *waylandSurface = qobject_cast<QWaylandQuickSurface *>(surfaceItem->surface()); + if (waylandSurface != nullptr && waylandSurface->useTextureAlpha() && !waylandSurface->isOpaque()) + opt |= QQuickWindow::TextureHasAlphaChannel; + QSGTexture *scenegraphTexture; + if (ref.bufferFormatEgl() == QWaylandBufferRef::BufferFormatEgl_EXTERNAL_OES) { + scenegraphTexture = QNativeInterface::QSGOpenGLTexture::fromNativeExternalOES(texture->textureId(), + surfaceItem->window(), + ref.size(), + opt); + } else { + scenegraphTexture = QNativeInterface::QSGOpenGLTexture::fromNative(texture->textureId(), + surfaceItem->window(), + ref.size(), + opt); + } + scenegraphTexture->setFiltering(surfaceItem->smooth() ? QSGTexture::Linear : QSGTexture::Nearest); + setTextureForPlane(plane, texture, scenegraphTexture); + } + } + + bind(); +} +#endif // QT_CONFIG(opengl) + QMutex *QWaylandQuickItemPrivate::mutex = nullptr; class QWaylandSurfaceTextureProvider : public QSGTextureProvider @@ -271,8 +377,7 @@ public: ~QWaylandSurfaceTextureProvider() override { - if (m_sgTex) - m_sgTex->deleteLater(); + delete m_sgTex; } void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &buffer) @@ -284,18 +389,21 @@ public: if (m_ref.hasBuffer()) { if (buffer.isSharedMemory()) { m_sgTex = surfaceItem->window()->createTextureFromImage(buffer.image()); - if (m_sgTex) { - m_sgTex->bind(); - } } else { +#if QT_CONFIG(opengl) QQuickWindow::CreateTextureOptions opt; QWaylandQuickSurface *surface = qobject_cast<QWaylandQuickSurface *>(surfaceItem->surface()); - if (surface && surface->useTextureAlpha()) { + if (surface && surface->useTextureAlpha() && !surface->isOpaque()) { opt |= QQuickWindow::TextureHasAlphaChannel; } auto texture = buffer.toOpenGLTexture(); - m_sgTex = surfaceItem->window()->createTextureFromId(texture->textureId() , QSize(surfaceItem->width(), surfaceItem->height()), opt); + GLuint textureId = texture->textureId(); + auto size = surface->bufferSize(); + m_sgTex = QNativeInterface::QSGOpenGLTexture::fromNative(textureId, surfaceItem->window(), size, opt); +#else + qCWarning(qLcWaylandCompositor) << "Without OpenGL support only shared memory textures are supported"; +#endif } } emit textureChanged(); @@ -317,6 +425,7 @@ private: /*! * \qmltype WaylandQuickItem + * \instantiates QWaylandQuickItem * \inqmlmodule QtWayland.Compositor * \since 5.8 * \brief Provides a Qt Quick item that represents a WaylandView. @@ -341,9 +450,8 @@ private: * Constructs a QWaylandQuickItem with the given \a parent. */ QWaylandQuickItem::QWaylandQuickItem(QQuickItem *parent) - : QQuickItem(*new QWaylandQuickItemPrivate(), parent) + : QWaylandQuickItem(*new QWaylandQuickItemPrivate(), parent) { - d_func()->init(); } /*! @@ -353,6 +461,7 @@ QWaylandQuickItem::QWaylandQuickItem(QWaylandQuickItemPrivate &dd, QQuickItem *p : QQuickItem(dd, parent) { d_func()->init(); + connect(this, &QQuickItem::activeFocusChanged, this, &QWaylandQuickItem::updateFocus); } /*! @@ -362,13 +471,16 @@ QWaylandQuickItem::~QWaylandQuickItem() { Q_D(QWaylandQuickItem); disconnect(this, &QQuickItem::windowChanged, this, &QWaylandQuickItem::updateWindow); + disconnect(this, &QQuickItem::activeFocusChanged, this, &QWaylandQuickItem::updateFocus); QMutexLocker locker(d->mutex); - if (d->provider) + if (d->provider) { + disconnect(d->texProviderConnection); d->provider->deleteLater(); + } } /*! - * \qmlproperty WaylandCompositor QtWaylandCompositor::WaylandQuickItem::compositor + * \qmlproperty WaylandCompositor QtWayland.Compositor::WaylandQuickItem::compositor * * This property holds the compositor for the surface rendered by this WaylandQuickItem. */ @@ -394,7 +506,7 @@ QWaylandView *QWaylandQuickItem::view() const } /*! - * \qmlproperty WaylandSurface QtWaylandCompositor::WaylandQuickItem::surface + * \qmlproperty WaylandSurface QtWayland.Compositor::WaylandQuickItem::surface * * This property holds the surface rendered by this WaylandQuickItem. */ @@ -414,12 +526,21 @@ QWaylandSurface *QWaylandQuickItem::surface() const void QWaylandQuickItem::setSurface(QWaylandSurface *surface) { Q_D(QWaylandQuickItem); + QWaylandSurface *oldSurf = d->view->surface(); + QWaylandCompositor *oldComp = d->view->surface() ? d->view->surface()->compositor() : nullptr; d->view->setSurface(surface); + QWaylandCompositor *newComp = d->view->surface() ? d->view->surface()->compositor() : nullptr; + if (oldComp != newComp) + emit compositorChanged(); + if (oldSurf != surface) + emit surfaceChanged(); + + updateFocus(); update(); } /*! - * \qmlproperty enum QtWaylandCompositor::WaylandQuickItem::origin + * \qmlproperty enum QtWayland.Compositor::WaylandQuickItem::origin * * This property holds the origin of the QWaylandQuickItem. */ @@ -465,7 +586,7 @@ void QWaylandQuickItem::mousePressEvent(QMouseEvent *event) return; } - if (!inputRegionContains(event->pos())) { + if (!inputRegionContains(event->position())) { event->ignore(); return; } @@ -475,9 +596,9 @@ void QWaylandQuickItem::mousePressEvent(QMouseEvent *event) if (d->focusOnClick) takeFocus(seat); - seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->localPos()), event->windowPos()); + seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->position()), event->scenePosition()); seat->sendMousePressEvent(event->button()); - d->hoverPos = event->pos(); + d->hoverPos = event->position(); } /*! @@ -492,21 +613,21 @@ void QWaylandQuickItem::mouseMoveEvent(QMouseEvent *event) if (d->isDragging) { QWaylandQuickOutput *currentOutput = qobject_cast<QWaylandQuickOutput *>(view()->output()); //TODO: also check if dragging onto other outputs - QWaylandQuickItem *targetItem = qobject_cast<QWaylandQuickItem *>(currentOutput->pickClickableItem(mapToScene(event->localPos()))); + QWaylandQuickItem *targetItem = qobject_cast<QWaylandQuickItem *>(currentOutput->pickClickableItem(mapToScene(event->position()))); QWaylandSurface *targetSurface = targetItem ? targetItem->surface() : nullptr; if (targetSurface) { - QPointF position = mapToItem(targetItem, event->localPos()); + QPointF position = mapToItem(targetItem, event->position()); QPointF surfacePosition = targetItem->mapToSurface(position); seat->drag()->dragMove(targetSurface, surfacePosition); } } else #endif // QT_CONFIG(draganddrop) { - seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->localPos()), event->windowPos()); - d->hoverPos = event->pos(); + seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->position()), event->scenePosition()); + d->hoverPos = event->position(); } } else { - emit mouseMove(event->windowPos()); + emit mouseMove(event->scenePosition()); event->ignore(); } } @@ -540,14 +661,14 @@ void QWaylandQuickItem::mouseReleaseEvent(QMouseEvent *event) void QWaylandQuickItem::hoverEnterEvent(QHoverEvent *event) { Q_D(QWaylandQuickItem); - if (!inputRegionContains(event->pos())) { + if (!inputRegionContains(event->position())) { event->ignore(); return; } if (d->shouldSendInputEvents()) { QWaylandSeat *seat = compositor()->seatFor(event); - seat->sendMouseMoveEvent(d->view.data(), event->pos(), mapToScene(event->pos())); - d->hoverPos = event->pos(); + seat->sendMouseMoveEvent(d->view.data(), event->position(), mapToScene(event->position())); + d->hoverPos = event->position(); } else { event->ignore(); } @@ -560,16 +681,16 @@ void QWaylandQuickItem::hoverMoveEvent(QHoverEvent *event) { Q_D(QWaylandQuickItem); if (surface()) { - if (!inputRegionContains(event->pos())) { + if (!inputRegionContains(event->position())) { event->ignore(); return; } } if (d->shouldSendInputEvents()) { QWaylandSeat *seat = compositor()->seatFor(event); - if (event->pos() != d->hoverPos) { - seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->pos()), mapToScene(event->pos())); - d->hoverPos = event->pos(); + if (event->position() != d->hoverPos) { + seat->sendMouseMoveEvent(d->view.data(), mapToSurface(event->position()), mapToScene(event->position())); + d->hoverPos = event->position(); } } else { event->ignore(); @@ -598,13 +719,17 @@ void QWaylandQuickItem::wheelEvent(QWheelEvent *event) { Q_D(QWaylandQuickItem); if (d->shouldSendInputEvents()) { - if (!inputRegionContains(event->pos())) { + if (!inputRegionContains(event->position())) { event->ignore(); return; } QWaylandSeat *seat = compositor()->seatFor(event); - seat->sendMouseWheelEvent(event->orientation(), event->delta()); + // TODO: fix this to send a single event, when diagonal scrolling is supported + if (event->angleDelta().x() != 0) + seat->sendMouseWheelEvent(Qt::Horizontal, event->angleDelta().x()); + if (event->angleDelta().y() != 0) + seat->sendMouseWheelEvent(Qt::Vertical, event->angleDelta().y()); } else { event->ignore(); } @@ -634,7 +759,7 @@ void QWaylandQuickItem::keyPressEvent(QKeyEvent *event) void QWaylandQuickItem::keyReleaseEvent(QKeyEvent *event) { Q_D(QWaylandQuickItem); - if (d->shouldSendInputEvents() && hasFocus()) { + if (d->shouldSendInputEvents()) { QWaylandSeat *seat = compositor()->seatFor(event); seat->sendFullKeyEvent(event); } else { @@ -651,10 +776,10 @@ void QWaylandQuickItem::touchEvent(QTouchEvent *event) if (d->shouldSendInputEvents() && d->touchEventsEnabled) { QWaylandSeat *seat = compositor()->seatFor(event); - QPoint pointPos; - const QList<QTouchEvent::TouchPoint> &points = event->touchPoints(); + QPointF pointPos; + const QList<QTouchEvent::TouchPoint> &points = event->points(); if (!points.isEmpty()) - pointPos = points.at(0).pos().toPoint(); + pointPos = points.at(0).position(); if (event->type() == QEvent::TouchBegin && !inputRegionContains(pointPos)) { event->ignore(); @@ -723,10 +848,16 @@ void QWaylandQuickItem::handleSubsurfaceAdded(QWaylandSurface *childSurface) childItem->setSurface(childSurface); childItem->setVisible(true); childItem->setParentItem(this); + childItem->setParent(this); connect(childSurface, &QWaylandSurface::subsurfacePositionChanged, childItem, &QWaylandQuickItem::handleSubsurfacePosition); + connect(childSurface, &QWaylandSurface::destroyed, childItem, &QObject::deleteLater); } else { bool success = QMetaObject::invokeMethod(d->subsurfaceHandler, "handleSubsurfaceAdded", Q_ARG(QWaylandSurface *, childSurface)); if (!success) + success = QMetaObject::invokeMethod(d->subsurfaceHandler, "handleSubsurfaceAdded", + Q_ARG(QVariant, QVariant::fromValue(childSurface))); + + if (!success) qWarning("QWaylandQuickItem: subsurfaceHandler does not implement handleSubsurfaceAdded()"); } } @@ -765,8 +896,15 @@ void QWaylandQuickItem::handlePlaceBelow(QWaylandSurface *referenceSurface) } } +void QWaylandQuickItem::updateFocus() +{ + Q_D(const QWaylandQuickItem); + if (hasActiveFocus() && compositor()) + compositor()->defaultSeat()->setKeyboardFocus(d->view->surface()); +} + /*! - \qmlproperty object QtWaylandCompositor::WaylandQuickItem::subsurfaceHandler + \qmlproperty object QtWayland.Compositor::WaylandQuickItem::subsurfaceHandler This property provides a way to override the default subsurface behavior. @@ -778,8 +916,9 @@ void QWaylandQuickItem::handlePlaceBelow(QWaylandSurface *referenceSurface) \code ShellSurfaceItem { subsurfaceHandler: QtObject { - function handleSubsurfaceAdded(child) { - //create custom surface item, and connect the subsurfacePositionChanged signal + function handleSubsurfaceAdded(child) { + // create custom surface item, and connect the subsurfacePositionChanged signal + } } } \endcode @@ -804,6 +943,11 @@ void QWaylandQuickItem::setSubsurfaceHandler(QObject *handler) } /*! + * \qmlproperty WaylandOutput QtWayland.Compositor::WaylandQuickItem::output + * + * This property holds the output on which this item is displayed. + */ +/*! * \property QWaylandQuickItem::output * * This property holds the output on which this item is displayed. @@ -821,7 +965,15 @@ void QWaylandQuickItem::setOutput(QWaylandOutput *output) } /*! - * \property QWaylandQuickItem::isBufferLocked + * \qmlproperty bool QtWayland.Compositor::WaylandQuickItem::bufferLocked + * + * This property holds whether the item's buffer is currently locked. As long as + * the buffer is locked, it will not be released and returned to the client. + * + * The default is false. + */ +/*! + * \property QWaylandQuickItem::bufferLocked * * This property holds whether the item's buffer is currently locked. As long as * the buffer is locked, it will not be released and returned to the client. @@ -838,6 +990,10 @@ void QWaylandQuickItem::setBufferLocked(bool locked) { Q_D(QWaylandQuickItem); d->view->setBufferLocked(locked); + + // Apply the latest surface size + if (!locked) + updateSize(); } /*! @@ -886,7 +1042,7 @@ void QWaylandQuickItem::handleSurfaceChanged() if (d->oldSurface) { disconnect(d->oldSurface.data(), &QWaylandSurface::hasContentChanged, this, &QWaylandQuickItem::surfaceMappedChanged); disconnect(d->oldSurface.data(), &QWaylandSurface::parentChanged, this, &QWaylandQuickItem::parentChanged); - disconnect(d->oldSurface.data(), &QWaylandSurface::sizeChanged, this, &QWaylandQuickItem::updateSize); + disconnect(d->oldSurface.data(), &QWaylandSurface::destinationSizeChanged, this, &QWaylandQuickItem::updateSize); disconnect(d->oldSurface.data(), &QWaylandSurface::bufferScaleChanged, this, &QWaylandQuickItem::updateSize); disconnect(d->oldSurface.data(), &QWaylandSurface::configure, this, &QWaylandQuickItem::updateBuffer); disconnect(d->oldSurface.data(), &QWaylandSurface::redraw, this, &QQuickItem::update); @@ -903,7 +1059,7 @@ void QWaylandQuickItem::handleSurfaceChanged() if (QWaylandSurface *newSurface = d->view->surface()) { connect(newSurface, &QWaylandSurface::hasContentChanged, this, &QWaylandQuickItem::surfaceMappedChanged); connect(newSurface, &QWaylandSurface::parentChanged, this, &QWaylandQuickItem::parentChanged); - connect(newSurface, &QWaylandSurface::sizeChanged, this, &QWaylandQuickItem::updateSize); + connect(newSurface, &QWaylandSurface::destinationSizeChanged, this, &QWaylandQuickItem::updateSize); connect(newSurface, &QWaylandSurface::bufferScaleChanged, this, &QWaylandQuickItem::updateSize); connect(newSurface, &QWaylandSurface::configure, this, &QWaylandQuickItem::updateBuffer); connect(newSurface, &QWaylandSurface::redraw, this, &QQuickItem::update); @@ -947,7 +1103,7 @@ void QWaylandQuickItem::takeFocus(QWaylandSeat *device) { forceActiveFocus(); - if (!surface()) + if (!surface() || !surface()->client()) return; QWaylandSeat *target = device; @@ -955,9 +1111,27 @@ void QWaylandQuickItem::takeFocus(QWaylandSeat *device) target = compositor()->defaultSeat(); } target->setKeyboardFocus(surface()); - QWaylandTextInput *textInput = QWaylandTextInput::findIn(target); - if (textInput) - textInput->setFocus(surface()); + + qCDebug(qLcWaylandCompositorInputMethods) << Q_FUNC_INFO << " surface:" << surface() + << ", client:" << surface()->client() + << ", textinputprotocol:" << (int)(surface()->client()->textInputProtocols()); + if (surface()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) { + QWaylandTextInput *textInput = QWaylandTextInput::findIn(target); + if (textInput) + textInput->setFocus(surface()); + } + + if (surface()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV3)) { + QWaylandTextInputV3 *textInputV3 = QWaylandTextInputV3::findIn(target); + if (textInputV3) + textInputV3->setFocus(surface()); + } + + if (surface()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) { + QWaylandQtTextInputMethod *textInputMethod = QWaylandQtTextInputMethod::findIn(target); + if (textInputMethod) + textInputMethod->setFocus(surface()); + } } /*! @@ -990,17 +1164,21 @@ void QWaylandQuickItem::updateSize() { Q_D(QWaylandQuickItem); + // No resize if buffer is locked + if (isBufferLocked()) { + qWarning() << "No update on item size as the buffer is currently locked"; + return; + } + QSize size(0, 0); if (surface()) - size = surface()->size() * (d->scaleFactor() / surface()->bufferScale()); + size = surface()->destinationSize() * d->scaleFactor(); setImplicitSize(size.width(), size.height()); - if (d->sizeFollowsSurface) - setSize(size); } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandQuickItem::focusOnClick + * \qmlproperty bool QtWayland.Compositor::WaylandQuickItem::focusOnClick * * This property specifies whether the WaylandQuickItem should take focus when * it is clicked or touched. @@ -1039,19 +1217,17 @@ void QWaylandQuickItem::setFocusOnClick(bool focus) bool QWaylandQuickItem::inputRegionContains(const QPointF &localPosition) const { if (QWaylandSurface *s = surface()) - return s->inputRegionContains(mapToSurface(localPosition).toPoint()); + return s->inputRegionContains(mapToSurface(localPosition)); return false; } -// Qt 6: Remove the non-const version /*! - * Returns \c true if the input region of this item's surface contains the - * position given by \a localPosition. + * \qmlmethod point WaylandQuickItem::mapToSurface(point point) + * + * Maps the given \a point in this item's coordinate system to the equivalent + * point within the Wayland surface's coordinate system, and returns the mapped + * coordinate. */ -bool QWaylandQuickItem::inputRegionContains(const QPointF &localPosition) -{ - return const_cast<const QWaylandQuickItem *>(this)->inputRegionContains(localPosition); -} /*! * Maps the given \a point in this item's coordinate system to the equivalent @@ -1061,48 +1237,39 @@ bool QWaylandQuickItem::inputRegionContains(const QPointF &localPosition) QPointF QWaylandQuickItem::mapToSurface(const QPointF &point) const { Q_D(const QWaylandQuickItem); - if (!surface() || surface()->size().isEmpty()) + if (!surface() || surface()->destinationSize().isEmpty()) return point / d->scaleFactor(); - qreal xScale = width() / surface()->size().width() * surface()->bufferScale(); - qreal yScale = height() / surface()->size().height() * surface()->bufferScale(); + qreal xScale = width() / surface()->destinationSize().width(); + qreal yScale = height() / surface()->destinationSize().height(); return QPointF(point.x() / xScale, point.y() / yScale); } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandQuickItem::sizeFollowsSurface - * - * This property specifies whether the size of the item should always match - * the size of its surface. + * \qmlmethod point WaylandQuickItem::mapFromSurface(point point) + * \since 5.13 * - * The default is \c true. + * Maps the given \a point in the Wayland surfaces's coordinate system to the equivalent + * point within this item's coordinate system, and returns the mapped coordinate. */ /*! - * \property QWaylandQuickItem::sizeFollowsSurface - * - * This property specifies whether the size of the item should always match - * the size of its surface. + * Maps the given \a point in the Wayland surfaces's coordinate system to the equivalent + * point within this item's coordinate system, and returns the mapped coordinate. * - * The default is \c true. + * \since 5.13 */ -bool QWaylandQuickItem::sizeFollowsSurface() const +QPointF QWaylandQuickItem::mapFromSurface(const QPointF &point) const { Q_D(const QWaylandQuickItem); - return d->sizeFollowsSurface; -} + if (!surface() || surface()->destinationSize().isEmpty()) + return point * d->scaleFactor(); -//TODO: sizeFollowsSurface became obsolete when we added an implementation for -//implicit size. The property is here for compatibility reasons only and should -//be removed or at least default to false in Qt 6. -void QWaylandQuickItem::setSizeFollowsSurface(bool sizeFollowsSurface) -{ - Q_D(QWaylandQuickItem); - if (d->sizeFollowsSurface == sizeFollowsSurface) - return; - d->sizeFollowsSurface = sizeFollowsSurface; - emit sizeFollowsSurfaceChanged(); + qreal xScale = width() / surface()->destinationSize().width(); + qreal yScale = height() / surface()->destinationSize().height(); + + return QPointF(point.x() * xScale, point.y() * yScale); } #if QT_CONFIG(im) @@ -1126,7 +1293,7 @@ QVariant QWaylandQuickItem::inputMethodQuery(Qt::InputMethodQuery query, QVarian #endif /*! - \qmlproperty bool QtWaylandCompositor::WaylandQuickItem::paintEnabled + \qmlproperty bool QtWayland.Compositor::WaylandQuickItem::paintEnabled Returns true if the item is hidden, though the texture is still updated. As opposed to hiding the item by @@ -1135,12 +1302,14 @@ QVariant QWaylandQuickItem::inputMethodQuery(Qt::InputMethodQuery query, QVarian */ /*! - Returns true if the item is hidden, though the texture + \property QWaylandQuickItem::paintEnabled + + Holds \c true if the item is hidden, though the texture is still updated. As opposed to hiding the item by - setting \l{Item::visible}{visible} to \c false, setting this property to \c false + setting \l{QQuickItem::}{visible} to \c false, setting this property to \c false will not prevent mouse or keyboard input from reaching item. */ -bool QWaylandQuickItem::paintEnabled() const +bool QWaylandQuickItem::isPaintEnabled() const { Q_D(const QWaylandQuickItem); return d->paintEnabled; @@ -1149,10 +1318,28 @@ bool QWaylandQuickItem::paintEnabled() const void QWaylandQuickItem::setPaintEnabled(bool enabled) { Q_D(QWaylandQuickItem); - d->paintEnabled = enabled; + + if (enabled != d->paintEnabled) { + d->paintEnabled = enabled; + emit paintEnabledChanged(); + } + update(); } +/*! + \qmlproperty bool QtWayland.Compositor::WaylandQuickItem::touchEventsEnabled + + This property holds \c true if touch events are forwarded to the client + surface, \c false otherwise. +*/ + +/*! + \property QWaylandQuickItem::touchEventsEnabled + + This property holds \c true if touch events are forwarded to the client + surface, \c false otherwise. +*/ bool QWaylandQuickItem::touchEventsEnabled() const { Q_D(const QWaylandQuickItem); @@ -1187,15 +1374,15 @@ void QWaylandQuickItem::updateWindow() if (d->connectedWindow) { connect(d->connectedWindow, &QQuickWindow::beforeSynchronizing, this, &QWaylandQuickItem::beforeSync, Qt::DirectConnection); connect(d->connectedWindow, &QQuickWindow::screenChanged, this, &QWaylandQuickItem::updateSize); // new screen may have new dpr - } - if (compositor() && d->connectedWindow) { - QWaylandOutput *output = compositor()->outputFor(d->connectedWindow); - Q_ASSERT(output); - d->view->setOutput(output); - } + if (compositor()) { + QWaylandOutput *output = compositor()->outputFor(d->connectedWindow); + Q_ASSERT(output); + d->view->setOutput(output); + } - updateSize(); // because scaleFactor depends on devicePixelRatio, which may be different for the new window + updateSize(); // because scaleFactor depends on devicePixelRatio, which may be different for the new window + } } void QWaylandQuickItem::updateOutput() @@ -1236,7 +1423,7 @@ void QWaylandQuickItem::updateInputMethod(Qt::InputMethodQueries queries) #endif /*! - * \qmlsignal void QtWaylandCompositor::WaylandQuickItem::surfaceDestroyed() + * \qmlsignal void QtWayland.Compositor::WaylandQuickItem::surfaceDestroyed() * * This signal is emitted when the client has destroyed the \c wl_surface associated * with the WaylandQuickItem. The handler for this signal is expected to either destroy the @@ -1245,7 +1432,7 @@ void QWaylandQuickItem::updateInputMethod(Qt::InputMethodQueries queries) * If an animation is started, bufferLocked should be set to ensure the item keeps its content * until the animation finishes * - * \sa isBufferLocked + * \sa bufferLocked */ /*! @@ -1258,7 +1445,7 @@ void QWaylandQuickItem::updateInputMethod(Qt::InputMethodQueries queries) * If an animation is started, bufferLocked should be set to ensure the item keeps its content * until the animation finishes * - * \sa QWaylandQuickkItem::bufferLocked + * \sa QWaylandQuickItem::bufferLocked */ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) @@ -1267,10 +1454,10 @@ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat d->lastMatrix = data->transformNode->combinedMatrix(); const bool bufferHasContent = d->view->currentBuffer().hasContent(); - if (d->view->isBufferLocked() && !bufferHasContent && d->paintEnabled) + if (d->view->isBufferLocked() && d->paintEnabled) return oldNode; - if (!bufferHasContent || !d->paintEnabled) { + if (!bufferHasContent || !d->paintEnabled || !surface()) { delete oldNode; return nullptr; } @@ -1280,17 +1467,47 @@ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat const QRectF rect = invertY ? QRectF(0, height(), width(), -height()) : QRectF(0, 0, width(), height()); - if (ref.isSharedMemory() || bufferTypes[ref.bufferFormatEgl()].canProvideTexture) { + if (ref.isSharedMemory() +#if QT_CONFIG(opengl) + || bufferTypes[ref.bufferFormatEgl()].canProvideTexture +#endif + ) { +#if QT_CONFIG(opengl) + if (oldNode && !d->paintByProvider) { + // Need to re-create a node + delete oldNode; + oldNode = nullptr; + } + d->paintByProvider = true; +#endif // This case could covered by the more general path below, but this is more efficient (especially when using ShaderEffect items). QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode); if (!node) { node = new QSGSimpleTextureNode(); + if (smooth()) + node->setFiltering(QSGTexture::Linear); d->newTexture = true; } - if (!d->provider) + if (!d->provider) { d->provider = new QWaylandSurfaceTextureProvider(); + if (compositor()) { + d->texProviderConnection = + QObject::connect( + compositor(), + &QObject::destroyed, + this, + [this](QObject*) { + auto *itemPriv = QWaylandQuickItemPrivate::get(this); + if (itemPriv->provider) { + itemPriv->provider->deleteLater(); + itemPriv->provider = nullptr; + } + disconnect(itemPriv->texProviderConnection); } + ); + } + } if (d->newTexture) { d->newTexture = false; @@ -1301,46 +1518,67 @@ QSGNode *QWaylandQuickItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDat d->provider->setSmooth(smooth()); node->setRect(rect); + qreal scale = surface()->bufferScale(); + QRectF source = surface()->sourceGeometry(); + node->setSourceRect(QRectF(source.topLeft() * scale, source.size() * scale)); + return node; - } else { - Q_ASSERT(!d->provider); + } - QSGGeometryNode *node = static_cast<QSGGeometryNode *>(oldNode); +#if QT_CONFIG(opengl) + Q_ASSERT(!d->provider); - if (!node) { - node = new QSGGeometryNode; - d->newTexture = true; - } + if (oldNode && d->paintByProvider) { + // Need to re-create a node + delete oldNode; + oldNode = nullptr; + } + d->paintByProvider = false; - QSGGeometry *geometry = node->geometry(); - QWaylandBufferMaterial *material = static_cast<QWaylandBufferMaterial *>(node->material()); + QSGGeometryNode *node = static_cast<QSGGeometryNode *>(oldNode); - if (!geometry) - geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4); + if (!node) { + node = new QSGGeometryNode; + d->newTexture = true; + } - if (!material) - material = new QWaylandBufferMaterial(ref.bufferFormatEgl()); + QSGGeometry *geometry = node->geometry(); + QWaylandBufferMaterial *material = static_cast<QWaylandBufferMaterial *>(node->material()); - if (d->newTexture) { - d->newTexture = false; - for (int plane = 0; plane < bufferTypes[ref.bufferFormatEgl()].planeCount; plane++) - if (auto texture = ref.toOpenGLTexture(plane)) - material->setTextureForPlane(plane, texture); - material->bind(); - } + if (!geometry) + geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4); - QSGGeometry::updateTexturedRectGeometry(geometry, rect, QRectF(0, 0, 1, 1)); + if (!material) + material = new QWaylandBufferMaterial(ref.bufferFormatEgl()); - node->setGeometry(geometry); - node->setFlag(QSGNode::OwnsGeometry, true); + if (d->newTexture) { + d->newTexture = false; + material->setBufferRef(this, ref); + } - node->setMaterial(material); - node->setFlag(QSGNode::OwnsMaterial, true); + const QSize surfaceSize = ref.size() / surface()->bufferScale(); + const QRectF sourceGeometry = surface()->sourceGeometry(); + const QRectF normalizedCoordinates = + sourceGeometry.isValid() + ? QRectF(sourceGeometry.x() / surfaceSize.width(), + sourceGeometry.y() / surfaceSize.height(), + sourceGeometry.width() / surfaceSize.width(), + sourceGeometry.height() / surfaceSize.height()) + : QRectF(0, 0, 1, 1); - return node; - } + QSGGeometry::updateTexturedRectGeometry(geometry, rect, normalizedCoordinates); + + node->setGeometry(geometry); + node->setFlag(QSGNode::OwnsGeometry, true); + + node->setMaterial(material); + node->setFlag(QSGNode::OwnsMaterial, true); - Q_UNREACHABLE(); + return node; +#else + qCWarning(qLcWaylandCompositor) << "Without OpenGL support only shared memory textures are supported"; + return nullptr; +#endif // QT_CONFIG(opengl) } void QWaylandQuickItem::setTouchEventsEnabled(bool enabled) @@ -1371,20 +1609,34 @@ void QWaylandQuickItem::setInputEventsEnabled(bool enabled) void QWaylandQuickItem::lower() { - QQuickItem *parent = parentItem(); + Q_D(QWaylandQuickItem); + d->lower(); +} + +void QWaylandQuickItemPrivate::lower() +{ + Q_Q(QWaylandQuickItem); + QQuickItem *parent = q->parentItem(); Q_ASSERT(parent); - QQuickItem *bottom = parent->childItems().first(); - if (this != bottom) - stackBefore(bottom); + QQuickItem *bottom = parent->childItems().constFirst(); + if (q != bottom) + q->stackBefore(bottom); } void QWaylandQuickItem::raise() { - QQuickItem *parent = parentItem(); + Q_D(QWaylandQuickItem); + d->raise(); +} + +void QWaylandQuickItemPrivate::raise() +{ + Q_Q(QWaylandQuickItem); + QQuickItem *parent = q->parentItem(); Q_ASSERT(parent); - QQuickItem *top = parent->childItems().last(); - if (this != top) - stackAfter(top); + QQuickItem *top = parent->childItems().constLast(); + if (q != top) + q->stackAfter(top); } void QWaylandQuickItem::sendMouseMoveEvent(const QPointF &position, QWaylandSeat *seat) @@ -1514,3 +1766,5 @@ void QWaylandQuickItemPrivate::placeBelowParent() } QT_END_NAMESPACE + +#include "moc_qwaylandquickitem.cpp" diff --git a/src/compositor/compositor_api/qwaylandquickitem.h b/src/compositor/compositor_api/qwaylandquickitem.h index 23708353e..d30528a8a 100644 --- a/src/compositor/compositor_api/qwaylandquickitem.h +++ b/src/compositor/compositor_api/qwaylandquickitem.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACEITEM_H #define QWAYLANDSURFACEITEM_H @@ -52,27 +16,33 @@ Q_DECLARE_METATYPE(QWaylandQuickSurface*) +QT_REQUIRE_CONFIG(wayland_compositor_quick); + QT_BEGIN_NAMESPACE class QWaylandSeat; class QWaylandQuickItemPrivate; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickItem : public QQuickItem +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickItem : public QQuickItem { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandQuickItem) - Q_PROPERTY(QWaylandCompositor *compositor READ compositor) + Q_PROPERTY(QWaylandCompositor *compositor READ compositor NOTIFY compositorChanged) Q_PROPERTY(QWaylandSurface *surface READ surface WRITE setSurface NOTIFY surfaceChanged) - Q_PROPERTY(bool paintEnabled READ paintEnabled WRITE setPaintEnabled) + Q_PROPERTY(bool paintEnabled READ isPaintEnabled WRITE setPaintEnabled NOTIFY paintEnabledChanged) Q_PROPERTY(bool touchEventsEnabled READ touchEventsEnabled WRITE setTouchEventsEnabled NOTIFY touchEventsEnabledChanged) Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged) Q_PROPERTY(bool inputEventsEnabled READ inputEventsEnabled WRITE setInputEventsEnabled NOTIFY inputEventsEnabledChanged) Q_PROPERTY(bool focusOnClick READ focusOnClick WRITE setFocusOnClick NOTIFY focusOnClickChanged) - Q_PROPERTY(bool sizeFollowsSurface READ sizeFollowsSurface WRITE setSizeFollowsSurface NOTIFY sizeFollowsSurfaceChanged) Q_PROPERTY(QObject *subsurfaceHandler READ subsurfaceHandler WRITE setSubsurfaceHandler NOTIFY subsurfaceHandlerChanged) Q_PROPERTY(QWaylandOutput *output READ output WRITE setOutput NOTIFY outputChanged) Q_PROPERTY(bool bufferLocked READ isBufferLocked WRITE setBufferLocked NOTIFY bufferLockedChanged) Q_PROPERTY(bool allowDiscardFrontBuffer READ allowDiscardFrontBuffer WRITE setAllowDiscardFrontBuffer NOTIFY allowDiscardFrontBufferChanged) + Q_MOC_INCLUDE("qwaylandcompositor.h") + Q_MOC_INCLUDE("qwaylandseat.h") + Q_MOC_INCLUDE("qwaylanddrag.h") + QML_NAMED_ELEMENT(WaylandQuickItem) + QML_ADDED_IN_VERSION(1, 0) public: QWaylandQuickItem(QQuickItem *parent = nullptr); ~QWaylandQuickItem() override; @@ -88,7 +58,7 @@ public: bool isTextureProvider() const override; QSGTextureProvider *textureProvider() const override; - bool paintEnabled() const; + bool isPaintEnabled() const; bool touchEventsEnabled() const; void setTouchEventsEnabled(bool enabled); @@ -100,11 +70,8 @@ public: void setFocusOnClick(bool focus); bool inputRegionContains(const QPointF &localPosition) const; - bool inputRegionContains(const QPointF &localPosition); Q_INVOKABLE QPointF mapToSurface(const QPointF &point) const; - - bool sizeFollowsSurface() const; - void setSizeFollowsSurface(bool sizeFollowsSurface); + Q_REVISION(1, 13) Q_INVOKABLE QPointF mapFromSurface(const QPointF &point) const; #if QT_CONFIG(im) QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; @@ -173,9 +140,12 @@ private Q_SLOTS: #if QT_CONFIG(im) void updateInputMethod(Qt::InputMethodQueries queries); #endif + void updateFocus(); Q_SIGNALS: void surfaceChanged(); + void compositorChanged(); + void paintEnabledChanged(); void touchEventsEnabledChanged(); void originChanged(); void surfaceDestroyed(); @@ -183,7 +153,6 @@ Q_SIGNALS: void focusOnClickChanged(); void mouseMove(const QPointF &windowPosition); void mouseRelease(); - void sizeFollowsSurfaceChanged(); void subsurfaceHandlerChanged(); void outputChanged(); void bufferLockedChanged(); diff --git a/src/compositor/compositor_api/qwaylandquickitem_p.h b/src/compositor/compositor_api/qwaylandquickitem_p.h index 3d710d71b..0ddabc7da 100644 --- a/src/compositor/compositor_api/qwaylandquickitem_p.h +++ b/src/compositor/compositor_api/qwaylandquickitem_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDQUICKITEM_P_H #define QWAYLANDQUICKITEM_P_H @@ -58,28 +22,25 @@ #include <QtWaylandCompositor/QWaylandQuickItem> #include <QtWaylandCompositor/QWaylandOutput> +#include <QtCore/qpointer.h> + QT_BEGIN_NAMESPACE class QWaylandSurfaceTextureProvider; class QMutex; class QOpenGLTexture; +#if QT_CONFIG(opengl) class QWaylandBufferMaterialShader : public QSGMaterialShader { public: QWaylandBufferMaterialShader(QWaylandBufferRef::BufferFormatEgl format); - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -protected: - void initialize() override; - -private: - const QWaylandBufferRef::BufferFormatEgl m_format; - int m_id_matrix; - int m_id_opacity; - QVarLengthArray<int, 3> m_id_tex; + bool updateUniformData(RenderState &state, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; + void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; + void setupExternalOESShader(const QString &shaderFilename); }; class QWaylandBufferMaterial : public QSGMaterial @@ -88,20 +49,27 @@ public: QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format); ~QWaylandBufferMaterial() override; - void setTextureForPlane(int plane, QOpenGLTexture *texture); + void setTextureForPlane(int plane, QOpenGLTexture *texture, QSGTexture *scenegraphTexture); + void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref); void bind(); + void updateScenegraphTextures(QRhi *rhi); QSGMaterialType *type() const override; - QSGMaterialShader *createShader() const override; + QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; private: + friend QWaylandBufferMaterialShader; + void setTextureParameters(GLenum target); void ensureTextures(int count); const QWaylandBufferRef::BufferFormatEgl m_format; QVarLengthArray<QOpenGLTexture*, 3> m_textures; + QVarLengthArray<QSGTexture*, 3> m_scenegraphTextures; + QWaylandBufferRef m_bufferRef; }; +#endif // QT_CONFIG(opengl) class QWaylandQuickItemPrivate : public QQuickItemPrivate { @@ -145,6 +113,7 @@ public: Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 | Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 | Qt::ExtraButton12 | Qt::ExtraButton13) : Qt::NoButton); + q->setAcceptTouchEvents(enable); q->setAcceptHoverEvents(enable); inputEventsEnabled = enable; } @@ -158,27 +127,33 @@ public: void placeAboveParent(); void placeBelowParent(); + virtual void raise(); + virtual void lower(); + static QMutex *mutex; QScopedPointer<QWaylandView> view; QPointer<QWaylandSurface> oldSurface; mutable QWaylandSurfaceTextureProvider *provider = nullptr; + QMetaObject::Connection texProviderConnection; bool paintEnabled = true; bool touchEventsEnabled = true; bool inputEventsEnabled = true; bool isDragging = false; bool newTexture = false; bool focusOnClick = true; - bool sizeFollowsSurface = true; bool belowParent = false; - QPoint hoverPos; +#if QT_CONFIG(opengl) + bool paintByProvider = false; +#endif + QPointF hoverPos; QMatrix4x4 lastMatrix; QQuickWindow *connectedWindow = nullptr; QWaylandOutput *connectedOutput = nullptr; QWaylandSurface::Origin origin = QWaylandSurface::OriginTopLeft; QPointer<QObject> subsurfaceHandler; - QVector<QWaylandSeat *> touchingSeats; + QList<QWaylandSeat *> touchingSeats; }; QT_END_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandquickoutput.cpp b/src/compositor/compositor_api/qwaylandquickoutput.cpp index c6294eead..de6c3ede4 100644 --- a/src/compositor/compositor_api/qwaylandquickoutput.cpp +++ b/src/compositor/compositor_api/qwaylandquickoutput.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandquickoutput.h" #include "qwaylandquickcompositor.h" @@ -96,7 +60,7 @@ void QWaylandQuickOutput::update() } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandOutput::automaticFrameCallback + * \qmlproperty bool QtWayland.Compositor::WaylandOutput::automaticFrameCallback * * This property holds whether the WaylandOutput automatically sends frame * callbacks when rendering. @@ -174,3 +138,5 @@ void QWaylandQuickOutput::doFrameCallbacks() sendFrameCallbacks(); } QT_END_NAMESPACE + +#include "moc_qwaylandquickoutput.cpp" diff --git a/src/compositor/compositor_api/qwaylandquickoutput.h b/src/compositor/compositor_api/qwaylandquickoutput.h index 5f3749b01..c5fde60ff 100644 --- a/src/compositor/compositor_api/qwaylandquickoutput.h +++ b/src/compositor/compositor_api/qwaylandquickoutput.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDQUICKOUTPUT_H #define QWAYLANDQUICKOUTPUT_H @@ -45,17 +9,21 @@ #include <QtWaylandCompositor/qwaylandoutput.h> #include <QtWaylandCompositor/qwaylandquickchildren.h> +QT_REQUIRE_CONFIG(wayland_compositor_quick); + QT_BEGIN_NAMESPACE class QWaylandQuickCompositor; class QQuickWindow; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickOutput : public QWaylandOutput, public QQmlParserStatus +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickOutput : public QWaylandOutput, public QQmlParserStatus { Q_INTERFACES(QQmlParserStatus) Q_OBJECT Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(QWaylandQuickOutput) Q_PROPERTY(bool automaticFrameCallback READ automaticFrameCallback WRITE setAutomaticFrameCallback NOTIFY automaticFrameCallbackChanged) + QML_NAMED_ELEMENT(WaylandOutput) + QML_ADDED_IN_VERSION(1, 0) public: QWaylandQuickOutput(); QWaylandQuickOutput(QWaylandCompositor *compositor, QWindow *window); diff --git a/src/compositor/compositor_api/qwaylandquicksurface.cpp b/src/compositor/compositor_api/qwaylandquicksurface.cpp index 279795e46..920415d68 100644 --- a/src/compositor/compositor_api/qwaylandquicksurface.cpp +++ b/src/compositor/compositor_api/qwaylandquicksurface.cpp @@ -1,48 +1,12 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QSGTexture> -#include <QOpenGLTexture> #include <QQuickWindow> #include <QDebug> #include "qwaylandquicksurface.h" +#include "qwaylandquicksurface_p.h" #include "qwaylandquickcompositor.h" #include "qwaylandquickitem.h" #include <QtWaylandCompositor/qwaylandbufferref.h> @@ -51,22 +15,6 @@ QT_BEGIN_NAMESPACE -class QWaylandQuickSurfacePrivate : public QWaylandSurfacePrivate -{ - Q_DECLARE_PUBLIC(QWaylandQuickSurface) -public: - QWaylandQuickSurfacePrivate() - { - } - - ~QWaylandQuickSurfacePrivate() override - { - } - - bool useTextureAlpha = true; - bool clientRenderingEnabled = true; -}; - QWaylandQuickSurface::QWaylandQuickSurface() : QWaylandSurface(* new QWaylandQuickSurfacePrivate()) { @@ -78,13 +26,18 @@ QWaylandQuickSurface::QWaylandQuickSurface(QWaylandCompositor *compositor, QWayl initialize(compositor, client, id, version); } +QWaylandQuickSurface::QWaylandQuickSurface(QWaylandQuickSurfacePrivate &dptr) + : QWaylandSurface(dptr) +{ +} + QWaylandQuickSurface::~QWaylandQuickSurface() { } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandSurface::useTextureAlpha + * \qmlproperty bool QtWayland.Compositor::WaylandSurface::useTextureAlpha * * This property specifies whether the surface should use texture alpha. */ @@ -104,28 +57,6 @@ void QWaylandQuickSurface::setUseTextureAlpha(bool useTextureAlpha) } } -/*! - * \qmlproperty bool QtWaylandCompositor::WaylandSurface::clientRenderingEnabled - * \deprecated - * - * This property used to specify whether client rendering was enabled for the surface. - * It depended on a Wayland extension that was part of the private API. The surface extension - * is not used anymore, so this property does nothing. - */ -bool QWaylandQuickSurface::clientRenderingEnabled() const -{ - Q_D(const QWaylandQuickSurface); - return d->clientRenderingEnabled; -} - -void QWaylandQuickSurface::setClientRenderingEnabled(bool enabled) -{ - Q_D(QWaylandQuickSurface); - qWarning() << Q_FUNC_INFO << "doesn't do anything"; - if (d->clientRenderingEnabled != enabled) { - d->clientRenderingEnabled = enabled; - emit clientRenderingEnabledChanged(); - } -} - QT_END_NAMESPACE + +#include "moc_qwaylandquicksurface.cpp" diff --git a/src/compositor/compositor_api/qwaylandquicksurface.h b/src/compositor/compositor_api/qwaylandquicksurface.h index 258f1a22f..5ed26cfe2 100644 --- a/src/compositor/compositor_api/qwaylandquicksurface.h +++ b/src/compositor/compositor_api/qwaylandquicksurface.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QQUICKWAYLANDSURFACE_H #define QQUICKWAYLANDSURFACE_H @@ -45,18 +9,21 @@ struct wl_client; +QT_REQUIRE_CONFIG(wayland_compositor_quick); + QT_BEGIN_NAMESPACE class QWaylandQuickSurfacePrivate; class QWaylandQuickCompositor; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandQuickSurface : public QWaylandSurface +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickSurface : public QWaylandSurface { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandQuickSurface) Q_WAYLAND_COMPOSITOR_DECLARE_QUICK_CHILDREN(QWaylandQuickSurface) Q_PROPERTY(bool useTextureAlpha READ useTextureAlpha WRITE setUseTextureAlpha NOTIFY useTextureAlphaChanged) - Q_PROPERTY(bool clientRenderingEnabled READ clientRenderingEnabled WRITE setClientRenderingEnabled NOTIFY clientRenderingEnabledChanged) + QML_NAMED_ELEMENT(WaylandSurface) + QML_ADDED_IN_VERSION(1, 0) public: QWaylandQuickSurface(); QWaylandQuickSurface(QWaylandCompositor *compositor, QWaylandClient *client, quint32 id, int version); @@ -65,12 +32,11 @@ public: bool useTextureAlpha() const; void setUseTextureAlpha(bool useTextureAlpha); - Q_DECL_DEPRECATED bool clientRenderingEnabled() const; - Q_DECL_DEPRECATED void setClientRenderingEnabled(bool enabled); +protected: + QWaylandQuickSurface(QWaylandQuickSurfacePrivate &dptr); Q_SIGNALS: void useTextureAlphaChanged(); - void clientRenderingEnabledChanged(); //deprecated }; QT_END_NAMESPACE diff --git a/src/compositor/compositor_api/qwaylandquicksurface_p.h b/src/compositor/compositor_api/qwaylandquicksurface_p.h new file mode 100644 index 000000000..8426276b0 --- /dev/null +++ b/src/compositor/compositor_api/qwaylandquicksurface_p.h @@ -0,0 +1,40 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#ifndef QWAYLANDQUICKSURFACE_P_H +#define QWAYLANDQUICKSURFACE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtWaylandCompositor/private/qwaylandsurface_p.h> + +QT_BEGIN_NAMESPACE + +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandQuickSurfacePrivate : public QWaylandSurfacePrivate +{ + Q_DECLARE_PUBLIC(QWaylandQuickSurface) +public: + QWaylandQuickSurfacePrivate() + { + } + + ~QWaylandQuickSurfacePrivate() override + { + } + + bool useTextureAlpha = true; + bool clientRenderingEnabled = true; +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDQUICKSURFACE_P_H diff --git a/src/compositor/compositor_api/qwaylandresource.cpp b/src/compositor/compositor_api/qwaylandresource.cpp index f3d010830..fc744c4b6 100644 --- a/src/compositor/compositor_api/qwaylandresource.cpp +++ b/src/compositor/compositor_api/qwaylandresource.cpp @@ -1,53 +1,44 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandresource.h" QT_BEGIN_NAMESPACE +/*! + * \class QWaylandResource + * \inmodule QtWaylandCompositor + * \since 5.8 + * \brief QWaylandResource is a container for a \c wl_resource. + * + * The QWaylandResource is a simple wrapper around the Wayland type \c wl_resource, and makes it + * possible to use wl_resource pointers in Qt Quick APIs. + * + * \sa {Custom Shell} + */ + +/*! + * Constructs an invalid QWaylandResource. The \l{resource()} accessor will return null. + */ QWaylandResource::QWaylandResource() { } +/*! + * Constructs a QWaylandResource which contains \a resource. + */ QWaylandResource::QWaylandResource(wl_resource *resource) : m_resource(resource) { } +/*! + * \fn wl_resource *QWaylandResource::resource() const + * + * \return the wl_resource pointer held by this QWaylandResource. + */ + QT_END_NAMESPACE + +#include "moc_qwaylandresource.cpp" diff --git a/src/compositor/compositor_api/qwaylandresource.h b/src/compositor/compositor_api/qwaylandresource.h index 11ab64da9..ab8897700 100644 --- a/src/compositor/compositor_api/qwaylandresource.h +++ b/src/compositor/compositor_api/qwaylandresource.h @@ -1,55 +1,23 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDRESOURCE_H #define QWAYLANDRESOURCE_H #include <QtCore/QObject> #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> struct wl_resource; QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandResource +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandResource { Q_GADGET + QML_NAMED_ELEMENT(waylandresource) + QML_UNCREATABLE("") + QML_ADDED_IN_VERSION(1, 0) public: QWaylandResource(); explicit QWaylandResource(wl_resource *resource); diff --git a/src/compositor/compositor_api/qwaylandseat.cpp b/src/compositor/compositor_api/qwaylandseat.cpp index a7b01ef03..0e7df0ec0 100644 --- a/src/compositor/compositor_api/qwaylandseat.cpp +++ b/src/compositor/compositor_api/qwaylandseat.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandseat.h" #include "qwaylandseat_p.h" @@ -51,12 +15,16 @@ #include <QtWaylandCompositor/QWaylandKeymap> #include <QtWaylandCompositor/private/qwaylandseat_p.h> #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> +#include <QtWaylandCompositor/private/qwaylandkeyboard_p.h> #if QT_CONFIG(wayland_datadevice) #include <QtWaylandCompositor/private/qwldatadevice_p.h> #endif +#include <QtWaylandCompositor/private/qwaylandutils_p.h> #include "extensions/qwlqtkey_p.h" #include "extensions/qwaylandtextinput.h" +#include "extensions/qwaylandtextinputv3.h" +#include "extensions/qwaylandqttextinputmethod.h" QT_BEGIN_NAMESPACE @@ -145,6 +113,7 @@ void QWaylandSeatPrivate::seat_get_touch(wl_seat::Resource *resource, uint32_t i /*! * \qmltype WaylandSeat + * \instantiates QWaylandSeat * \inqmlmodule QtWayland.Compositor * \since 5.8 * \brief Provides access to keyboard, mouse, and touch input. @@ -176,7 +145,7 @@ void QWaylandSeatPrivate::seat_get_touch(wl_seat::Resource *resource, uint32_t i */ /*! - * Constructs a QWaylandSeat for the given \a compositor and with the given \a capabilityFlags. + * Constructs a QWaylandSeat for the given \a compositor and \a capabilityFlags. */ QWaylandSeat::QWaylandSeat(QWaylandCompositor *compositor, CapabilityFlags capabilityFlags) : QWaylandObject(*new QWaylandSeatPrivate(this)) @@ -186,6 +155,9 @@ QWaylandSeat::QWaylandSeat(QWaylandCompositor *compositor, CapabilityFlags capab d->capabilities = capabilityFlags; if (compositor->isCreated()) initialize(); + + // Support deprecated signal for backward compatibility + connect(this, &QWaylandSeat::cursorSurfaceRequested, this, &QWaylandSeat::cursorSurfaceRequest); } /*! @@ -195,6 +167,14 @@ QWaylandSeat::~QWaylandSeat() { } +/*! + * Initializes parts of the seat corresponding to the capabilities set in the constructor, or + * through setCapabilities(). + * + * \note Normally, this function is called automatically after the seat and compositor have been + * created, so calling it manually is usually unnecessary. + */ + void QWaylandSeat::initialize() { Q_D(QWaylandSeat); @@ -210,6 +190,11 @@ void QWaylandSeat::initialize() d->isInitialized = true; } +/*! + * Returns true if the QWaylandSeat is initialized; false otherwise. + * + * The value \c true indicates that it's now possible for clients to start using the seat. + */ bool QWaylandSeat::isInitialized() const { Q_D(const QWaylandSeat); @@ -275,6 +260,10 @@ void QWaylandSeat::sendKeyReleaseEvent(uint code) * Sends a touch point event to the \a surface on a touch device with the given * \a id, \a point and \a state. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l QWaylandQuickItem::touchEventsEnabled or \l sendFullTouchEvent, + * as it might lead to conflicting touch ids. + * * Returns the serial for the touch up or touch down event. */ uint QWaylandSeat::sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state) @@ -288,7 +277,7 @@ uint QWaylandSeat::sendTouchPointEvent(QWaylandSurface *surface, int id, const Q } /*! - * \qmlmethod uint QtWaylandCompositor::WaylandSeat::sendTouchPointPressed(WaylandSurface surface, int id, point position) + * \qmlmethod uint QtWayland.Compositor::WaylandSeat::sendTouchPointPressed(WaylandSurface surface, int id, point position) * * Sends a touch pressed event for the touch point \a id on \a surface with * position \a position. @@ -296,6 +285,10 @@ uint QWaylandSeat::sendTouchPointEvent(QWaylandSurface *surface, int id, const Q * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l WaylandQuickItem::touchEventsEnabled, as it might lead to + * conflicting touch ids. + * * Returns the serial for the touch down event. */ @@ -306,6 +299,10 @@ uint QWaylandSeat::sendTouchPointEvent(QWaylandSurface *surface, int id, const Q * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l QWaylandQuickItem::touchEventsEnabled or \l sendFullTouchEvent, + * as it might lead to conflicting touch ids. + * * Returns the serial for the touch down event. */ uint QWaylandSeat::sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position) @@ -314,7 +311,7 @@ uint QWaylandSeat::sendTouchPointPressed(QWaylandSurface *surface, int id, const } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSeat::sendTouchPointReleased(WaylandSurface surface, int id, point position) + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendTouchPointReleased(WaylandSurface surface, int id, point position) * * Sends a touch released event for the touch point \a id on \a surface with * position \a position. @@ -322,6 +319,10 @@ uint QWaylandSeat::sendTouchPointPressed(QWaylandSurface *surface, int id, const * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l WaylandQuickItem::touchEventsEnabled, as it might lead to + * conflicting touch ids. + * * Returns the serial for the touch up event. */ @@ -332,6 +333,10 @@ uint QWaylandSeat::sendTouchPointPressed(QWaylandSurface *surface, int id, const * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l QWaylandQuickItem::touchEventsEnabled or \l sendFullTouchEvent, + * as it might lead to conflicting touch ids. + * * Returns the serial for the touch up event. */ uint QWaylandSeat::sendTouchPointReleased(QWaylandSurface *surface, int id, const QPointF &position) @@ -340,7 +345,7 @@ uint QWaylandSeat::sendTouchPointReleased(QWaylandSurface *surface, int id, cons } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSeat::sendTouchPointMoved(WaylandSurface surface, int id, point position) + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendTouchPointMoved(WaylandSurface surface, int id, point position) * * Sends a touch moved event for the touch point \a id on \a surface with * position \a position. @@ -348,6 +353,10 @@ uint QWaylandSeat::sendTouchPointReleased(QWaylandSurface *surface, int id, cons * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l WaylandQuickItem::touchEventsEnabled, as it might lead to + * conflicting touch ids. + * * Returns the serial for the touch motion event. */ @@ -358,6 +367,10 @@ uint QWaylandSeat::sendTouchPointReleased(QWaylandSurface *surface, int id, cons * \note You need to send a touch frame event when you are done sending touch * events. * + * \warning This API should not be used in combination with forwarding of touch + * events using \l QWaylandQuickItem::touchEventsEnabled or \l sendFullTouchEvent, + * as it might lead to conflicting touch ids. + * * Returns the serial for the touch motion event. */ uint QWaylandSeat::sendTouchPointMoved(QWaylandSurface *surface, int id, const QPointF &position) @@ -366,7 +379,7 @@ uint QWaylandSeat::sendTouchPointMoved(QWaylandSurface *surface, int id, const Q } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSeat::sendTouchFrameEvent(WaylandClient client) + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendTouchFrameEvent(WaylandClient client) * * Sends a frame event to the touch device of a \a client to indicate the end * of a series of touch up, down, and motion events. @@ -384,7 +397,7 @@ void QWaylandSeat::sendTouchFrameEvent(QWaylandClient *client) } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSeat::sendTouchCancelEvent(WaylandClient client) + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendTouchCancelEvent(WaylandClient client) * * Sends a cancel event to the touch device of a \a client. */ @@ -401,6 +414,11 @@ void QWaylandSeat::sendTouchCancelEvent(QWaylandClient *client) /*! * Sends the \a event to the specified \a surface on the touch device. + * + * \warning This API will automatically map \l QEventPoint::id() to a + * sequential id before sending it to the client. It should therefore not be + * used in combination with the other API using explicit ids, as collisions + * might occur. */ void QWaylandSeat::sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *event) { @@ -414,6 +432,11 @@ void QWaylandSeat::sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *eve /*! * Sends the \a event to the keyboard device. + * + * \note The \a event should correspond to an actual keyboard key in the current mapping. + * For example, \c Qt::Key_Exclam is normally not a separate key: with most keyboards the + * exclamation mark is produced with Shift + 1. In that case, to send an exclamation mark + * key press event, use \c{QKeyEvent(QEvent::KeyPress, Qt::Key_1, Qt::ShiftModifier)}. */ void QWaylandSeat::sendFullKeyEvent(QKeyEvent *event) { @@ -427,10 +450,30 @@ void QWaylandSeat::sendFullKeyEvent(QKeyEvent *event) #if QT_CONFIG(im) if (keyboardFocus()->inputMethodControl()->enabled() && event->nativeScanCode() == 0) { - QWaylandTextInput *textInput = QWaylandTextInput::findIn(this); - if (textInput) { - textInput->sendKeyEvent(event); - return; + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) { + QWaylandTextInput *textInput = QWaylandTextInput::findIn(this); + if (textInput) { + textInput->sendKeyEvent(event); + return; + } + } + + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) { + QWaylandQtTextInputMethod *textInputMethod = QWaylandQtTextInputMethod::findIn(this); + if (textInputMethod) { + textInputMethod->sendKeyEvent(event); + return; + } + } + + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV3)) { + QWaylandTextInputV3 *textInputV3 = QWaylandTextInputV3::findIn(this); + if (textInputV3 && !event->text().isEmpty()) { + // it will just commit the text for text-input-unstable-v3 when keyPress + if (event->type() == QEvent::KeyPress) + textInputV3->sendKeyEvent(event); + return; + } } } #endif @@ -450,22 +493,29 @@ void QWaylandSeat::sendFullKeyEvent(QKeyEvent *event) return; } - if (event->type() == QEvent::KeyPress) + if (event->type() == QEvent::KeyPress) { + QWaylandKeyboardPrivate::get(d->keyboard.data())->checkAndRepairModifierState(event); d->keyboard->sendKeyPressEvent(scanCode); - else if (event->type() == QEvent::KeyRelease) + } else if (event->type() == QEvent::KeyRelease) { d->keyboard->sendKeyReleaseEvent(scanCode); + } } } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSeat::sendKeyEvent(int qtKey, bool pressed) + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendKeyEvent(int qtKey, bool pressed) * \since 5.12 * - * Sends a key press or release to the keyboard device. + * Sends a key press (if \a pressed is \c true) or release (if \a pressed is \c false) + * event of a key \a qtKey to the keyboard device. */ /*! - * Sends a key press or release to the keyboard device. + * Sends a key press (if \a pressed is \c true) or release (if \a pressed is \c false) + * event of a key \a qtKey to the keyboard device. + * + * \note This function does not support key events that require modifiers, such as \c Qt::Key_Exclam. + * Use \l{sendFullKeyEvent} instead. * * \since 5.12 */ @@ -488,6 +538,104 @@ void QWaylandSeat::sendKeyEvent(int qtKey, bool pressed) } /*! + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendUnicodeKeyPressEvent(uint unicode) + * \since 6.7 + * + * Sends a key press event of a UCS4 \a unicode through a text-input protocol. + * + * \note This function will not work properly if the client does not support the + * text-input protocol that the compositor supports. + */ + +/*! + * Sends a key press event of a UCS4 \a unicode through a text-input protocol. + * + * \note This function will not work properly if the client does not support the + * text-input protocol that the compositor supports. + * + * \sa {sendFullKeyEvent} {sendKeyEvent} + * + * \since 6.7 + */ +void QWaylandSeat::sendUnicodeKeyPressEvent(uint unicode) +{ + sendUnicodeKeyEvent(unicode, QEvent::KeyPress); +} + +/*! + * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendUnicodeKeyReleaseEvent(uint unicode) + * \since 6.7 + * + * Sends a key release event of a UCS4 \a unicode through a text-input protocol. + * + * \note This function will not work properly if the client does not support the + * text-input protocol that the compositor supports. + */ + +/*! + * Sends a key release event of a UCS4 \a unicode through a text-input protocol. + * + * \note This function will not work properly if the client does not support the + * text-input protocol that the compositor supports. + * + * \sa {sendFullKeyEvent} {sendKeyEvent} + * + * \since 6.7 + */ +void QWaylandSeat::sendUnicodeKeyReleaseEvent(uint unicode) +{ + sendUnicodeKeyEvent(unicode, QEvent::KeyRelease); +} + +/*! + * \internal + * + * Sends an \a eventType for the UCS4 \a unicode through a text-input protocol. + */ +void QWaylandSeat::sendUnicodeKeyEvent(uint unicode, QEvent::Type eventType) +{ + if (!keyboardFocus()) { + qWarning("Can't send a unicode key event, no keyboard focus, fix the compositor"); + return; + } +#if QT_CONFIG(im) + QString text; + text += QChar::fromUcs4(static_cast<char32_t>(unicode)); + + QKeyEvent event(eventType, Qt::Key_unknown, Qt::KeyboardModifiers{}, text); + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) { + QWaylandTextInput *textInput = QWaylandTextInput::findIn(this); + if (textInput) { + textInput->sendKeyEvent(&event); + return; + } + } + + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) { + QWaylandQtTextInputMethod *textInputMethod = QWaylandQtTextInputMethod::findIn(this); + if (textInputMethod) { + textInputMethod->sendKeyEvent(&event); + return; + } + } + + if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV3)) { + QWaylandTextInputV3 *textInputV3 = QWaylandTextInputV3::findIn(this); + if (textInputV3 && !text.isEmpty()) { + // it will just commit the text for text-input-unstable-v3 when keyPress + if (eventType == QEvent::KeyPress) + textInputV3->sendKeyEvent(&event); + return; + } + } +#else + Q_UNUSED(unicode); + Q_UNUSED(eventType); + qWarning() << "Can't send a unicode key event: Unable to find a text-input protocol."; +#endif +} + +/*! * Returns the keyboard for this input device. */ QWaylandKeyboard *QWaylandSeat::keyboard() const @@ -534,6 +682,11 @@ bool QWaylandSeat::setKeyboardFocus(QWaylandSurface *surface) return true; } + +/*! + * Returns the keymap object for this QWaylandSeat. + */ + QWaylandKeymap *QWaylandSeat::keymap() { Q_D(const QWaylandSeat); @@ -631,8 +784,8 @@ bool QWaylandSeat::isOwner(QInputEvent *inputEvent) const */ QWaylandSeat *QWaylandSeat::fromSeatResource(struct ::wl_resource *resource) { - if (auto *r = QWaylandSeatPrivate::Resource::fromResource(resource)) - return static_cast<QWaylandSeatPrivate *>(r->seat_object)->q_func(); + if (auto p = QtWayland::fromResource<QWaylandSeatPrivate *>(resource)) + return p->q_func(); return nullptr; } @@ -653,4 +806,71 @@ void QWaylandSeat::handleMouseFocusDestroyed() emit mouseFocusChanged(d->mouseFocus, oldFocus); } + +/*! \qmlsignal void QtWayland.Compositor::WaylandSeat::keyboardFocusChanged(QWaylandSurface newFocus, QWaylandSurface oldFocus) + * + * This signal is emitted when setKeyboardFocus() is called or when a WaylandQuickItem has focus + * and the user starts pressing keys. + * + * \a newFocus has the surface that received keyboard focus; or \c nullptr if no surface has + * focus. + * \a oldFocus has the surface that lost keyboard focus; or \c nullptr if no surface had focus. + */ + +/*! + * \fn void QWaylandSeat::keyboardFocusChanged(QWaylandSurface *newFocus, QWaylandSurface *oldFocus) + * + * This signal is emitted when setKeyboardFocus() is called. + * + * \a newFocus has the surface that received keyboard focus; or \c nullptr if no surface has + * focus. + * \a oldFocus has the surface that lost keyboard focus; or \c nullptr if no surface had focus. + */ + +/*! \qmlsignal void QtWayland.Compositor::WaylandSeat::cursorSurfaceRequest(QWaylandSurface surface, int hotspotX, int hotspotY) + * + * This signal is emitted when the client has requested for a specific \a surface to be the mouse + * cursor. For example, when the user hovers over a particular surface, and you want the cursor + * to change into a resize arrow. + * + * Both \a hotspotX and \a hotspotY are offsets from the top-left of a pointer surface, where a + * click should happen. For example, if the requested cursor surface is an arrow, the parameters + * indicate where the arrow's tip is, on that surface. + */ + + +/*! + * \fn void QWaylandSeat::cursorSurfaceRequest(QWaylandSurface *surface, int hotspotX, int hotspotY) + * + * This signal is emitted when the client has requested for a specific \a surface to be the mouse + * cursor. For example, when the user hovers over a particular surface, and you want the cursor + * to change into a resize arrow. + * + * Both \a hotspotX and \a hotspotY are offsets from the top-left of a pointer surface, where a + * click should happen. For example, if the requested cursor surface is an arrow, the parameters + * indicate where the arrow's tip is, on that surface. + */ + +/*! + * \property QWaylandSeat::drag + * + * This property holds the drag and drop operations and sends signals when they start and end. + * The property stores details like what image should be under the mouse cursor when the user + * drags it. + */ + +/*! + * \property QWaylandSeat::keymap + * This property holds the keymap object. + * + * A keymap provides a way to translate actual key scan codes into a meaningful value. + * For example, if you use a keymap with a Norwegian layout, the key to the right of + * the letter L produces an Ø. + * + * Keymaps can also be used to customize key functions, such as to specify whether + * Control and CAPS lock should be swapped, and so on. + */ + QT_END_NAMESPACE + +#include "moc_qwaylandseat.cpp" diff --git a/src/compositor/compositor_api/qwaylandseat.h b/src/compositor/compositor_api/qwaylandseat.h index 6a4d6e176..dd67e83ae 100644 --- a/src/compositor/compositor_api/qwaylandseat.h +++ b/src/compositor/compositor_api/qwaylandseat.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSEAT_H #define QWAYLANDSEAT_H @@ -45,8 +9,10 @@ #include <QtCore/QString> #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qtwaylandqmlinclude.h> #include <QtWaylandCompositor/qwaylandcompositorextension.h> #include <QtWaylandCompositor/qwaylandkeyboard.h> +#include <QtWaylandCompositor/qwaylandview.h> QT_BEGIN_NAMESPACE @@ -54,7 +20,6 @@ class QWaylandCompositor; class QWaylandSurface; class QKeyEvent; class QTouchEvent; -class QWaylandView; class QInputEvent; class QWaylandSeatPrivate; class QWaylandDrag; @@ -62,15 +27,22 @@ class QWaylandKeyboard; class QWaylandPointer; class QWaylandTouch; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSeat : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSeat : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandSeat) #if QT_CONFIG(draganddrop) Q_PROPERTY(QWaylandDrag *drag READ drag CONSTANT) + Q_MOC_INCLUDE("qwaylanddrag.h") #endif Q_PROPERTY(QWaylandKeymap *keymap READ keymap CONSTANT) + Q_MOC_INCLUDE("qwaylandkeymap.h") + Q_MOC_INCLUDE("qwaylandview.h") + + QML_NAMED_ELEMENT(WaylandSeat) + QML_ADDED_IN_VERSION(1, 0) + QML_UNCREATABLE("") public: enum CapabilityFlag { // The order should match the enum WL_SEAT_CAPABILITY_* @@ -99,6 +71,9 @@ public: void sendFullKeyEvent(QKeyEvent *event); Q_INVOKABLE void sendKeyEvent(int qtKey, bool pressed); + Q_REVISION(6, 7) Q_INVOKABLE void sendUnicodeKeyPressEvent(uint unicode); + Q_REVISION(6, 7) Q_INVOKABLE void sendUnicodeKeyReleaseEvent(uint unicode); + uint sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state); Q_INVOKABLE uint sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position); Q_INVOKABLE uint sendTouchPointReleased(QWaylandSurface *surface, int id, const QPointF &position); @@ -136,9 +111,14 @@ public: Q_SIGNALS: void mouseFocusChanged(QWaylandView *newFocus, QWaylandView *oldFocus); void keyboardFocusChanged(QWaylandSurface *newFocus, QWaylandSurface *oldFocus); +#if QT_DEPRECATED_SINCE(6, 1) void cursorSurfaceRequest(QWaylandSurface *surface, int hotspotX, int hotspotY); +#endif + void cursorSurfaceRequested(QWaylandSurface *surface, int hotspotX, int hotspotY, QWaylandClient *client); private: + void sendUnicodeKeyEvent(uint unicode, QEvent::Type type); + void handleMouseFocusDestroyed(); }; diff --git a/src/compositor/compositor_api/qwaylandseat_p.h b/src/compositor/compositor_api/qwaylandseat_p.h index 7eb6aa69c..b82f899a3 100644 --- a/src/compositor/compositor_api/qwaylandseat_p.h +++ b/src/compositor/compositor_api/qwaylandseat_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSEAT_P_H #define QWAYLANDSEAT_P_H @@ -84,7 +48,7 @@ class InputMethod; } -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSeatPrivate : public QObjectPrivate, public QtWaylandServer::wl_seat +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSeatPrivate : public QObjectPrivate, public QtWaylandServer::wl_seat { public: Q_DECLARE_PUBLIC(QWaylandSeat) diff --git a/src/compositor/compositor_api/qwaylandsurface.cpp b/src/compositor/compositor_api/qwaylandsurface.cpp index f457c372c..207158bf7 100644 --- a/src/compositor/compositor_api/qwaylandsurface.cpp +++ b/src/compositor/compositor_api/qwaylandsurface.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandsurface.h" #include "qwaylandsurface_p.h" @@ -59,6 +23,7 @@ #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> #include <QtWaylandCompositor/private/qwaylandview_p.h> #include <QtWaylandCompositor/private/qwaylandseat_p.h> +#include <QtWaylandCompositor/private/qwaylandutils_p.h> #include <QtCore/private/qobject_p.h> @@ -66,6 +31,7 @@ #include <QtGui/QScreen> #include <QtCore/QDebug> +#include <QtCore/QtMath> QT_BEGIN_NAMESPACE @@ -135,9 +101,9 @@ QWaylandSurfacePrivate::~QWaylandSurfacePrivate() bufferRef = QWaylandBufferRef(); - foreach (QtWayland::FrameCallback *c, pendingFrameCallbacks) + for (QtWayland::FrameCallback *c : std::as_const(pendingFrameCallbacks)) c->destroy(); - foreach (QtWayland::FrameCallback *c, frameCallbacks) + for (QtWayland::FrameCallback *c : std::as_const(frameCallbacks)) c->destroy(); } @@ -150,7 +116,8 @@ void QWaylandSurfacePrivate::removeFrameCallback(QtWayland::FrameCallback *callb void QWaylandSurfacePrivate::notifyViewsAboutDestruction() { Q_Q(QWaylandSurface); - foreach (QWaylandView *view, views) { + const auto viewsCopy = views; // Views will be removed from the list when marked as destroyed + for (QWaylandView *view : viewsCopy) { QWaylandViewPrivate::get(view)->markSurfaceAsDestroyed(q); } if (hasContent) { @@ -202,9 +169,20 @@ void QWaylandSurfacePrivate::surface_attach(Resource *, struct wl_resource *buff pending.newlyAttached = true; } +/* + Note: The Wayland protocol specifies that buffer scale and damage can be interleaved, so + we cannot scale the damage region until commit. We assume that clients will either use + surface_damage or surface_damage_buffer within one frame for one surface. +*/ + void QWaylandSurfacePrivate::surface_damage(Resource *, int32_t x, int32_t y, int32_t width, int32_t height) { - pending.damage = pending.damage.united(QRect(x, y, width, height)); + pending.surfaceDamage = pending.surfaceDamage.united(QRect(x, y, width, height)); +} + +void QWaylandSurfacePrivate::surface_damage_buffer(Resource *, int32_t x, int32_t y, int32_t width, int32_t height) +{ + pending.bufferDamage = pending.bufferDamage.united(QRect(x, y, width, height)); } void QWaylandSurfacePrivate::surface_frame(Resource *resource, uint32_t callback) @@ -234,32 +212,66 @@ void QWaylandSurfacePrivate::surface_commit(Resource *) // Needed in order to know whether we want to emit signals later QSize oldBufferSize = bufferSize; + QRectF oldSourceGeometry = sourceGeometry; + QSize oldDestinationSize = destinationSize; bool oldHasContent = hasContent; int oldBufferScale = bufferScale; // Update all internal state if (pending.buffer.hasBuffer() || pending.newlyAttached) bufferRef = pending.buffer; + bufferScale = pending.bufferScale; bufferSize = bufferRef.size(); - damage = pending.damage.intersected(QRect(QPoint(), bufferSize)); + QSize surfaceSize = bufferSize / bufferScale; + sourceGeometry = !pending.sourceGeometry.isValid() ? QRect(QPoint(), surfaceSize) : pending.sourceGeometry; + destinationSize = pending.destinationSize.isEmpty() ? sourceGeometry.size().toSize() : pending.destinationSize; + QRect destinationRect(QPoint(), destinationSize); + // pending.damage is already in surface coordinates + damage = pending.surfaceDamage.intersected(destinationRect); + if (!pending.bufferDamage.isNull()) { + if (bufferScale == 1) { + damage |= pending.bufferDamage.intersected(destinationRect); // Already in surface coordinates + } else { + // We must transform pending.damage from buffer coordinate system to surface coordinates + // TODO(QTBUG-85461): Also support wp_viewport setting more complex transformations + auto xform = [](const QRect &r, int scale) -> QRect { + QRect res{ + QPoint{ r.x() / scale, r.y() / scale }, + QPoint{ (r.right() + scale - 1) / scale, (r.bottom() + scale - 1) / scale } + }; + return res; + }; + for (const QRect &r : pending.bufferDamage) + damage |= xform(r, bufferScale).intersected(destinationRect); + } + } hasContent = bufferRef.hasContent(); - bufferScale = pending.bufferScale; frameCallbacks << pendingFrameCallbacks; - inputRegion = pending.inputRegion.intersected(QRect(QPoint(), bufferSize)); - opaqueRegion = pending.opaqueRegion.intersected(QRect(QPoint(), bufferSize)); + inputRegion = pending.inputRegion.intersected(destinationRect); + opaqueRegion = pending.opaqueRegion.intersected(destinationRect); + bool becameOpaque = opaqueRegion.boundingRect().contains(destinationRect); + if (becameOpaque != isOpaque) { + isOpaque = becameOpaque; + emit q->isOpaqueChanged(); + } + QPoint offsetForNextFrame = pending.offset; + if (viewport) + viewport->checkCommittedState(); + // Clear per-commit state pending.buffer = QWaylandBufferRef(); pending.offset = QPoint(); pending.newlyAttached = false; - pending.damage = QRegion(); + pending.bufferDamage = QRegion(); + pending.surfaceDamage = QRegion(); pendingFrameCallbacks.clear(); // Notify buffers and views if (auto *buffer = bufferRef.buffer()) buffer->setCommitted(damage); - for (auto *view : qAsConst(views)) + for (auto *view : std::as_const(views)) view->bufferCommitted(bufferRef, damage); // Now all double-buffered state has been applied so it's safe to emit general signals @@ -269,11 +281,17 @@ void QWaylandSurfacePrivate::surface_commit(Resource *) emit q->damaged(damage); if (oldBufferSize != bufferSize) - emit q->sizeChanged(); + emit q->bufferSizeChanged(); if (oldBufferScale != bufferScale) emit q->bufferScaleChanged(); + if (oldDestinationSize != destinationSize) + emit q->destinationSizeChanged(); + + if (oldSourceGeometry != sourceGeometry) + emit q->sourceGeometryChanged(); + if (oldHasContent != hasContent) emit q->hasContentChanged(); @@ -320,7 +338,54 @@ QtWayland::ClientBuffer *QWaylandSurfacePrivate::getBuffer(struct ::wl_resource } /*! + * \class QWaylandSurfaceRole + * \inmodule QtWaylandCompositor + * \since 5.8 + * \brief The QWaylandSurfaceRole class represents the role of the surface in context of wl_surface. + * + * QWaylandSurfaceRole is used to represent the role of a QWaylandSurface. According to the protocol + * specification, the role of a surface is permanent once set, and if the same surface is later + * reused for a different role, this constitutes a protocol error. Setting the surface to the same + * role multiple times is not an error. + * + * As an example, the QWaylandXdgShell can assign either "popup" or "toplevel" roles to surfaces. + * If \c get_toplevel is requested on a surface which has previously received a \c get_popup + * request, then the compositor will issue a protocol error. + * + * Roles are compared by pointer value, so any two objects of QWaylandSurfaceRole will be considered + * different roles, regardless of what their \l{name()}{names} are. A typical way of assigning a + * role is to have a static QWaylandSurfaceRole object to represent it. + * + * \code + * class MyShellSurfaceSubType + * { + * static QWaylandSurfaceRole s_role; + * // ... + * }; + * + * // ... + * + * surface->setRole(&MyShellSurfaceSubType::s_role, resource->handle, MY_ERROR_CODE); + * \endcode + */ + +/*! + * \fn QWaylandSurfaceRole::QWaylandSurfaceRole(const QByteArray &name) + * + * Creates a QWaylandSurfaceRole and assigns it \a name. The name is used in error messages + * involving this QWaylandSurfaceRole. + */ + +/*! + * \fn const QByteArray QWaylandSurfaceRole::name() + * + * Returns the name of the QWaylandSurfaceRole. The name is used in error messages involving this + * QWaylandSurfaceRole, for example if an attempt is made to change the role of a surface. + */ + +/*! * \qmltype WaylandSurface + * \instantiates QWaylandSurface * \inqmlmodule QtWayland.Compositor * \since 5.8 * \brief Represents a rectangular area on an output device. @@ -371,12 +436,13 @@ QWaylandSurface::QWaylandSurface(QWaylandSurfacePrivate &dptr) QWaylandSurface::~QWaylandSurface() { Q_D(QWaylandSurface); - QWaylandCompositorPrivate::get(d->compositor)->unregisterSurface(this); + if (d->compositor) + QWaylandCompositorPrivate::get(d->compositor)->unregisterSurface(this); d->notifyViewsAboutDestruction(); } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSurface::initialize(WaylandCompositor compositor, WaylandClient client, int id, int version) + * \qmlmethod void QtWayland.Compositor::WaylandSurface::initialize(WaylandCompositor compositor, WaylandClient client, int id, int version) * * Initializes the WaylandSurface with the given \a compositor and \a client, and with the given \a id * and \a version. @@ -411,7 +477,7 @@ bool QWaylandSurface::isInitialized() const } /*! - * \qmlproperty WaylandClient QtWaylandCompositor::WaylandSurface::client + * \qmlproperty WaylandClient QtWayland.Compositor::WaylandSurface::client * * This property holds the client using this WaylandSurface. */ @@ -431,9 +497,7 @@ QWaylandClient *QWaylandSurface::client() const } /*! - * \property QWaylandSurface::waylandClient - * - * This property holds the \c wl_client using this QWaylandSurface. + * Holds the \c wl_client using this QWaylandSurface. */ ::wl_client *QWaylandSurface::waylandClient() const { @@ -444,7 +508,7 @@ QWaylandClient *QWaylandSurface::client() const } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandSurface::hasContent + * \qmlproperty bool QtWayland.Compositor::WaylandSurface::hasContent * * This property holds whether the WaylandSurface has content. */ @@ -461,24 +525,92 @@ bool QWaylandSurface::hasContent() const } /*! - * \qmlproperty size QtWaylandCompositor::WaylandSurface::size + * \qmlproperty rect QtWayland.Compositor::WaylandSurface::sourceGeometry + * \since 5.13 + * + * This property describes the portion of the attached Wayland buffer that should + * be drawn on the screen. The coordinates are from the corner of the buffer and are + * scaled by \l bufferScale. + * + * \sa bufferScale + * \sa bufferSize + * \sa destinationSize + */ + +/*! + * \property QWaylandSurface::sourceGeometry + * \since 5.13 + * + * This property describes the portion of the attached QWaylandBuffer that should + * be drawn on the screen. The coordinates are from the corner of the buffer and are + * scaled by \l bufferScale. + * + * \sa bufferScale + * \sa bufferSize + * \sa destinationSize + */ +QRectF QWaylandSurface::sourceGeometry() const +{ + Q_D(const QWaylandSurface); + return d->sourceGeometry; +} + +/*! + * \qmlproperty size QtWayland.Compositor::WaylandSurface::destinationSize + * \since 5.13 + * + * This property holds the size of this WaylandSurface in surface coordinates. + * + * \sa bufferScale + * \sa bufferSize + */ + +/*! + * \property QWaylandSurface::destinationSize + * \since 5.13 + * + * This property holds the size of this WaylandSurface in surface coordinates. + * + * \sa bufferScale + * \sa bufferSize + */ +QSize QWaylandSurface::destinationSize() const +{ + Q_D(const QWaylandSurface); + return d->destinationSize; +} + +/*! + * \qmlproperty size QtWayland.Compositor::WaylandSurface::bufferSize + * + * This property holds the size of the current buffer of this WaylandSurface in pixels, + * not in surface coordinates. * - * This property holds the WaylandSurface's size in pixels. + * For the size in surface coordinates, use \l destinationSize instead. + * + * \sa destinationSize + * \sa bufferScale */ /*! - * \property QWaylandSurface::size + * \property QWaylandSurface::bufferSize + * + * This property holds the size of the current buffer of this QWaylandSurface in pixels, + * not in surface coordinates. * - * This property holds the QWaylandSurface's size in pixels. + * For the size in surface coordinates, use \l destinationSize instead. + * + * \sa destinationSize + * \sa bufferScale */ -QSize QWaylandSurface::size() const +QSize QWaylandSurface::bufferSize() const { Q_D(const QWaylandSurface); return d->bufferSize; } /*! - * \qmlproperty size QtWaylandCompositor::WaylandSurface::bufferScale + * \qmlproperty size QtWayland.Compositor::WaylandSurface::bufferScale * * This property holds the WaylandSurface's buffer scale. The buffer scale lets * a client supply higher resolution buffer data for use on high resolution @@ -499,7 +631,7 @@ int QWaylandSurface::bufferScale() const } /*! - * \qmlproperty enum QtWaylandCompositor::WaylandSurface::contentOrientation + * \qmlproperty enum QtWayland.Compositor::WaylandSurface::contentOrientation * * This property holds the orientation of the WaylandSurface's contents. * @@ -529,7 +661,7 @@ Qt::ScreenOrientation QWaylandSurface::contentOrientation() const */ /*! - * \qmlproperty enum QtWaylandCompositor::WaylandSurface::origin + * \qmlproperty enum QtWayland.Compositor::WaylandSurface::origin * * This property holds the origin of the WaylandSurface's buffer, or * WaylandSurface.OriginTopLeft if the surface has no buffer. @@ -568,7 +700,7 @@ QWaylandCompositor *QWaylandSurface::compositor() const void QWaylandSurface::frameStarted() { Q_D(QWaylandSurface); - foreach (QtWayland::FrameCallback *c, d->frameCallbacks) + for (QtWayland::FrameCallback *c : std::as_const(d->frameCallbacks)) c->canSend = true; } @@ -602,7 +734,25 @@ bool QWaylandSurface::inputRegionContains(const QPoint &p) const } /*! - * \qmlmethod void QtWaylandCompositor::WaylandSurface::destroy() + * Returns \c true if the QWaylandSurface's input region contains the point \a position. + * Otherwise returns \c false. + * + * \since 5.14 + */ +bool QWaylandSurface::inputRegionContains(const QPointF &position) const +{ + Q_D(const QWaylandSurface); + // QRegion::contains operates in integers. If a region has a rect (0,0,10,10), (0,0) is + // inside while (10,10) is outside. Therefore, we can't use QPoint::toPoint(), which will + // round upwards, meaning the point (-0.25,-0.25) would be rounded to (0,0) and count as + // being inside the region, and similarly, a point (9.75,9.75) inside the region would be + // rounded upwards and count as being outside the region. + const QPoint floored(qFloor(position.x()), qFloor(position.y())); + return d->inputRegion.contains(floored); +} + +/*! + * \qmlmethod void QtWayland.Compositor::WaylandSurface::destroy() * * Destroys the WaylandSurface. */ @@ -617,7 +767,7 @@ void QWaylandSurface::destroy() } /*! - * \qmlmethod bool QtWaylandCompositor::WaylandSurface::isDestroyed() + * \qmlmethod bool QtWayland.Compositor::WaylandSurface::isDestroyed() * * Returns \c true if the WaylandSurface has been destroyed. Otherwise returns \c false. */ @@ -632,7 +782,7 @@ bool QWaylandSurface::isDestroyed() const } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandSurface::cursorSurface + * \qmlproperty bool QtWayland.Compositor::WaylandSurface::cursorSurface * * This property holds whether the WaylandSurface is a cursor surface. */ @@ -658,6 +808,52 @@ bool QWaylandSurface::isCursorSurface() const return d->isCursorSurface; } +/*! + * \qmlproperty bool QtWayland.Compositor::WaylandSurface::inhibitsIdle + * \since 5.14 + * + * This property holds whether this surface is intended to inhibit the idle + * behavior of the compositor such as screen blanking, locking and screen saving. + * + * \sa IdleInhibitManagerV1 + */ + +/*! + * \property QWaylandSurface::inhibitsIdle + * \since 5.14 + * + * This property holds whether this surface is intended to inhibit the idle + * behavior of the compositor such as screen blanking, locking and screen saving. + * + * \sa QWaylandIdleInhibitManagerV1 + */ +bool QWaylandSurface::inhibitsIdle() const +{ + Q_D(const QWaylandSurface); + return !d->idleInhibitors.isEmpty(); +} + +/*! + * \qmlproperty bool QtWayland.Compositor::WaylandSurface::isOpaque + * \since 6.4 + * + * This property holds whether the surface is fully opaque, as reported by the + * client through the set_opaque_region request. + */ + +/*! + * \property QWaylandSurface::isOpaque + * \since 6.4 + * + * This property holds whether the surface is fully opaque, as reported by the + * client through the set_opaque_region request. + */ +bool QWaylandSurface::isOpaque() const +{ + Q_D(const QWaylandSurface); + return d->isOpaque; +} + #if QT_CONFIG(im) QWaylandInputMethodControl *QWaylandSurface::inputMethodControl() const { @@ -740,12 +936,12 @@ QList<QWaylandView *> QWaylandSurface::views() const } /*! - * Returns the QWaylandSurface corresponding to the Wayland resource \a res. + * Returns the QWaylandSurface corresponding to the Wayland resource \a resource. */ -QWaylandSurface *QWaylandSurface::fromResource(::wl_resource *res) +QWaylandSurface *QWaylandSurface::fromResource(::wl_resource *resource) { - if (auto *r = QWaylandSurfacePrivate::Resource::fromResource(res)) - return static_cast<QWaylandSurfacePrivate *>(r->surface_object)->q_func(); + if (auto p = QtWayland::fromResource<QWaylandSurfacePrivate *>(resource)) + return p->q_func(); return nullptr; } @@ -759,11 +955,21 @@ struct wl_resource *QWaylandSurface::resource() const } /*! - * Sets a \a role on the surface. A role defines how a surface will be mapped on screen, without a role - * a surface is supposed to be hidden. Only one role at all times can be set on a surface. Although - * setting the same role many times is allowed, attempting to change the role of a surface will trigger - * a protocol error to the \a errorResource and send an \a errorCode to the client. + * Sets a \a role on the surface. A role defines how a surface will be mapped on screen; without a + * role a surface is supposed to be hidden. Once a role is assigned to a surface, this becomes its + * permanent role. Any subsequent call to \c setRole() with a different role will trigger a + * protocol error to the \a errorResource and send an \a errorCode to the client. Enforcing this + * requirement is the main purpose of the surface role. + * + * The \a role is compared by pointer value. Any two objects of QWaylandSurfaceRole will be + * considered different roles, regardless of their names. * + * The surface role is set internally by protocol implementations when a surface is adopted for a + * specific purpose, for example in a \l{Shell Extensions - Qt Wayland Compositor}{shell extension}. + * Unless you are developing extensions which use surfaces in this way, you should not call this + * function. + * + * Returns true if a role can be assigned; false otherwise. */ bool QWaylandSurface::setRole(QWaylandSurfaceRole *role, wl_resource *errorResource, uint32_t errorCode) { @@ -869,7 +1075,7 @@ void QWaylandSurfacePrivate::Subsurface::subsurface_set_desync(wl_subsurface::Re } /*! - * \qmlsignal QtWaylandCompositor::WaylandSurface::childAdded(WaylandSurface child) + * \qmlsignal QtWayland.Compositor::WaylandSurface::childAdded(WaylandSurface child) * * This signal is emitted when a wl_subsurface, \a child, has been added to the surface. */ @@ -881,7 +1087,7 @@ void QWaylandSurfacePrivate::Subsurface::subsurface_set_desync(wl_subsurface::Re */ /*! - * \qmlsignal QtWaylandCompositor::WaylandSurface::surfaceDestroyed() + * \qmlsignal QtWayland.Compositor::WaylandSurface::surfaceDestroyed() * * This signal is emitted when the corresponding wl_surface is destroyed. */ @@ -893,7 +1099,7 @@ void QWaylandSurfacePrivate::Subsurface::subsurface_set_desync(wl_subsurface::Re */ /*! - * \qmlsignal void QtWaylandCompositor::WaylandSurface::dragStarted(WaylandDrag drag) + * \qmlsignal void QtWayland.Compositor::WaylandSurface::dragStarted(WaylandDrag drag) * * This signal is emitted when a \a drag has started from this surface. */ @@ -904,4 +1110,23 @@ void QWaylandSurfacePrivate::Subsurface::subsurface_set_desync(wl_subsurface::Re * This signal is emitted when a \a drag has started from this surface. */ +/*! + * \fn void damaged(const QRegion &rect) + * + * This signal is emitted when the client tells the compositor that a particular part of, or + * possibly the entire surface has been updated, so the compositor can redraw that part. + * + * While the compositor APIs take care of redrawing automatically, this function may be useful + * if you require a specific, custom behavior. + */ + +/*! + * \fn void parentChanged(QWaylandSurface *newParent, QWaylandSurface *oldParent) + * + * This signal is emitted when the client has requested that this surface should be a + * subsurface of \a newParent. + */ + QT_END_NAMESPACE + +#include "moc_qwaylandsurface.cpp" diff --git a/src/compositor/compositor_api/qwaylandsurface.h b/src/compositor/compositor_api/qwaylandsurface.h index a138b2af5..0494a091e 100644 --- a/src/compositor/compositor_api/qwaylandsurface.h +++ b/src/compositor/compositor_api/qwaylandsurface.h @@ -1,49 +1,15 @@ -/**************************************************************************** -** -** Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017-2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACE_H #define QWAYLANDSURFACE_H #include <QtWaylandCompositor/qtwaylandcompositorglobal.h> +#include <QtWaylandCompositor/qwaylandcompositor.h> #include <QtWaylandCompositor/qwaylandcompositorextension.h> #include <QtWaylandCompositor/qwaylandclient.h> +#include <QtWaylandCompositor/qwaylanddrag.h> #include <QtCore/QScopedPointer> #include <QtGui/QImage> @@ -56,14 +22,10 @@ struct wl_resource; QT_BEGIN_NAMESPACE class QTouchEvent; -class QWaylandClient; class QWaylandSurfacePrivate; -class QWaylandCompositor; class QWaylandBufferRef; class QWaylandView; -class QWaylandSurfaceOp; class QWaylandInputMethodControl; -class QWaylandDrag; class QWaylandSurfaceRole { @@ -76,18 +38,27 @@ private: QByteArray m_name; }; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSurface : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSurface : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandSurface) Q_PROPERTY(QWaylandClient *client READ client CONSTANT) - Q_PROPERTY(QSize size READ size NOTIFY sizeChanged) + Q_PROPERTY(QRectF sourceGeometry READ sourceGeometry NOTIFY sourceGeometryChanged REVISION(1, 13)) + Q_PROPERTY(QSize destinationSize READ destinationSize NOTIFY destinationSizeChanged REVISION(1, 13)) + Q_PROPERTY(QSize bufferSize READ bufferSize NOTIFY bufferSizeChanged REVISION(1, 13)) Q_PROPERTY(int bufferScale READ bufferScale NOTIFY bufferScaleChanged) Q_PROPERTY(Qt::ScreenOrientation contentOrientation READ contentOrientation NOTIFY contentOrientationChanged) Q_PROPERTY(QWaylandSurface::Origin origin READ origin NOTIFY originChanged) Q_PROPERTY(bool hasContent READ hasContent NOTIFY hasContentChanged) Q_PROPERTY(bool cursorSurface READ isCursorSurface WRITE markAsCursorSurface NOTIFY cursorSurfaceChanged) - + Q_PROPERTY(bool inhibitsIdle READ inhibitsIdle NOTIFY inhibitsIdleChanged REVISION(1, 14)) + Q_PROPERTY(bool isOpaque READ isOpaque NOTIFY isOpaqueChanged REVISION(6, 4)) + Q_MOC_INCLUDE("qwaylanddrag.h") + Q_MOC_INCLUDE("qwaylandcompositor.h") + + QML_NAMED_ELEMENT(WaylandSurfaceBase) + QML_ADDED_IN_VERSION(1, 0) + QML_UNCREATABLE("Cannot create instance of WaylandSurfaceBase, use WaylandSurface instead") public: enum Origin { OriginTopLeft, @@ -110,7 +81,9 @@ public: bool hasContent() const; - QSize size() const; + QRectF sourceGeometry() const; + QSize destinationSize() const; + QSize bufferSize() const; int bufferScale() const; Qt::ScreenOrientation contentOrientation() const; @@ -120,6 +93,7 @@ public: QWaylandCompositor *compositor() const; bool inputRegionContains(const QPoint &p) const; + bool inputRegionContains(const QPointF &position) const; Q_INVOKABLE void destroy(); Q_INVOKABLE bool isDestroyed() const; @@ -138,6 +112,9 @@ public: void markAsCursorSurface(bool cursorSurface); bool isCursorSurface() const; + bool inhibitsIdle() const; + bool isOpaque() const; + #if QT_CONFIG(im) QWaylandInputMethodControl *inputMethodControl() const; #endif @@ -155,7 +132,9 @@ Q_SIGNALS: void damaged(const QRegion &rect); void parentChanged(QWaylandSurface *newParent, QWaylandSurface *oldParent); void childAdded(QWaylandSurface *child); - void sizeChanged(); + Q_REVISION(1, 13) void sourceGeometryChanged(); + Q_REVISION(1, 13) void destinationSizeChanged(); + Q_REVISION(1, 13) void bufferSizeChanged(); void bufferScaleChanged(); void offsetForNextFrame(const QPoint &offset); void contentOrientationChanged(); @@ -166,6 +145,8 @@ Q_SIGNALS: void subsurfacePlaceBelow(QWaylandSurface *sibling); void dragStarted(QWaylandDrag *drag); void cursorSurfaceChanged(); + Q_REVISION(14) void inhibitsIdleChanged(); + Q_REVISION(6, 4) void isOpaqueChanged(); void configure(bool hasBuffer); void redraw(); diff --git a/src/compositor/compositor_api/qwaylandsurface_p.h b/src/compositor/compositor_api/qwaylandsurface_p.h index df868de63..b4df7498e 100644 --- a/src/compositor/compositor_api/qwaylandsurface_p.h +++ b/src/compositor/compositor_api/qwaylandsurface_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACE_P_H #define QWAYLANDSURFACE_P_H @@ -61,7 +25,7 @@ #include <QtWaylandCompositor/private/qwlregion_p.h> -#include <QtCore/QVector> +#include <QtCore/QList> #include <QtCore/QRect> #include <QtGui/QRegion> #include <QtGui/QImage> @@ -73,20 +37,23 @@ #include <wayland-util.h> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> +#include <QtWaylandCompositor/private/qwaylandviewporter_p.h> +#include <QtWaylandCompositor/private/qwaylandidleinhibitv1_p.h> + +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE class QWaylandCompositor; class QWaylandSurface; class QWaylandView; -class QWaylandSurfaceInterface; class QWaylandInputMethodControl; namespace QtWayland { class FrameCallback; } -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWaylandServer::wl_surface +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSurfacePrivate : public QObjectPrivate, public QtWaylandServer::wl_surface { public: static QWaylandSurfacePrivate *get(QWaylandSurface *surface); @@ -124,6 +91,7 @@ protected: struct wl_resource *buffer, int x, int y) override; void surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; + void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; void surface_frame(Resource *resource, uint32_t callback) override; void surface_set_opaque_region(Resource *resource, @@ -144,14 +112,18 @@ public: //member variables QRegion damage; QWaylandBufferRef bufferRef; QWaylandSurfaceRole *role = nullptr; + QWaylandViewporterPrivate::Viewport *viewport = nullptr; struct { QWaylandBufferRef buffer; - QRegion damage; + QRegion surfaceDamage; + QRegion bufferDamage; QPoint offset; - bool newlyAttached; + bool newlyAttached = false; QRegion inputRegion; - int bufferScale; + int bufferScale = 1; + QRectF sourceGeometry; + QSize destinationSize; QRegion opaqueRegion; } pending; @@ -163,15 +135,20 @@ public: //member variables QList<QPointer<QWaylandSurface>> subsurfaceChildren; + QList<QWaylandIdleInhibitManagerV1Private::Inhibitor *> idleInhibitors; + QRegion inputRegion; QRegion opaqueRegion; + QRectF sourceGeometry; + QSize destinationSize; QSize bufferSize; int bufferScale = 1; bool isCursorSurface = false; bool destroyed = false; bool hasContent = false; bool isInitialized = false; + bool isOpaque = false; Qt::ScreenOrientation contentOrientation = Qt::PrimaryOrientation; QWindow::Visibility visibility; #if QT_CONFIG(im) diff --git a/src/compositor/compositor_api/qwaylandsurfacegrabber.cpp b/src/compositor/compositor_api/qwaylandsurfacegrabber.cpp index d36efb543..5f24d1c77 100644 --- a/src/compositor/compositor_api/qwaylandsurfacegrabber.cpp +++ b/src/compositor/compositor_api/qwaylandsurfacegrabber.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandsurfacegrabber.h" @@ -119,3 +83,5 @@ void QWaylandSurfaceGrabber::grab() } QT_END_NAMESPACE + +#include "moc_qwaylandsurfacegrabber.cpp" diff --git a/src/compositor/compositor_api/qwaylandsurfacegrabber.h b/src/compositor/compositor_api/qwaylandsurfacegrabber.h index c28614f37..b21572ec0 100644 --- a/src/compositor/compositor_api/qwaylandsurfacegrabber.h +++ b/src/compositor/compositor_api/qwaylandsurfacegrabber.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACEGRABBER_H #define QWAYLANDSURFACEGRABBER_H @@ -48,7 +12,7 @@ QT_BEGIN_NAMESPACE class QWaylandSurface; class QWaylandSurfaceGrabberPrivate; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSurfaceGrabber : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandSurfaceGrabber : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandSurfaceGrabber) diff --git a/src/compositor/compositor_api/qwaylandtouch.cpp b/src/compositor/compositor_api/qwaylandtouch.cpp index 15746cb5f..39aeac491 100644 --- a/src/compositor/compositor_api/qwaylandtouch.cpp +++ b/src/compositor/compositor_api/qwaylandtouch.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandtouch.h" #include "qwaylandtouch_p.h" @@ -109,7 +73,7 @@ int QWaylandTouchPrivate::toSequentialWaylandId(int touchId) return availableId; } ids.append(touchId); - return ids.length() - 1; + return ids.size() - 1; } /*! @@ -172,6 +136,9 @@ uint QWaylandTouch::sendTouchPointEvent(QWaylandSurface *surface, int id, const case Qt::TouchPointStationary: // stationary points are not sent through wayland, the client must cache them break; + case Qt::TouchPointUnknownState: + // Ignored + break; } return serial; @@ -218,17 +185,17 @@ void QWaylandTouch::sendFullTouchEvent(QWaylandSurface *surface, QTouchEvent *ev if (ext && ext->postTouchEvent(event, surface)) return; - const QList<QTouchEvent::TouchPoint> points = event->touchPoints(); + const QList<QTouchEvent::TouchPoint> points = event->points(); if (points.isEmpty()) return; - const int pointCount = points.count(); + const int pointCount = points.size(); for (int i = 0; i < pointCount; ++i) { const QTouchEvent::TouchPoint &tp(points.at(i)); // Convert the local pos in the compositor window to surface-relative. const int id = d->toSequentialWaylandId(tp.id()); - sendTouchPointEvent(surface, id, tp.pos(), tp.state()); - if (tp.state() == Qt::TouchPointReleased) + sendTouchPointEvent(surface, id, tp.position(), Qt::TouchPointState(tp.state())); + if (tp.state() == QEventPoint::Released) d->ids[id] = -1; } sendFrameEvent(surface->client()); @@ -244,3 +211,5 @@ void QWaylandTouch::addClient(QWaylandClient *client, uint32_t id, uint32_t vers } QT_END_NAMESPACE + +#include "moc_qwaylandtouch.cpp" diff --git a/src/compositor/compositor_api/qwaylandtouch.h b/src/compositor/compositor_api/qwaylandtouch.h index 7269e64e1..bdaa68eb6 100644 --- a/src/compositor/compositor_api/qwaylandtouch.h +++ b/src/compositor/compositor_api/qwaylandtouch.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDTOUCH_H #define QWAYLANDTOUCH_H @@ -56,7 +20,7 @@ class QWaylandView; class QWaylandClient; class QWaylandSurface; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTouch : public QWaylandObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandTouch : public QWaylandObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandTouch) diff --git a/src/compositor/compositor_api/qwaylandtouch_p.h b/src/compositor/compositor_api/qwaylandtouch_p.h index 0b87f8475..eb5d4e783 100644 --- a/src/compositor/compositor_api/qwaylandtouch_p.h +++ b/src/compositor/compositor_api/qwaylandtouch_p.h @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QTWAYLAND_QWLTOUCH_P_H #define QTWAYLAND_QWLTOUCH_P_H @@ -60,13 +24,14 @@ #include <QtWaylandCompositor/QWaylandCompositor> #include <QtCore/QPoint> +#include <QtCore/qvarlengtharray.h> #include <QtCore/private/qobject_p.h> #include <QtWaylandCompositor/private/qwayland-server-wayland.h> QT_BEGIN_NAMESPACE -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandTouchPrivate : public QObjectPrivate, public QtWaylandServer::wl_touch +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandTouchPrivate : public QObjectPrivate, public QtWaylandServer::wl_touch { Q_DECLARE_PUBLIC(QWaylandTouch) public: diff --git a/src/compositor/compositor_api/qwaylandview.cpp b/src/compositor/compositor_api/qwaylandview.cpp index 1a6bf1a64..f8a0f38af 100644 --- a/src/compositor/compositor_api/qwaylandview.cpp +++ b/src/compositor/compositor_api/qwaylandview.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandview.h" #include "qwaylandview_p.h" @@ -47,6 +11,7 @@ #include <QtWaylandCompositor/private/qwaylandoutput_p.h> #include <QtCore/QMutex> +#include <QtCore/qpointer.h> QT_BEGIN_NAMESPACE @@ -64,6 +29,7 @@ void QWaylandViewPrivate::markSurfaceAsDestroyed(QWaylandSurface *surface) /*! * \qmltype WaylandView + * \instantiates QWaylandView * \inqmlmodule QtWayland.Compositor * \since 5.8 * \brief Represents a view of a surface on an output. @@ -119,7 +85,7 @@ QObject *QWaylandView::renderObject() const } /*! - * \qmlproperty WaylandSurface QtWaylandCompositor::WaylandView::surface + * \qmlproperty WaylandSurface QtWayland.Compositor::WaylandView::surface * * This property holds the surface viewed by this WaylandView. */ @@ -178,7 +144,7 @@ void QWaylandView::setSurface(QWaylandSurface *newSurface) } /*! - * \qmlproperty WaylandOutput QtWaylandCompositor::WaylandView::output + * \qmlproperty WaylandOutput QtWayland.Compositor::WaylandView::output * * This property holds the output on which this view displays its surface. */ @@ -246,7 +212,8 @@ bool QWaylandView::advance() return false; if (d->surface && d->surface->primaryView() == this) { - Q_FOREACH (QWaylandView *view, d->surface->views()) { + const auto views = d->surface->views(); + for (QWaylandView *view : views) { if (view != this && view->allowDiscardFrontBuffer() && view->d_func()->currentBuffer == d->currentBuffer) view->discardCurrentBuffer(); } @@ -292,7 +259,7 @@ QRegion QWaylandView::currentDamage() } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandView::bufferLocked + * \qmlproperty bool QtWayland.Compositor::WaylandView::bufferLocked * * This property holds whether the view's buffer is currently locked. When * the buffer is locked, advance() will not advance to the next buffer and @@ -325,7 +292,7 @@ void QWaylandView::setBufferLocked(bool locked) emit bufferLockedChanged(); } /*! - * \qmlproperty bool QtWaylandCompositor::WaylandView::allowDiscardFrontBuffer + * \qmlproperty bool QtWayland.Compositor::WaylandView::allowDiscardFrontBuffer * * By default, the view locks the current buffer until advance() is called. Set this property * to true to allow Qt to release the buffer when the primary view is no longer using it. @@ -397,3 +364,5 @@ struct wl_resource *QWaylandView::surfaceResource() const } QT_END_NAMESPACE + +#include "moc_qwaylandview.cpp" diff --git a/src/compositor/compositor_api/qwaylandview.h b/src/compositor/compositor_api/qwaylandview.h index c98b81053..a48dae5f6 100644 --- a/src/compositor/compositor_api/qwaylandview.h +++ b/src/compositor/compositor_api/qwaylandview.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Jolla Ltd, author: <giulio.camuffo@jollamobile.com> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACEVIEW_H #define QWAYLANDSURFACEVIEW_H @@ -52,7 +16,7 @@ class QWaylandSurface; class QWaylandViewPrivate; class QWaylandOutput; -class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandView : public QObject +class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandView : public QObject { Q_OBJECT Q_DECLARE_PRIVATE(QWaylandView) @@ -61,6 +25,7 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandView : public QObject Q_PROPERTY(QWaylandOutput *output READ output WRITE setOutput NOTIFY outputChanged) Q_PROPERTY(bool bufferLocked READ isBufferLocked WRITE setBufferLocked NOTIFY bufferLockedChanged) Q_PROPERTY(bool allowDiscardFrontBuffer READ allowDiscardFrontBuffer WRITE setAllowDiscardFrontBuffer NOTIFY allowDiscardFrontBufferChanged) + Q_MOC_INCLUDE("qwaylandoutput.h") public: QWaylandView(QObject *renderObject = nullptr, QObject *parent = nullptr); ~QWaylandView() override; diff --git a/src/compositor/compositor_api/qwaylandview_p.h b/src/compositor/compositor_api/qwaylandview_p.h index e7f521afe..01f582738 100644 --- a/src/compositor/compositor_api/qwaylandview_p.h +++ b/src/compositor/compositor_api/qwaylandview_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QWAYLANDSURFACEVIEW_P_H #define QWAYLANDSURFACEVIEW_P_H |