Update code to use amended ext-idle-notify protocol

This commit is contained in:
James Ramsey 2025-01-04 15:51:54 -05:00
parent b0bae15499
commit d3726be82a
3 changed files with 18 additions and 11 deletions

View file

@ -138,7 +138,7 @@ CProtocolManager::CProtocolManager() {
PROTO::constraints = std::make_unique<CPointerConstraintsProtocol>(&zwp_pointer_constraints_v1_interface, 1, "PointerConstraints"); 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::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::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::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::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"); PROTO::virtualKeyboard = std::make_unique<CVirtualKeyboardProtocol>(&zwp_virtual_keyboard_manager_v1_interface, 1, "VirtualKeyboard");

View file

@ -10,7 +10,8 @@ static int onTimer(SP<CEventLoopTimer> self, void* data) {
return 0; 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()) if (!resource_->resource())
return; return;
@ -35,7 +36,7 @@ bool CExtIdleNotification::good() {
} }
void CExtIdleNotification::updateTimer() { void CExtIdleNotification::updateTimer() {
if (PROTO::idle->isInhibited) if (PROTO::idle->isInhibited && obeyInhibitors)
timer->updateTimeout(std::nullopt); timer->updateTimeout(std::nullopt);
else else
timer->updateTimeout(std::chrono::milliseconds(timeoutMs)); timer->updateTimeout(std::chrono::milliseconds(timeoutMs));
@ -63,7 +64,10 @@ void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ve
RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); }); RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CExtIdleNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->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) { void CIdleNotifyProtocol::onManagerResourceDestroy(wl_resource* res) {
@ -74,9 +78,10 @@ void CIdleNotifyProtocol::destroyNotification(CExtIdleNotification* notif) {
std::erase_if(m_vNotifications, [&](const auto& other) { return other.get() == 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) { void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors) {
const auto CLIENT = pMgr->client(); const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout)).get(); const auto RESOURCE =
m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout, obeyInhibitors)).get();
if (!RESOURCE->good()) { if (!RESOURCE->good()) {
pMgr->noMemory(); pMgr->noMemory();
@ -94,6 +99,7 @@ void CIdleNotifyProtocol::onActivity() {
void CIdleNotifyProtocol::setInhibit(bool inhibited) { void CIdleNotifyProtocol::setInhibit(bool inhibited) {
isInhibited = inhibited; isInhibited = inhibited;
for (auto const& n : m_vNotifications) { for (auto const& n : m_vNotifications) {
if (n->obeyInhibitors)
n->onActivity(); n->onActivity();
} }
} }

View file

@ -10,7 +10,7 @@ class CEventLoopTimer;
class CExtIdleNotification { class CExtIdleNotification {
public: public:
CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs); CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs, bool obeyInhibitors);
~CExtIdleNotification(); ~CExtIdleNotification();
bool good(); bool good();
@ -23,6 +23,7 @@ class CExtIdleNotification {
SP<CEventLoopTimer> timer; SP<CEventLoopTimer> timer;
bool idled = false; bool idled = false;
bool obeyInhibitors = false;
void updateTimer(); void updateTimer();
}; };
@ -39,7 +40,7 @@ class CIdleNotifyProtocol : public IWaylandProtocol {
private: private:
void onManagerResourceDestroy(wl_resource* res); void onManagerResourceDestroy(wl_resource* res);
void destroyNotification(CExtIdleNotification* notif); 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; bool isInhibited = false;