diff options
-rw-r--r-- | src/3rdparty/protocol/idle-inhibit-unstable-v1.xml | 83 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandsurface.cpp | 23 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandsurface.h | 4 | ||||
-rw-r--r-- | src/compositor/compositor_api/qwaylandsurface_p.h | 3 | ||||
-rw-r--r-- | src/compositor/extensions/extensions.pri | 4 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandidleinhibitv1.cpp | 185 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandidleinhibitv1.h | 61 | ||||
-rw-r--r-- | src/compositor/extensions/qwaylandidleinhibitv1_p.h | 88 | ||||
-rw-r--r-- | src/imports/compositor/qwaylandquickcompositorplugin.cpp | 4 | ||||
-rw-r--r-- | sync.profile | 2 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/compositor.pro | 3 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.cpp | 12 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.h | 3 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/tst_compositor.cpp | 39 |
14 files changed, 513 insertions, 1 deletions
diff --git a/src/3rdparty/protocol/idle-inhibit-unstable-v1.xml b/src/3rdparty/protocol/idle-inhibit-unstable-v1.xml new file mode 100644 index 000000000..9c06cdcba --- /dev/null +++ b/src/3rdparty/protocol/idle-inhibit-unstable-v1.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<protocol name="idle_inhibit_unstable_v1"> + + <copyright> + Copyright © 2015 Samsung Electronics Co., Ltd + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + </copyright> + + <interface name="zwp_idle_inhibit_manager_v1" version="1"> + <description summary="control behavior when display idles"> + This interface permits inhibiting the idle behavior such as screen + blanking, locking, and screensaving. The client binds the idle manager + globally, then creates idle-inhibitor objects for each surface. + + Warning! The protocol described in this file is experimental and + backward incompatible changes may be made. Backward compatible changes + may be added together with the corresponding interface version bump. + Backward incompatible changes are done by bumping the version number in + the protocol and interface names and resetting the interface version. + Once the protocol is to be declared stable, the 'z' prefix and the + version number in the protocol and interface names are removed and the + interface version number is reset. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the idle inhibitor object"> + Destroy the inhibit manager. + </description> + </request> + + <request name="create_inhibitor"> + <description summary="create a new inhibitor object"> + Create a new inhibitor object associated with the given surface. + </description> + <arg name="id" type="new_id" interface="zwp_idle_inhibitor_v1"/> + <arg name="surface" type="object" interface="wl_surface" + summary="the surface that inhibits the idle behavior"/> + </request> + + </interface> + + <interface name="zwp_idle_inhibitor_v1" version="1"> + <description summary="context object for inhibiting idle behavior"> + An idle inhibitor prevents the output that the associated surface is + visible on from being set to a state where it is not visually usable due + to lack of user interaction (e.g. blanked, dimmed, locked, set to power + save, etc.) Any screensaver processes are also blocked from displaying. + + If the surface is destroyed, unmapped, becomes occluded, loses + visibility, or otherwise becomes not visually relevant for the user, the + idle inhibitor will not be honored by the compositor; if the surface + subsequently regains visibility the inhibitor takes effect once again. + Likewise, the inhibitor isn't honored if the system was already idled at + the time the inhibitor was established, although if the system later + de-idles and re-idles the inhibitor will take effect. + </description> + + <request name="destroy" type="destructor"> + <description summary="destroy the idle inhibitor object"> + Remove the inhibitor effect from the associated wl_surface. + </description> + </request> + + </interface> +</protocol> diff --git a/src/compositor/compositor_api/qwaylandsurface.cpp b/src/compositor/compositor_api/qwaylandsurface.cpp index 433b53228..2265b41c0 100644 --- a/src/compositor/compositor_api/qwaylandsurface.cpp +++ b/src/compositor/compositor_api/qwaylandsurface.cpp @@ -764,6 +764,29 @@ bool QWaylandSurface::isCursorSurface() const return d->isCursorSurface; } +/*! + * \qmlproperty bool QtWaylandCompositor::WaylandSurface::inhibitsIdle + * + * 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 + * + * 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(); +} + #if QT_CONFIG(im) QWaylandInputMethodControl *QWaylandSurface::inputMethodControl() const { diff --git a/src/compositor/compositor_api/qwaylandsurface.h b/src/compositor/compositor_api/qwaylandsurface.h index 667f911c3..ecb53704a 100644 --- a/src/compositor/compositor_api/qwaylandsurface.h +++ b/src/compositor/compositor_api/qwaylandsurface.h @@ -92,6 +92,7 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandSurface : public QWaylandObject 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) public: enum Origin { @@ -148,6 +149,8 @@ public: void markAsCursorSurface(bool cursorSurface); bool isCursorSurface() const; + bool inhibitsIdle() const; + #if QT_CONFIG(im) QWaylandInputMethodControl *inputMethodControl() const; #endif @@ -181,6 +184,7 @@ Q_SIGNALS: void subsurfacePlaceBelow(QWaylandSurface *sibling); void dragStarted(QWaylandDrag *drag); void cursorSurfaceChanged(); + void inhibitsIdleChanged(); 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 1637d8704..97cb19d9b 100644 --- a/src/compositor/compositor_api/qwaylandsurface_p.h +++ b/src/compositor/compositor_api/qwaylandsurface_p.h @@ -74,6 +74,7 @@ #include <QtWaylandCompositor/private/qwayland-server-wayland.h> #include <QtWaylandCompositor/private/qwaylandviewporter_p.h> +#include <QtWaylandCompositor/private/qwaylandidleinhibitv1_p.h> QT_BEGIN_NAMESPACE @@ -167,6 +168,8 @@ public: //member variables QList<QPointer<QWaylandSurface>> subsurfaceChildren; + QVector<QWaylandIdleInhibitManagerV1Private::Inhibitor *> idleInhibitors; + QRegion inputRegion; QRegion opaqueRegion; diff --git a/src/compositor/extensions/extensions.pri b/src/compositor/extensions/extensions.pri index 027ea114b..c1a9f7882 100644 --- a/src/compositor/extensions/extensions.pri +++ b/src/compositor/extensions/extensions.pri @@ -15,6 +15,7 @@ WAYLANDSERVERSOURCES += \ ../3rdparty/protocol/xdg-shell.xml \ ../3rdparty/protocol/xdg-decoration-unstable-v1.xml \ ../3rdparty/protocol/ivi-application.xml \ + ../3rdparty/protocol/idle-inhibit-unstable-v1.xml \ HEADERS += \ extensions/qwlqttouch_p.h \ @@ -42,6 +43,8 @@ HEADERS += \ extensions/qwaylandxdgdecorationv1.h \ extensions/qwaylandxdgdecorationv1_p.h \ extensions/qwaylandshellsurface.h \ + extensions/qwaylandidleinhibitv1.h \ + extensions/qwaylandidleinhibitv1_p.h \ extensions/qwaylandiviapplication.h \ extensions/qwaylandiviapplication_p.h \ extensions/qwaylandivisurface.h \ @@ -62,6 +65,7 @@ SOURCES += \ extensions/qwaylandxdgshell.cpp \ extensions/qwaylandxdgdecorationv1.cpp \ extensions/qwaylandshellsurface.cpp \ + extensions/qwaylandidleinhibitv1.cpp \ extensions/qwaylandiviapplication.cpp \ extensions/qwaylandivisurface.cpp \ diff --git a/src/compositor/extensions/qwaylandidleinhibitv1.cpp b/src/compositor/extensions/qwaylandidleinhibitv1.cpp new file mode 100644 index 000000000..9e586a779 --- /dev/null +++ b/src/compositor/extensions/qwaylandidleinhibitv1.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtWaylandCompositor/QWaylandCompositor> +#include <QtWaylandCompositor/private/qwaylandsurface_p.h> + +#include "qwaylandidleinhibitv1_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QWaylandIdleInhibitManagerV1 + \inmodule QtWaylandCompositor + \since 5.14 + \brief Provides an extension that allows to inhibit the idle behavior of the compositor + \sa QWaylandSurface::inhibitsIdle + + The QWaylandIdleInhibitV1 extension provides a way for a client to inhibit the idle behavior of + the compositor when a specific surface is visually relevant to the user. + + QWaylandIdleInhibitManagerV1 corresponds to the Wayland interface, \c zwp_idle_inhibit_manager_v1. + + Inhibited surfaces have the QWaylandSurface::inhibitsIdle property set to \c true. +*/ + +/*! + \qmltype IdleInhibitManagerV1 + \inqmlmodule QtWayland.Compositor + \since 5.14 + \brief Provides an extension that allows to inhibit the idle behavior of the compositor + \sa WaylandSurface::inhibitsIdle + + The IdleInhibitManagerV1 extension provides a way for a client to inhibit the idle behavior of + the compositor when a specific surface is visually relevant to the user. + + IdleInhibitManagerV1 corresponds to the Wayland interface, \c zwp_idle_inhibit_manager_v1. + + To provide the functionality of the extension in a compositor, create an instance of the + IdleInhibitManagerV1 component and add it to the list of extensions supported by the compositor: + + \qml \QtMinorVersion + import QtWayland.Compositor 1.\1 + + WaylandCompositor { + IdleInhibitManagerV1 { + // ... + } + } + \endqml + + Inhibited surfaces have the WaylandSurface::inhibitsIdle property set to \c true. +*/ + +/*! + Constructs a QWaylandIdleInhibitManagerV1 object. +*/ +QWaylandIdleInhibitManagerV1::QWaylandIdleInhibitManagerV1() + : QWaylandCompositorExtensionTemplate<QWaylandIdleInhibitManagerV1>(*new QWaylandIdleInhibitManagerV1Private()) +{ +} + +/*! + Constructs a QWaylandIdleInhibitManagerV1 object for the provided \a compositor. +*/ +QWaylandIdleInhibitManagerV1::QWaylandIdleInhibitManagerV1(QWaylandCompositor *compositor) + : QWaylandCompositorExtensionTemplate<QWaylandIdleInhibitManagerV1>(compositor, *new QWaylandIdleInhibitManagerV1Private()) +{ +} + +/*! + Initializes the extension. +*/ +void QWaylandIdleInhibitManagerV1::initialize() +{ + Q_D(QWaylandIdleInhibitManagerV1); + + QWaylandCompositorExtensionTemplate::initialize(); + QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); + if (!compositor) { + qCWarning(qLcWaylandCompositor) << "Failed to find QWaylandCompositor when initializing QWaylandIdleInhibitManagerV1"; + return; + } + d->init(compositor->display(), d->interfaceVersion()); +} + +/*! + Returns the Wayland interface for the QWaylandIdleInhibitManagerV1. +*/ +const wl_interface *QWaylandIdleInhibitManagerV1::interface() +{ + return QWaylandIdleInhibitManagerV1Private::interface(); +} + + +void QWaylandIdleInhibitManagerV1Private::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint id, wl_resource *surfaceResource) +{ + auto *surface = QWaylandSurface::fromResource(surfaceResource); + if (!surface) { + qCWarning(qLcWaylandCompositor) << "Couldn't find surface requested for creating an inhibitor"; + wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT, + "invalid wl_surface@%d", wl_resource_get_id(surfaceResource)); + return; + } + + auto *surfacePrivate = QWaylandSurfacePrivate::get(surface); + if (!surfacePrivate) { + wl_resource_post_no_memory(resource->handle); + return; + } + + auto *inhibitor = new Inhibitor(surface, resource->client(), id, resource->version()); + if (!inhibitor) { + wl_resource_post_no_memory(resource->handle); + return; + } + surfacePrivate->idleInhibitors.append(inhibitor); + + if (surfacePrivate->idleInhibitors.size() == 1) + Q_EMIT surface->inhibitsIdleChanged(); +} + + +QWaylandIdleInhibitManagerV1Private::Inhibitor::Inhibitor(QWaylandSurface *surface, + wl_client *client, + quint32 id, quint32 version) + : QtWaylandServer::zwp_idle_inhibitor_v1(client, id, qMin<quint32>(version, interfaceVersion())) + , m_surface(surface) +{ + Q_ASSERT(surface); +} + +void QWaylandIdleInhibitManagerV1Private::Inhibitor::zwp_idle_inhibitor_v1_destroy_resource(Resource *resource) +{ + Q_UNUSED(resource); + delete this; +} + +void QWaylandIdleInhibitManagerV1Private::Inhibitor::zwp_idle_inhibitor_v1_destroy(Resource *resource) +{ + if (m_surface) { + auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface.data()); + Q_ASSERT(surfacePrivate->idleInhibitors.contains(this)); + surfacePrivate->idleInhibitors.removeOne(this); + + if (surfacePrivate->idleInhibitors.isEmpty()) + Q_EMIT m_surface.data()->inhibitsIdleChanged(); + } + + wl_resource_destroy(resource->handle); +} + +QT_END_NAMESPACE diff --git a/src/compositor/extensions/qwaylandidleinhibitv1.h b/src/compositor/extensions/qwaylandidleinhibitv1.h new file mode 100644 index 000000000..49e38fcfd --- /dev/null +++ b/src/compositor/extensions/qwaylandidleinhibitv1.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDIDLEINHIBITV1_H +#define QWAYLANDIDLEINHIBITV1_H + +#include <QtWaylandCompositor/QWaylandCompositorExtension> + +QT_BEGIN_NAMESPACE + +class QWaylandIdleInhibitManagerV1Private; + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIdleInhibitManagerV1 : public QWaylandCompositorExtensionTemplate<QWaylandIdleInhibitManagerV1> +{ + Q_OBJECT + Q_DECLARE_PRIVATE(QWaylandIdleInhibitManagerV1) +public: + explicit QWaylandIdleInhibitManagerV1(); + QWaylandIdleInhibitManagerV1(QWaylandCompositor *compositor); + + void initialize() override; + + static const struct wl_interface *interface(); +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIDLEINHIBITV1_H diff --git a/src/compositor/extensions/qwaylandidleinhibitv1_p.h b/src/compositor/extensions/qwaylandidleinhibitv1_p.h new file mode 100644 index 000000000..380551804 --- /dev/null +++ b/src/compositor/extensions/qwaylandidleinhibitv1_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtWaylandCompositor module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWAYLANDIDLEINHIBITV1_P_H +#define QWAYLANDIDLEINHIBITV1_P_H + +#include <QtWaylandCompositor/QWaylandSurface> +#include <QtWaylandCompositor/QWaylandIdleInhibitManagerV1> +#include <QtWaylandCompositor/private/qwaylandcompositorextension_p.h> +#include <QtWaylandCompositor/private/qwayland-server-idle-inhibit-unstable-v1.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. +// + +QT_BEGIN_NAMESPACE + +class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandIdleInhibitManagerV1Private + : public QWaylandCompositorExtensionPrivate + , public QtWaylandServer::zwp_idle_inhibit_manager_v1 +{ + Q_DECLARE_PUBLIC(QWaylandIdleInhibitManagerV1) +public: + explicit QWaylandIdleInhibitManagerV1Private() = default; + + class Q_WAYLAND_COMPOSITOR_EXPORT Inhibitor + : public QtWaylandServer::zwp_idle_inhibitor_v1 + { + public: + explicit Inhibitor(QWaylandSurface *surface, wl_client *client, quint32 id, quint32 version); + + protected: + void zwp_idle_inhibitor_v1_destroy_resource(Resource *resource) override; + void zwp_idle_inhibitor_v1_destroy(Resource *resource) override; + + private: + QPointer<QWaylandSurface> m_surface; + }; + + static QWaylandIdleInhibitManagerV1Private *get(QWaylandIdleInhibitManagerV1 *manager) { return manager ? manager->d_func() : nullptr; } + +protected: + void zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *surfaceResource) override; +}; + +QT_END_NAMESPACE + +#endif // QWAYLANDIDLEINHIBITV1_P_H diff --git a/src/imports/compositor/qwaylandquickcompositorplugin.cpp b/src/imports/compositor/qwaylandquickcompositorplugin.cpp index 949d2cfaa..5a6571ba4 100644 --- a/src/imports/compositor/qwaylandquickcompositorplugin.cpp +++ b/src/imports/compositor/qwaylandquickcompositorplugin.cpp @@ -66,6 +66,7 @@ #include <QtWaylandCompositor/QWaylandXdgShellV6> #include <QtWaylandCompositor/QWaylandXdgShell> #include <QtWaylandCompositor/QWaylandXdgDecorationManagerV1> +#include <QtWaylandCompositor/QWaylandIdleInhibitManagerV1> #include <QtWaylandCompositor/QWaylandIviApplication> #include <QtWaylandCompositor/QWaylandIviSurface> @@ -76,6 +77,7 @@ QT_BEGIN_NAMESPACE Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CONTAINER_CLASS(QWaylandQuickCompositor) Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandQtWindowManager) +Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandIdleInhibitManagerV1) Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandIviApplication) Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandWlScaler) Q_COMPOSITOR_DECLARE_QUICK_EXTENSION_CLASS(QWaylandWlShell) @@ -185,6 +187,8 @@ public: qmlRegisterType<QWaylandXdgDecorationManagerV1QuickExtension>(uri, 1, 3, "XdgDecorationManagerV1"); qmlRegisterType<QWaylandWlScalerQuickExtension>(uri, 1, 13, "WlScaler"); + + qmlRegisterType<QWaylandIdleInhibitManagerV1QuickExtension>(uri, 1, 14, "IdleInhibitManagerV1"); } }; //![class decl] diff --git a/sync.profile b/sync.profile index 4d9099e94..be25721fc 100644 --- a/sync.profile +++ b/sync.profile @@ -57,6 +57,7 @@ "$basedir/src/compositor" => [ "^qwayland-server-wayland.h", "^qwayland-server-hardware-integration.h", + "^qwayland-server-idle-inhibit-unstable-v1.h", "^qwayland-server-ivi-application.h", "^qwayland-server-qt-windowmanager.h", "^qwayland-server-qt-key-unstable-v1.h", @@ -70,6 +71,7 @@ "^qwayland-server-xdg-shell-unstable-v6.h", "^qwayland-server-xdg-shell.h", "^wayland-hardware-integration-server-protocol.h", + "^wayland-idle-inhibit-unstable-v1-server-protocol.h", "^wayland-ivi-application-server-protocol.h", "^wayland-qt-windowmanager-server-protocol.h", "^wayland-qt-key-unstable-v1-server-protocol.h", diff --git a/tests/auto/compositor/compositor/compositor.pro b/tests/auto/compositor/compositor/compositor.pro index 500a92c61..8a364e52c 100644 --- a/tests/auto/compositor/compositor/compositor.pro +++ b/tests/auto/compositor/compositor/compositor.pro @@ -14,7 +14,8 @@ WAYLANDCLIENTSOURCES += \ ../../../../src/3rdparty/protocol/ivi-application.xml \ ../../../../src/3rdparty/protocol/wayland.xml \ ../../../../src/3rdparty/protocol/xdg-shell.xml \ - ../../../../src/3rdparty/protocol/viewporter.xml + ../../../../src/3rdparty/protocol/viewporter.xml \ + ../../../../src/3rdparty/protocol/idle-inhibit-unstable-v1.xml SOURCES += \ tst_compositor.cpp \ diff --git a/tests/auto/compositor/compositor/mockclient.cpp b/tests/auto/compositor/compositor/mockclient.cpp index fa4d4c6b3..4ae04998e 100644 --- a/tests/auto/compositor/compositor/mockclient.cpp +++ b/tests/auto/compositor/compositor/mockclient.cpp @@ -184,6 +184,8 @@ void MockClient::handleGlobal(uint32_t id, const QByteArray &interface) } else if (interface == "wl_seat") { wl_seat *s = static_cast<wl_seat *>(wl_registry_bind(registry, id, &wl_seat_interface, 1)); m_seats << new MockSeat(s); + } else if (interface == "zwp_idle_inhibit_manager_v1") { + idleInhibitManager = static_cast<zwp_idle_inhibit_manager_v1 *>(wl_registry_bind(registry, id, &zwp_idle_inhibit_manager_v1_interface, 1)); } } @@ -222,6 +224,16 @@ ivi_surface *MockClient::createIviSurface(wl_surface *surface, uint iviId) return ivi_application_surface_create(iviApplication, iviId, surface); } +zwp_idle_inhibitor_v1 *MockClient::createIdleInhibitor(wl_surface *surface) +{ + flushDisplay(); + + auto *idleInhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor( + idleInhibitManager, surface); + zwp_idle_inhibitor_v1_set_user_data(idleInhibitor, this); + return idleInhibitor; +} + ShmBuffer::ShmBuffer(const QSize &size, wl_shm *shm) { int stride = size.width() * 4; diff --git a/tests/auto/compositor/compositor/mockclient.h b/tests/auto/compositor/compositor/mockclient.h index b537e9df1..aa20a7ac7 100644 --- a/tests/auto/compositor/compositor/mockclient.h +++ b/tests/auto/compositor/compositor/mockclient.h @@ -30,6 +30,7 @@ #include <qwayland-xdg-shell.h> #include <wayland-ivi-application-client-protocol.h> #include "wayland-viewporter-client-protocol.h" +#include "wayland-idle-inhibit-unstable-v1-client-protocol.h" #include <QObject> #include <QImage> @@ -63,6 +64,7 @@ public: xdg_surface *createXdgSurface(wl_surface *surface); xdg_toplevel *createXdgToplevel(xdg_surface *xdgSurface); ivi_surface *createIviSurface(wl_surface *surface, uint iviId); + zwp_idle_inhibitor_v1 *createIdleInhibitor(wl_surface *surface); wl_display *display = nullptr; wl_compositor *compositor = nullptr; @@ -73,6 +75,7 @@ public: xdg_wm_base *xdgWmBase = nullptr; wp_viewporter *viewporter = nullptr; ivi_application *iviApplication = nullptr; + zwp_idle_inhibit_manager_v1 *idleInhibitManager = nullptr; QList<MockSeat *> m_seats; diff --git a/tests/auto/compositor/compositor/tst_compositor.cpp b/tests/auto/compositor/compositor/tst_compositor.cpp index da5acc278..4749d8575 100644 --- a/tests/auto/compositor/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/compositor/tst_compositor.cpp @@ -47,8 +47,10 @@ #include <QtWaylandCompositor/QWaylandResource> #include <QtWaylandCompositor/QWaylandKeymap> #include <QtWaylandCompositor/QWaylandViewporter> +#include <QtWaylandCompositor/QWaylandIdleInhibitManagerV1> #include <qwayland-xdg-shell.h> #include <qwayland-ivi-application.h> +#include <QtWaylandCompositor/private/qwaylandsurface_p.h> #include <QtTest/QtTest> @@ -111,6 +113,8 @@ private slots: void viewportDestinationNoSurfaceError(); void viewportSourceNoSurfaceError(); void viewportHiDpi(); + + void idleInhibit(); }; void tst_WaylandCompositor::init() { @@ -1716,5 +1720,40 @@ void tst_WaylandCompositor::viewportHiDpi() wl_surface_destroy(surface); } +class IdleInhibitCompositor : public TestCompositor +{ + Q_OBJECT +public: + IdleInhibitCompositor() : idleInhibitManager(this) {} + QWaylandIdleInhibitManagerV1 idleInhibitManager; +}; + +void tst_WaylandCompositor::idleInhibit() +{ + IdleInhibitCompositor compositor; + compositor.create(); + MockClient client; + QTRY_VERIFY(client.idleInhibitManager); + + auto *surface = client.createSurface(); + QVERIFY(surface); + QTRY_COMPARE(compositor.surfaces.size(), 1); + + QWaylandSurface *waylandSurface = compositor.surfaces.at(0); + auto *waylandSurfacePrivate = + QWaylandSurfacePrivate::get(waylandSurface); + QVERIFY(waylandSurfacePrivate); + + QSignalSpy changedSpy(waylandSurface, SIGNAL(inhibitsIdleChanged())); + + QCOMPARE(waylandSurface->inhibitsIdle(), false); + + auto *idleInhibitor = client.createIdleInhibitor(surface); + QVERIFY(idleInhibitor); + QTRY_COMPARE(waylandSurfacePrivate->idleInhibitors.size(), 1); + QCOMPARE(waylandSurface->inhibitsIdle(), true); + QTRY_COMPARE(changedSpy.count(), 1); +} + #include <tst_compositor.moc> QTEST_MAIN(tst_WaylandCompositor); |