Commit 3eb27e60 authored by Adrien Faveraux's avatar Adrien Faveraux Committed by Vlad Zahorodnii
Browse files

move idle Inhibitor to the news approach

parent 1e4621ef
......@@ -20,7 +20,7 @@
#include "../../src/server/buffer_interface.h"
#include "../../src/server/compositor_interface.h"
#include "../../src/server/display.h"
#include "../../src/server/idleinhibit_interface.h"
#include "../../src/server/idleinhibit_v1_interface.h"
#include "../../src/server/surface_interface.h"
// Wayland
#include <wayland-client-protocol.h>
......@@ -57,7 +57,7 @@ private Q_SLOTS:
private:
KWaylandServer::Display *m_display;
KWaylandServer::CompositorInterface *m_compositorInterface;
KWaylandServer::IdleInhibitManagerInterface *m_idleInhibitInterface;
KWaylandServer::IdleInhibitManagerV1Interface *m_idleInhibitInterface;
KWayland::Client::ConnectionThread *m_connection;
KWayland::Client::Compositor *m_compositor;
KWayland::Client::ShmPool *m_shm;
......@@ -91,10 +91,8 @@ void TestWaylandSurface::init()
m_compositorInterface = m_display->createCompositor(m_display);
QVERIFY(m_compositorInterface);
m_idleInhibitInterface = m_display->createIdleInhibitManager(IdleInhibitManagerInterfaceVersion::UnstableV1, m_display);
m_idleInhibitInterface = m_display->createIdleInhibitManagerV1(m_display);
QVERIFY(m_idleInhibitInterface);
m_idleInhibitInterface->create();
QVERIFY(m_idleInhibitInterface->isValid());
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
......
......@@ -21,8 +21,7 @@ set(SERVER_LIB_SRCS
filtered_display.cpp
global.cpp
idle_interface.cpp
idleinhibit_interface.cpp
idleinhibit_interface_v1.cpp
idleinhibit_v1_interface
keyboard_interface.cpp
keyboard_shortcuts_inhibit_v1_interface.cpp
keystate_interface.cpp
......@@ -183,7 +182,7 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
BASENAME xdg-foreign-unstable-v2
)
ecm_add_wayland_server_protocol(SERVER_LIB_SRCS
ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS
PROTOCOL ${WaylandProtocols_DATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml
BASENAME idle-inhibit-unstable-v1
)
......@@ -378,7 +377,7 @@ set(SERVER_LIB_HEADERS
filtered_display.h
global.h
idle_interface.h
idleinhibit_interface.h
idleinhibit_v1_interface.h
keyboard_interface.h
keyboard_shortcuts_inhibit_v1_interface.h
keystate_interface.h
......
......@@ -15,7 +15,7 @@
#include "eglstream_controller_interface.h"
#include "fakeinput_interface.h"
#include "idle_interface.h"
#include "idleinhibit_interface_p.h"
#include "idleinhibit_v1_interface_p.h"
#include "keyboard_shortcuts_inhibit_v1_interface.h"
#include "keystate_interface.h"
#include "linuxdmabuf_v1_interface.h"
......@@ -408,16 +408,11 @@ XdgForeignInterface *Display::createXdgForeignInterface(QObject *parent)
return foreign;
}
IdleInhibitManagerInterface *Display::createIdleInhibitManager(const IdleInhibitManagerInterfaceVersion &version, QObject *parent)
IdleInhibitManagerV1Interface *Display::createIdleInhibitManagerV1(QObject *parent)
{
IdleInhibitManagerInterface *i = nullptr;
switch (version) {
case IdleInhibitManagerInterfaceVersion::UnstableV1:
i = new IdleInhibitManagerUnstableV1Interface(this, parent);
break;
}
connect(this, &Display::aboutToTerminate, i, [i] { delete i; });
return i;
IdleInhibitManagerV1Interface *idleManager = new IdleInhibitManagerV1Interface(this, parent);
connect(this, &Display::aboutToTerminate, idleManager, [idleManager] { delete idleManager; });
return idleManager;
}
AppMenuManagerInterface *Display::createAppMenuManagerInterface(QObject *parent)
......
......@@ -38,8 +38,7 @@ class CompositorInterface;
class DataDeviceManagerInterface;
class DpmsManagerInterface;
class IdleInterface;
enum class IdleInhibitManagerInterfaceVersion;
class IdleInhibitManagerInterface;
class IdleInhibitManagerV1Interface;
class FakeInputInterface;
class OutputInterface;
class OutputDeviceInterface;
......@@ -245,7 +244,7 @@ public:
* @returns The created manager object
* @since 5.41
**/
IdleInhibitManagerInterface *createIdleInhibitManager(const IdleInhibitManagerInterfaceVersion &version, QObject *parent = nullptr);
IdleInhibitManagerV1Interface *createIdleInhibitManagerV1(QObject *parent = nullptr);
/**
* Creates the AppMenuManagerInterface in interface @p version.
......
/*
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "idleinhibit_interface_p.h"
namespace KWaylandServer
{
IdleInhibitManagerInterface::Private::Private(IdleInhibitManagerInterface *q, Display *d, const wl_interface *interface, quint32 version, IdleInhibitManagerInterfaceVersion interfaceVersion)
: Global::Private(d, interface, version)
, interfaceVersion(interfaceVersion)
, q(q)
{
}
IdleInhibitManagerInterface::IdleInhibitManagerInterface(Private *d, QObject *parent)
: Global(d, parent)
{
}
IdleInhibitManagerInterface::~IdleInhibitManagerInterface() = default;
IdleInhibitManagerInterfaceVersion IdleInhibitManagerInterface::interfaceVersion() const
{
Q_D();
return d->interfaceVersion;
}
IdleInhibitManagerInterface::Private *IdleInhibitManagerInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
}
/*
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_P_H
#define KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_P_H
#include "idleinhibit_interface.h"
#include "global_p.h"
#include "resource_p.h"
#include <wayland-idle-inhibit-unstable-v1-server-protocol.h>
namespace KWaylandServer
{
class Q_DECL_HIDDEN IdleInhibitManagerUnstableV1Interface : public IdleInhibitManagerInterface
{
Q_OBJECT
public:
explicit IdleInhibitManagerUnstableV1Interface(Display *display, QObject *parent = nullptr);
~IdleInhibitManagerUnstableV1Interface() override;
private:
class Private;
};
class Q_DECL_HIDDEN IdleInhibitManagerInterface::Private : public Global::Private
{
public:
IdleInhibitManagerInterfaceVersion interfaceVersion;
protected:
Private(IdleInhibitManagerInterface *q, Display *d, const wl_interface *interface, quint32 version, IdleInhibitManagerInterfaceVersion interfaceVersion);
IdleInhibitManagerInterface *q;
};
class Q_DECL_HIDDEN IdleInhibitorInterface : public Resource
{
Q_OBJECT
public:
explicit IdleInhibitorInterface(IdleInhibitManagerInterface *c, wl_resource *parentResource);
virtual ~IdleInhibitorInterface();
/**
* @returns The interface version used by this IdleInhibitorInterface
**/
IdleInhibitManagerInterfaceVersion interfaceVersion() const;
protected:
class Private;
private:
Private *d_func() const;
friend class IdleInhibitManagerUnstableV1Interface;
};
class Q_DECL_HIDDEN IdleInhibitorInterface::Private : public Resource::Private
{
public:
Private(IdleInhibitorInterface *q, IdleInhibitManagerInterface *m, wl_resource *parentResource);
~Private();
private:
IdleInhibitorInterface *q_func() {
return reinterpret_cast<IdleInhibitorInterface *>(q);
}
static const struct zwp_idle_inhibitor_v1_interface s_interface;
};
}
#endif
/*
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "idleinhibit_interface_p.h"
#include "display.h"
#include "surface_interface_p.h"
namespace KWaylandServer
{
class Q_DECL_HIDDEN IdleInhibitManagerUnstableV1Interface::Private : public IdleInhibitManagerInterface::Private
{
public:
Private(IdleInhibitManagerUnstableV1Interface *q, Display *d);
private:
void bind(wl_client *client, uint32_t version, uint32_t id) override;
static void unbind(wl_resource *resource);
static Private *cast(wl_resource *r) {
return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
}
static void destroyCallback(wl_client *client, wl_resource *resource);
static void createInhibitorCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
static const struct zwp_idle_inhibit_manager_v1_interface s_interface;
static const quint32 s_version;
};
const quint32 IdleInhibitManagerUnstableV1Interface::Private::s_version = 1;
#ifndef K_DOXYGEN
const struct zwp_idle_inhibit_manager_v1_interface IdleInhibitManagerUnstableV1Interface::Private::s_interface = {
destroyCallback,
createInhibitorCallback
};
#endif
IdleInhibitManagerUnstableV1Interface::Private::Private(IdleInhibitManagerUnstableV1Interface *q, Display *d)
: IdleInhibitManagerInterface::Private(q, d, &zwp_idle_inhibit_manager_v1_interface, s_version, IdleInhibitManagerInterfaceVersion::UnstableV1)
{
}
void IdleInhibitManagerUnstableV1Interface::Private::destroyCallback(wl_client *client, wl_resource *resource)
{
Q_UNUSED(client)
wl_resource_destroy(resource);
}
void IdleInhibitManagerUnstableV1Interface::Private::createInhibitorCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
{
auto s = SurfaceInterface::get(surface);
if (!s) {
// send error?
return;
}
auto q = cast(resource);
auto inhibitor = new IdleInhibitorInterface(q->q, resource);
inhibitor->d_func()->create(q->display->getConnection(client), version, id);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->installIdleInhibitor(inhibitor);
}
void IdleInhibitManagerUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
auto c = display->getConnection(client);
wl_resource *resource = c->createResource(&zwp_idle_inhibit_manager_v1_interface, qMin(version, s_version), id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &s_interface, this, unbind);
// TODO: should we track?
}
void IdleInhibitManagerUnstableV1Interface::Private::unbind(wl_resource *resource)
{
Q_UNUSED(resource)
// TODO: implement?
}
IdleInhibitManagerUnstableV1Interface::IdleInhibitManagerUnstableV1Interface(Display *display, QObject *parent)
: IdleInhibitManagerInterface(new Private(this, display), parent)
{
}
IdleInhibitManagerUnstableV1Interface::~IdleInhibitManagerUnstableV1Interface() = default;
#ifndef K_DOXYGEN
const struct zwp_idle_inhibitor_v1_interface IdleInhibitorInterface::Private::s_interface = {
resourceDestroyedCallback
};
#endif
IdleInhibitorInterface::Private::Private(IdleInhibitorInterface *q, IdleInhibitManagerInterface *c, wl_resource *parentResource)
: Resource::Private(q, c, parentResource, &zwp_idle_inhibitor_v1_interface, &s_interface)
{
}
IdleInhibitorInterface::Private::~Private()
{
if (resource) {
wl_resource_destroy(resource);
resource = nullptr;
}
}
IdleInhibitorInterface::IdleInhibitorInterface(IdleInhibitManagerInterface *m, wl_resource *parentResource)
: Resource(new Private(this, m, parentResource))
{
}
IdleInhibitorInterface::~IdleInhibitorInterface() = default;
IdleInhibitorInterface::Private *IdleInhibitorInterface::d_func() const
{
return reinterpret_cast<Private*>(d.data());
}
}
/*
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "idleinhibit_v1_interface_p.h"
#include "display.h"
#include "surface_interface_p.h"
namespace KWaylandServer
{
const quint32 IdleInhibitManagerV1InterfacePrivate::s_version = 1;
IdleInhibitManagerV1InterfacePrivate::IdleInhibitManagerV1InterfacePrivate(IdleInhibitManagerV1Interface *_q, Display *display)
: QtWaylandServer::zwp_idle_inhibit_manager_v1(*display, s_version)
, q(_q)
{
}
void IdleInhibitManagerV1InterfacePrivate::zwp_idle_inhibit_manager_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void IdleInhibitManagerV1InterfacePrivate::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *surface)
{
auto s = SurfaceInterface::get(surface);
if (!s) {
wl_resource_post_error(resource->handle, 0, "Invalid surface");
return;
}
wl_resource *inhibitorResource = wl_resource_create(resource->client(), &zwp_idle_inhibitor_v1_interface, resource->version(), id);
if (!inhibitorResource) {
wl_client_post_no_memory(resource->client());
return;
}
auto inhibitor = new IdleInhibitorV1Interface(inhibitorResource);
SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
surfacePrivate->installIdleInhibitor(inhibitor);
}
IdleInhibitManagerV1Interface::IdleInhibitManagerV1Interface(Display *display, QObject *parent)
: QObject(parent)
, d(new IdleInhibitManagerV1InterfacePrivate(this, display))
{
}
IdleInhibitManagerV1Interface::~IdleInhibitManagerV1Interface() = default;
IdleInhibitorV1Interface::IdleInhibitorV1Interface(wl_resource *resource)
: QObject(nullptr)
, QtWaylandServer::zwp_idle_inhibitor_v1(resource)
{
}
IdleInhibitorV1Interface::~IdleInhibitorV1Interface() = default;
void IdleInhibitorV1Interface::zwp_idle_inhibitor_v1_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void IdleInhibitorV1Interface::zwp_idle_inhibitor_v1_destroy_resource(Resource *resource)
{
Q_UNUSED(resource)
delete this;
}
}
......@@ -6,27 +6,17 @@
#ifndef KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_H
#define KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_H
#include "global.h"
#include "resource.h"
#include <QObject>
#include <KWaylandServer/kwaylandserver_export.h>
struct wl_resource;
namespace KWaylandServer
{
class Display;
/**
* Enum describing the interface versions the IdleInhibitManagerInterface can support.
*
* @since 5.41
**/
enum class IdleInhibitManagerInterfaceVersion {
/**
* zwp_idle_inhibit_manager_v1
**/
UnstableV1
};
class IdleInhibitManagerV1InterfacePrivate;
/**
* The IdleInhibitorManagerInterface is used by clients to inhibit idle on a
......@@ -35,26 +25,20 @@ enum class IdleInhibitManagerInterfaceVersion {
*
* @since 5.41
**/
class KWAYLANDSERVER_EXPORT IdleInhibitManagerInterface : public Global
class KWAYLANDSERVER_EXPORT IdleInhibitManagerV1Interface : public QObject
{
Q_OBJECT
public:
virtual ~IdleInhibitManagerInterface();
/**
* @returns The interface version used by this IdleInhibitManagerInterface
**/
IdleInhibitManagerInterfaceVersion interfaceVersion() const;
~IdleInhibitManagerV1Interface() override;
protected:
class Private;
explicit IdleInhibitManagerInterface(Private *d, QObject *parent = nullptr);
friend class Display;
explicit IdleInhibitManagerV1Interface(Display *display, QObject *parent = nullptr);
private:
Private *d_func() const;
QScopedPointer<IdleInhibitManagerV1InterfacePrivate> d;
};
}
#endif
/*
SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_P_H
#define KWAYLAND_SERVER_IDLEINHIBIT_INTERFACE_P_H
#include "idleinhibit_v1_interface.h"
#include <qwayland-server-idle-inhibit-unstable-v1.h>
namespace KWaylandServer
{
class IdleInhibitManagerV1InterfacePrivate : public QtWaylandServer::zwp_idle_inhibit_manager_v1
{
public:
IdleInhibitManagerV1InterfacePrivate(IdleInhibitManagerV1Interface *_q, Display *display);
static const quint32 s_version;
IdleInhibitManagerV1Interface *q;
protected:
void zwp_idle_inhibit_manager_v1_destroy(Resource *resource) override;
void zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *surface) override;
};
class IdleInhibitorV1Interface : public QObject, QtWaylandServer::zwp_idle_inhibitor_v1
{
Q_OBJECT
public:
explicit IdleInhibitorV1Interface(wl_resource *resource);
~IdleInhibitorV1Interface() override;
protected:
void zwp_idle_inhibitor_v1_destroy_resource(Resource *resource) override;
void zwp_idle_inhibitor_v1_destroy(Resource *resource) override;
};
}
#endif
......@@ -10,7 +10,7 @@
#include "clientconnection.h"
#include "compositor_interface.h"
#include "display.h"
#include "idleinhibit_interface_p.h"
#include "idleinhibit_v1_interface_p.h"
#include "pointerconstraints_interface_p.h"
#include "region_interface.h"
#include "subcompositor_interface.h"
......@@ -266,10 +266,10 @@ void SurfaceInterfacePrivate::installPointerConstraint(ConfinedPointerInterface
emit q->pointerConstraintsChanged();
}
void SurfaceInterfacePrivate::installIdleInhibitor(IdleInhibitorInterface *inhibitor)
void SurfaceInterfacePrivate::installIdleInhibitor(IdleInhibitorV1Interface *inhibitor)
{
idleInhibitors << inhibitor;
QObject::connect(inhibitor, &IdleInhibitorInterface::aboutToBeUnbound, q,
QObject::connect(inhibitor, &IdleInhibitorV1Interface::destroyed, q,
[this, inhibitor] {
idleInhibitors.removeOne(inhibitor);
if (idleInhibitors.isEmpty()) {
......
......@@ -17,7 +17,7 @@
namespace KWaylandServer
{
class IdleInhibitorInterface;
class IdleInhibitorV1Interface;
class SurfaceRole;
class ViewportInterface;
......@@ -86,7 +86,7 @@ public:
void setSlide(const QPointer<SlideInterface> &slide);
void installPointerConstraint(LockedPointerInterface *lock);
void installPointerConstraint(ConfinedPointerInterface *confinement);
void installIdleInhibitor(IdleInhibitorInterface *inhibitor);
void installIdleInhibitor(IdleInhibitorV1Interface *inhibitor);
void commitSubSurface();
void commit();
......@@ -116,7 +116,7 @@ public:
QPointer<LockedPointerInterface> lockedPointer;
QPointer<ConfinedPointerInterface> confinedPointer;
QHash<OutputInterface*, QMetaObject::Connection> outputDestroyedConnections;
QVector<IdleInhibitorInterface*> idleInhibitors;
QVector<IdleInhibitorV1Interface*> idleInhibitors;
ViewportInterface *viewportExtension = nullptr;
SurfaceInterface *dataProxy = nullptr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment