Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#include <QtWaylandCompositor/QWaylandCompositor>
5#include <QtWaylandCompositor/private/qwaylandsurface_p.h>
6
8
10
62
70
75
80{
82
85 if (!compositor) {
86 qCWarning(qLcWaylandCompositor) << "Failed to find QWaylandCompositor when initializing QWaylandIdleInhibitManagerV1";
87 return;
88 }
89 d->init(compositor->display(), d->interfaceVersion());
90}
91
96{
97 return QWaylandIdleInhibitManagerV1Private::interface();
98}
99
100
101void QWaylandIdleInhibitManagerV1Private::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint id, wl_resource *surfaceResource)
102{
103 auto *surface = QWaylandSurface::fromResource(surfaceResource);
104 if (!surface) {
105 qCWarning(qLcWaylandCompositor) << "Couldn't find surface requested for creating an inhibitor";
106 wl_resource_post_error(resource->handle, WL_DISPLAY_ERROR_INVALID_OBJECT,
107 "invalid wl_surface@%d", wl_resource_get_id(surfaceResource));
108 return;
109 }
110
111 auto *surfacePrivate = QWaylandSurfacePrivate::get(surface);
112 if (!surfacePrivate) {
113 wl_resource_post_no_memory(resource->handle);
114 return;
115 }
116
117 auto *inhibitor = new Inhibitor(surface, resource->client(), id, resource->version());
118 if (!inhibitor) {
119 wl_resource_post_no_memory(resource->handle);
120 return;
121 }
122 surfacePrivate->idleInhibitors.append(inhibitor);
123
124 if (surfacePrivate->idleInhibitors.size() == 1)
125 Q_EMIT surface->inhibitsIdleChanged();
126}
127
128
130 wl_client *client,
131 quint32 id, quint32 version)
132 : QtWaylandServer::zwp_idle_inhibitor_v1(client, id, qMin<quint32>(version, interfaceVersion()))
133 , m_surface(surface)
134{
135 Q_ASSERT(surface);
136}
137
139{
140 Q_UNUSED(resource);
141 delete this;
142}
143
145{
146 if (m_surface) {
147 auto *surfacePrivate = QWaylandSurfacePrivate::get(m_surface.data());
148 Q_ASSERT(surfacePrivate->idleInhibitors.contains(this));
149 surfacePrivate->idleInhibitors.removeOne(this);
150
151 if (surfacePrivate->idleInhibitors.isEmpty())
152 Q_EMIT m_surface.data()->inhibitsIdleChanged();
153 }
154
155 wl_resource_destroy(resource->handle);
156}
157
159
160#include "moc_qwaylandidleinhibitv1.cpp"
virtual void initialize()
Initializes the QWaylandCompositorExtension.
\qmltype WaylandCompositor \instantiates QWaylandCompositor \inqmlmodule QtWayland....
void zwp_idle_inhibitor_v1_destroy(Resource *resource) override
Inhibitor(QWaylandSurface *surface, wl_client *client, quint32 id, quint32 version)
void zwp_idle_inhibitor_v1_destroy_resource(Resource *resource) override
void zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *surfaceResource) override
\inmodule QtWaylandCompositor
static const struct wl_interface * interface()
Returns the Wayland interface for the QWaylandIdleInhibitManagerV1.
~QWaylandIdleInhibitManagerV1()
Destructs a QWaylandIdleInhibitManagerV1 object.
QWaylandIdleInhibitManagerV1()
Constructs a QWaylandIdleInhibitManagerV1 object.
void initialize() override
Initializes the extension.
static QWaylandSurfacePrivate * get(QWaylandSurface *surface)
\qmltype WaylandSurface \instantiates QWaylandSurface \inqmlmodule QtWayland.Compositor
static QWaylandSurface * fromResource(::wl_resource *resource)
Returns the QWaylandSurface corresponding to the Wayland resource resource.
Combined button and popup list for selecting options.
#define qCWarning(category,...)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
static QOpenGLCompositor * compositor
GLenum GLuint id
[7]
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_EMIT
#define Q_UNUSED(x)
unsigned int quint32
Definition qtypes.h:50
unsigned int uint
Definition qtypes.h:34