Skip to content

Commit b9f282b

Browse files
author
James Ramsey
committed
Update code to use amended ext-idle-notify protocol
1 parent 3b99e90 commit b9f282b

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/managers/ProtocolManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ CProtocolManager::CProtocolManager() {
147147
PROTO::constraints = makeUnique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints");
148148
PROTO::outputPower = makeUnique<COutputPowerProtocol>(&zwlr_output_power_manager_v1_interface, 1, "OutputPower");
149149
PROTO::activation = makeUnique<CXDGActivationProtocol>(&xdg_activation_v1_interface, 1, "XDGActivation");
150-
PROTO::idle = makeUnique<CIdleNotifyProtocol>(&ext_idle_notifier_v1_interface, 1, "IdleNotify");
150+
PROTO::idle = makeUnique<CIdleNotifyProtocol>(&ext_idle_notifier_v1_interface, 2, "IdleNotify");
151151
PROTO::lockNotify = makeUnique<CLockNotifyProtocol>(&hyprland_lock_notifier_v1_interface, 1, "IdleNotify");
152152
PROTO::sessionLock = makeUnique<CSessionLockProtocol>(&ext_session_lock_manager_v1_interface, 1, "SessionLock");
153153
PROTO::ime = makeUnique<CInputMethodV2Protocol>(&zwp_input_method_manager_v2_interface, 1, "IMEv2");

src/protocols/IdleNotify.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ static int onTimer(SP<CEventLoopTimer> self, void* data) {
1010
return 0;
1111
}
1212

13-
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_) : resource(resource_), timeoutMs(timeoutMs_) {
13+
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_, bool obeyInhibitors_) :
14+
resource(resource_), timeoutMs(timeoutMs_), obeyInhibitors(obeyInhibitors_) {
1415
if UNLIKELY (!resource_->resource())
1516
return;
1617

@@ -35,7 +36,7 @@ bool CExtIdleNotification::good() {
3536
}
3637

3738
void CExtIdleNotification::updateTimer() {
38-
if (PROTO::idle->isInhibited)
39+
if (PROTO::idle->isInhibited && obeyInhibitors)
3940
timer->updateTimeout(std::nullopt);
4041
else
4142
timer->updateTimeout(std::chrono::milliseconds(timeoutMs));
@@ -54,6 +55,10 @@ void CExtIdleNotification::onActivity() {
5455
updateTimer();
5556
}
5657

58+
bool CExtIdleNotification::inhibitorsAreObeyed() const {
59+
return obeyInhibitors;
60+
}
61+
5762
CIdleNotifyProtocol::CIdleNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
5863
;
5964
}
@@ -63,7 +68,10 @@ void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ve
6368
RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); });
6469

6570
RESOURCE->setDestroy([this](CExtIdleNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
66-
RESOURCE->setGetIdleNotification([this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat); });
71+
RESOURCE->setGetIdleNotification(
72+
[this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat, true); });
73+
RESOURCE->setGetInputIdleNotification(
74+
[this](CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) { this->onGetNotification(pMgr, id, timeout, seat, false); });
6775
}
6876

6977
void CIdleNotifyProtocol::onManagerResourceDestroy(wl_resource* res) {
@@ -74,9 +82,10 @@ void CIdleNotifyProtocol::destroyNotification(CExtIdleNotification* notif) {
7482
std::erase_if(m_vNotifications, [&](const auto& other) { return other.get() == notif; });
7583
}
7684

77-
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat) {
78-
const auto CLIENT = pMgr->client();
79-
const auto RESOURCE = m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout)).get();
85+
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors) {
86+
const auto CLIENT = pMgr->client();
87+
const auto RESOURCE =
88+
m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout, obeyInhibitors)).get();
8089

8190
if UNLIKELY (!RESOURCE->good()) {
8291
pMgr->noMemory();
@@ -94,6 +103,7 @@ void CIdleNotifyProtocol::onActivity() {
94103
void CIdleNotifyProtocol::setInhibit(bool inhibited) {
95104
isInhibited = inhibited;
96105
for (auto const& n : m_vNotifications) {
97-
n->onActivity();
106+
if (n->inhibitorsAreObeyed())
107+
n->onActivity();
98108
}
99-
}
109+
}

src/protocols/IdleNotify.hpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ class CEventLoopTimer;
99

1010
class CExtIdleNotification {
1111
public:
12-
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs);
12+
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs, bool obeyInhibitors);
1313
~CExtIdleNotification();
1414

1515
bool good();
1616
void onTimerFired();
1717
void onActivity();
1818

19+
bool inhibitorsAreObeyed() const;
20+
1921
private:
2022
SP<CExtIdleNotificationV1> resource;
2123
uint32_t timeoutMs = 0;
2224
SP<CEventLoopTimer> timer;
2325

24-
bool idled = false;
26+
bool idled = false;
27+
bool obeyInhibitors = false;
2528

2629
void updateTimer();
2730
};
@@ -38,7 +41,7 @@ class CIdleNotifyProtocol : public IWaylandProtocol {
3841
private:
3942
void onManagerResourceDestroy(wl_resource* res);
4043
void destroyNotification(CExtIdleNotification* notif);
41-
void onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat);
44+
void onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors);
4245

4346
bool isInhibited = false;
4447

0 commit comments

Comments
 (0)