Skip to content

Commit

Permalink
Update code to use amended ext-idle-notify protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
James Ramsey committed Jan 16, 2025
1 parent 0dc7367 commit 58df01c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/managers/ProtocolManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ CProtocolManager::CProtocolManager() {
PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints");
PROTO::outputPower = std::make_unique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower");
PROTO::activation = std::make_unique<CXDGActivationProtocol>(&xdg_activation_v1_interface, 1, "XDGActivation");
PROTO::idle = std::make_unique<CIdleNotifyProtocol>(&ext_idle_notifier_v1_interface, 1, "IdleNotify");
PROTO::idle = std::make_unique<CIdleNotifyProtocol>(&ext_idle_notifier_v1_interface, 2, "IdleNotify");
PROTO::sessionLock = std::make_unique<CSessionLockProtocol>(&ext_session_lock_manager_v1_interface, 1, "SessionLock");
PROTO::ime = std::make_unique<CInputMethodV2Protocol>(&zwp_input_method_manager_v2_interface, 1, "IMEv2");
PROTO::virtualKeyboard = std::make_unique<CVirtualKeyboardProtocol>(&zwp_virtual_keyboard_manager_v1_interface, 1, "VirtualKeyboard");
Expand Down
24 changes: 17 additions & 7 deletions src/protocols/IdleNotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (!resource_->resource())
return;

Expand All @@ -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));
Expand All @@ -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) {
;
}
Expand All @@ -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) {
Expand All @@ -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 (!RESOURCE->good()) {
pMgr->noMemory();
Expand All @@ -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();
}
}
9 changes: 6 additions & 3 deletions src/protocols/IdleNotify.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ class CEventLoopTimer;

class CExtIdleNotification {
public:
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs);
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs, bool obeyInhibitors);
~CExtIdleNotification();

bool good();
void onTimerFired();
void onActivity();

bool inhibitorsAreObeyed() const;

private:
SP<CExtIdleNotificationV1> resource;
uint32_t timeoutMs = 0;
SP<CEventLoopTimer> timer;

bool idled = false;
bool idled = false;
bool obeyInhibitors = false;

void updateTimer();
};
Expand All @@ -39,7 +42,7 @@ class CIdleNotifyProtocol : public IWaylandProtocol {
private:
void onManagerResourceDestroy(wl_resource* res);
void destroyNotification(CExtIdleNotification* notif);
void onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat);
void onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors);

bool isInhibited = false;

Expand Down

0 comments on commit 58df01c

Please sign in to comment.