wayland: slightly simplify idle inhibit implementation

This commit is contained in:
Xaver Hugl 2024-02-14 20:57:26 +01:00
parent f303ba4b59
commit b7e5d3f232
4 changed files with 30 additions and 30 deletions

View file

@ -22,23 +22,11 @@ void IdleInhibitManagerV1InterfacePrivate::zwp_idle_inhibit_manager_v1_destroy(R
wl_resource_destroy(resource->handle);
}
void IdleInhibitManagerV1InterfacePrivate::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *surface)
void IdleInhibitManagerV1InterfacePrivate::zwp_idle_inhibit_manager_v1_create_inhibitor(Resource *resource, uint32_t id, wl_resource *wlsurface)
{
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);
const auto surface = SurfaceInterface::get(wlsurface);
const auto inhibitor = new IdleInhibitorV1Interface(resource->client(), id, resource->version(), surface);
SurfaceInterfacePrivate::get(surface)->installIdleInhibitor(inhibitor);
}
IdleInhibitManagerV1Interface::IdleInhibitManagerV1Interface(Display *display, QObject *parent)
@ -49,13 +37,18 @@ IdleInhibitManagerV1Interface::IdleInhibitManagerV1Interface(Display *display, Q
IdleInhibitManagerV1Interface::~IdleInhibitManagerV1Interface() = default;
IdleInhibitorV1Interface::IdleInhibitorV1Interface(wl_resource *resource)
: QObject(nullptr)
, QtWaylandServer::zwp_idle_inhibitor_v1(resource)
IdleInhibitorV1Interface::IdleInhibitorV1Interface(wl_client *client, uint32_t id, uint32_t version, SurfaceInterface *surface)
: QtWaylandServer::zwp_idle_inhibitor_v1(client, id, version)
, m_surface(surface)
{
}
IdleInhibitorV1Interface::~IdleInhibitorV1Interface() = default;
IdleInhibitorV1Interface::~IdleInhibitorV1Interface()
{
if (m_surface) {
SurfaceInterfacePrivate::get(m_surface)->removeIdleInhibitor(this);
}
}
void IdleInhibitorV1Interface::zwp_idle_inhibitor_v1_destroy(Resource *resource)
{

View file

@ -7,10 +7,14 @@
#include "idleinhibit_v1.h"
#include <QPointer>
#include <qwayland-server-idle-inhibit-unstable-v1.h>
namespace KWin
{
class SurfaceInterface;
class IdleInhibitManagerV1InterfacePrivate : public QtWaylandServer::zwp_idle_inhibit_manager_v1
{
public:
@ -23,16 +27,16 @@ protected:
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
class IdleInhibitorV1Interface : QtWaylandServer::zwp_idle_inhibitor_v1
{
Q_OBJECT
public:
explicit IdleInhibitorV1Interface(wl_resource *resource);
explicit IdleInhibitorV1Interface(wl_client *client, uint32_t id, uint32_t version, SurfaceInterface *surface);
~IdleInhibitorV1Interface() override;
protected:
void zwp_idle_inhibitor_v1_destroy_resource(Resource *resource) override;
void zwp_idle_inhibitor_v1_destroy(Resource *resource) override;
};
const QPointer<SurfaceInterface> m_surface;
};
}

View file

@ -257,17 +257,19 @@ void SurfaceInterfacePrivate::installPointerConstraint(ConfinedPointerV1Interfac
void SurfaceInterfacePrivate::installIdleInhibitor(IdleInhibitorV1Interface *inhibitor)
{
idleInhibitors << inhibitor;
QObject::connect(inhibitor, &IdleInhibitorV1Interface::destroyed, q, [this, inhibitor] {
idleInhibitors.removeOne(inhibitor);
if (idleInhibitors.isEmpty()) {
Q_EMIT q->inhibitsIdleChanged();
}
});
if (idleInhibitors.count() == 1) {
Q_EMIT q->inhibitsIdleChanged();
}
}
void SurfaceInterfacePrivate::removeIdleInhibitor(IdleInhibitorV1Interface *inhibitor)
{
idleInhibitors.removeOne(inhibitor);
if (idleInhibitors.isEmpty()) {
Q_EMIT q->inhibitsIdleChanged();
}
}
void SurfaceInterfacePrivate::surface_destroy_resource(Resource *)
{
Q_EMIT q->aboutToBeDestroyed();

View file

@ -114,6 +114,7 @@ public:
void installPointerConstraint(LockedPointerV1Interface *lock);
void installPointerConstraint(ConfinedPointerV1Interface *confinement);
void installIdleInhibitor(IdleInhibitorV1Interface *inhibitor);
void removeIdleInhibitor(IdleInhibitorV1Interface *inhibitor);
QRectF computeBufferSourceBox() const;
void applyState(SurfaceState *next);