Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandidleinhibitv1.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:critical reason:network-protocol
4
5#include <QtWaylandCompositor/QWaylandCompositor>
6#include <QtWaylandCompositor/private/qwaylandsurface_p.h>
7
9
11
12/*!
13 \class QWaylandIdleInhibitManagerV1
14 \inmodule QtWaylandCompositor
15 \since 5.14
16 \brief Provides an extension that allows to inhibit the idle behavior of the compositor.
17 \sa QWaylandSurface::inhibitsIdle
18
19 The QWaylandIdleInhibitV1 extension provides a way for a client to inhibit the idle behavior of
20 the compositor when a specific surface is visually relevant to the user.
21
22 QWaylandIdleInhibitManagerV1 corresponds to the Wayland interface, \c zwp_idle_inhibit_manager_v1.
23
24 Inhibited surfaces have the QWaylandSurface::inhibitsIdle property set to \c true.
25*/
26
27/*!
28 \qmltype IdleInhibitManagerV1
29 \nativetype QWaylandIdleInhibitManagerV1
30 \inqmlmodule QtWayland.Compositor
31 \since 5.14
32 \brief Provides an extension that allows to inhibit the idle behavior of the compositor.
33 \sa WaylandSurface::inhibitsIdle
34
35 The IdleInhibitManagerV1 extension provides a way for a client to inhibit the idle behavior of
36 the compositor when a specific surface is visually relevant to the user.
37
38 IdleInhibitManagerV1 corresponds to the Wayland interface, \c zwp_idle_inhibit_manager_v1.
39
40 To provide the functionality of the extension in a compositor, create an instance of the
41 IdleInhibitManagerV1 component and add it to the list of extensions supported by the compositor:
42
43 \qml
44 import QtWayland.Compositor
45
46 WaylandCompositor {
47 IdleInhibitManagerV1 {
48 // ...
49 }
50 }
51 \endqml
52
53 Inhibited surfaces have the WaylandSurface::inhibitsIdle property set to \c true.
54*/
55
56/*!
57 Constructs a QWaylandIdleInhibitManagerV1 object.
58*/
59QWaylandIdleInhibitManagerV1::QWaylandIdleInhibitManagerV1()
60 : QWaylandCompositorExtensionTemplate<QWaylandIdleInhibitManagerV1>(*new QWaylandIdleInhibitManagerV1Private())
61{
62}
63
64/*!
65 Constructs a QWaylandIdleInhibitManagerV1 object for the provided \a compositor.
66*/
67QWaylandIdleInhibitManagerV1::QWaylandIdleInhibitManagerV1(QWaylandCompositor *compositor)
68 : QWaylandCompositorExtensionTemplate<QWaylandIdleInhibitManagerV1>(compositor, *new QWaylandIdleInhibitManagerV1Private())
69{
70}
71
72/*!
73 Destructs a QWaylandIdleInhibitManagerV1 object.
74*/
75QWaylandIdleInhibitManagerV1::~QWaylandIdleInhibitManagerV1() = default;
76
77/*!
78 Initializes the extension.
79*/
80void QWaylandIdleInhibitManagerV1::initialize()
81{
82 Q_D(QWaylandIdleInhibitManagerV1);
83
84 QWaylandCompositorExtensionTemplate::initialize();
85 QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
86 if (!compositor) {
87 qCWarning(qLcWaylandCompositor) << "Failed to find QWaylandCompositor when initializing QWaylandIdleInhibitManagerV1";
88 return;
89 }
90 d->init(compositor->display(), d->interfaceVersion());
91}
92
93/*!
94 Returns the Wayland interface for the QWaylandIdleInhibitManagerV1.
95*/
96const wl_interface *QWaylandIdleInhibitManagerV1::interface()
97{
98 return QWaylandIdleInhibitManagerV1Private::interface();
99}
100
101
102void QWaylandIdleInhibitManagerV1Private::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint id, wl_resource *surfaceResource)
103{
104 auto *surface = QWaylandSurface::fromResource(surfaceResource);
105 if (!surface) {
106 qCWarning(qLcWaylandCompositor) << "Couldn't find surface requested for creating an inhibitor";
107 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
108 "invalid wl_surface@%d", wl_resource_get_id(surfaceResource));
109 return;
110 }
111
112 auto *surfacePrivate = QWaylandSurfacePrivate::get(surface);
113 if (!surfacePrivate) {
114 wl_resource_post_no_memory(resource->handle);
115 return;
116 }
117
118 auto *inhibitor = new Inhibitor(surface, resource->client(), id, resource->version());
119 if (!inhibitor) {
120 wl_resource_post_no_memory(resource->handle);
121 return;
122 }
123 surfacePrivate->idleInhibitors.append(inhibitor);
124
125 if (surfacePrivate->idleInhibitors.size() == 1)
126 Q_EMIT surface->inhibitsIdleChanged();
127}
128
129
130QWaylandIdleInhibitManagerV1Private::Inhibitor::Inhibitor(QWaylandSurface *surface,
131 wl_client *client,
132 quint32 id, quint32 version)
133 : QtWaylandServer::zwp_idle_inhibitor_v1(client, id, qMin<quint32>(version, interfaceVersion()))
134 , m_surface(surface)
135{
136 Q_ASSERT(surface);
137}
138
139void QWaylandIdleInhibitManagerV1Private::Inhibitor::zwp_idle_inhibitor_v1_destroy_resource(Resource *resource)
140{
141 Q_UNUSED(resource);
142 delete this;
143}
144
145void QWaylandIdleInhibitManagerV1Private::Inhibitor::zwp_idle_inhibitor_v1_destroy(Resource *resource)
146{
147 if (m_surface) {
148 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface.data());
149 Q_ASSERT(surfacePrivate->idleInhibitors.contains(this));
150 surfacePrivate->idleInhibitors.removeOne(this);
151
152 if (surfacePrivate->idleInhibitors.isEmpty())
153 Q_EMIT m_surface.data()->inhibitsIdleChanged();
154 }
155
156 wl_resource_destroy(resource->handle);
157}
158
159QT_END_NAMESPACE
160
161#include "moc_qwaylandidleinhibitv1.cpp"
Combined button and popup list for selecting options.