2024-04-21 17:29:30 +02:00
|
|
|
#include "IdleInhibit.hpp"
|
2024-06-08 10:07:59 +02:00
|
|
|
#include "core/Compositor.hpp"
|
2024-04-21 17:29:30 +02:00
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
CIdleInhibitor::CIdleInhibitor(SP<CIdleInhibitorResource> resource_, SP<CWLSurfaceResource> surf_) : resource(resource_), surface(surf_) {
|
2024-04-21 17:29:30 +02:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
CIdleInhibitorResource::CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, SP<CWLSurfaceResource> surface_) : resource(resource_), surface(surface_) {
|
|
|
|
listeners.destroySurface = surface->events.destroy.registerListener([this](std::any d) {
|
|
|
|
surface.reset();
|
|
|
|
listeners.destroySurface.reset();
|
|
|
|
destroySent = true;
|
|
|
|
events.destroy.emit();
|
|
|
|
});
|
2024-04-21 17:29:30 +02:00
|
|
|
|
|
|
|
resource->setOnDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
|
|
|
|
resource->setDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
|
|
|
|
}
|
|
|
|
|
|
|
|
CIdleInhibitorResource::~CIdleInhibitorResource() {
|
2024-04-24 20:15:01 +02:00
|
|
|
if (!destroySent)
|
|
|
|
events.destroy.emit();
|
2024-04-21 17:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CIdleInhibitProtocol::CIdleInhibitProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIdleInhibitProtocol::onManagerResourceDestroy(wl_resource* res) {
|
|
|
|
std::erase_if(m_vManagers, [res](const auto& other) { return other->resource() == res; });
|
|
|
|
}
|
|
|
|
|
|
|
|
void CIdleInhibitProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
|
|
|
const auto RESOURCE = m_vManagers.emplace_back(std::make_unique<CZwpIdleInhibitManagerV1>(client, ver, id)).get();
|
|
|
|
RESOURCE->setOnDestroy([this](CZwpIdleInhibitManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
|
|
|
|
|
|
|
|
RESOURCE->setDestroy([this](CZwpIdleInhibitManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
|
|
|
RESOURCE->setCreateInhibitor(
|
2024-06-08 10:07:59 +02:00
|
|
|
[this](CZwpIdleInhibitManagerV1* pMgr, uint32_t id, wl_resource* surface) { this->onCreateInhibitor(pMgr, id, CWLSurfaceResource::fromResource(surface)); });
|
2024-04-21 17:29:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CIdleInhibitProtocol::removeInhibitor(CIdleInhibitorResource* resource) {
|
|
|
|
std::erase_if(m_vInhibitors, [resource](const auto& el) { return el.get() == resource; });
|
|
|
|
}
|
|
|
|
|
2024-06-08 10:07:59 +02:00
|
|
|
void CIdleInhibitProtocol::onCreateInhibitor(CZwpIdleInhibitManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface) {
|
2024-05-01 20:40:35 +02:00
|
|
|
const auto CLIENT = pMgr->client();
|
2024-05-05 18:16:00 +02:00
|
|
|
const auto RESOURCE = m_vInhibitors.emplace_back(makeShared<CIdleInhibitorResource>(makeShared<CZwpIdleInhibitorV1>(CLIENT, pMgr->version(), id), surface));
|
2024-04-21 17:29:30 +02:00
|
|
|
|
2024-05-05 18:16:00 +02:00
|
|
|
RESOURCE->inhibitor = makeShared<CIdleInhibitor>(RESOURCE, surface);
|
2024-04-21 17:29:30 +02:00
|
|
|
events.newIdleInhibitor.emit(RESOURCE->inhibitor);
|
|
|
|
}
|