protocols: add version 2 of ext-idle-notify-v1 protocol (#8959)
Signed-off-by: James Ramsey <james.jehiel.ramsey@gmail.com> Co-authored-by: James Ramsey <james.jehiel.ramsey@gmail.com>
This commit is contained in:
parent
f2d43e5f21
commit
f83fe9986b
4 changed files with 26 additions and 13 deletions
|
|
@ -10,7 +10,8 @@ static int onTimer(SP<CEventLoopTimer> self, void* data) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_) : resource(resource_), timeoutMs(timeoutMs_) {
|
||||
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_, bool obeyInhibitors_) :
|
||||
resource(resource_), timeoutMs(timeoutMs_), obeyInhibitors(obeyInhibitors_) {
|
||||
if UNLIKELY (!resource_->resource())
|
||||
return;
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ bool CExtIdleNotification::good() {
|
|||
}
|
||||
|
||||
void CExtIdleNotification::updateTimer() {
|
||||
if (PROTO::idle->isInhibited)
|
||||
if (PROTO::idle->isInhibited && obeyInhibitors)
|
||||
timer->updateTimeout(std::nullopt);
|
||||
else
|
||||
timer->updateTimeout(std::chrono::milliseconds(timeoutMs));
|
||||
|
|
@ -54,6 +55,10 @@ void CExtIdleNotification::onActivity() {
|
|||
updateTimer();
|
||||
}
|
||||
|
||||
bool CExtIdleNotification::inhibitorsAreObeyed() const {
|
||||
return obeyInhibitors;
|
||||
}
|
||||
|
||||
CIdleNotifyProtocol::CIdleNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
|
||||
;
|
||||
}
|
||||
|
|
@ -63,7 +68,10 @@ void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ve
|
|||
RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); });
|
||||
|
||||
RESOURCE->setDestroy([this](CExtIdleNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
|
||||
RESOURCE->setGetIdleNotification([this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat); });
|
||||
RESOURCE->setGetIdleNotification(
|
||||
[this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat, true); });
|
||||
RESOURCE->setGetInputIdleNotification(
|
||||
[this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat, false); });
|
||||
}
|
||||
|
||||
void CIdleNotifyProtocol::onManagerResourceDestroy(wl_resource* res) {
|
||||
|
|
@ -74,9 +82,10 @@ void CIdleNotifyProtocol::destroyNotification(CExtIdleNotification* notif) {
|
|||
std::erase_if(m_vNotifications, [&](const auto& other) { return other.get() == notif; });
|
||||
}
|
||||
|
||||
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) {
|
||||
const auto CLIENT = pMgr->client();
|
||||
const auto RESOURCE = m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout)).get();
|
||||
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors) {
|
||||
const auto CLIENT = pMgr->client();
|
||||
const auto RESOURCE =
|
||||
m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout, obeyInhibitors)).get();
|
||||
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
pMgr->noMemory();
|
||||
|
|
@ -94,6 +103,7 @@ void CIdleNotifyProtocol::onActivity() {
|
|||
void CIdleNotifyProtocol::setInhibit(bool inhibited) {
|
||||
isInhibited = inhibited;
|
||||
for (auto const& n : m_vNotifications) {
|
||||
n->onActivity();
|
||||
if (n->inhibitorsAreObeyed())
|
||||
n->onActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue