idleinhibit: added less than 0 inhibitor mitigation (#11)

This commit is contained in:
Jakub Konior 2024-02-19 22:41:52 +01:00 committed by GitHub
parent f4659b1bb8
commit c26683b60d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 5 deletions

View File

@ -261,7 +261,7 @@ void CHypridle::onIdled(SIdleListener* pListener) {
Debug::log(LOG, "Idled: rule {:x}", (uintptr_t)pListener); Debug::log(LOG, "Idled: rule {:x}", (uintptr_t)pListener);
if (g_pHypridle->m_iInhibitLocks > 0) { if (g_pHypridle->m_iInhibitLocks > 0) {
Debug::log(LOG, "Ignoring, inhibit locks: {}", g_pHypridle->m_iInhibitLocks); Debug::log(LOG, "Ignoring from onIdled(), inhibit locks: {}", g_pHypridle->m_iInhibitLocks);
return; return;
} }
@ -278,7 +278,7 @@ void CHypridle::onResumed(SIdleListener* pListener) {
Debug::log(LOG, "Resumed: rule {:x}", (uintptr_t)pListener); Debug::log(LOG, "Resumed: rule {:x}", (uintptr_t)pListener);
if (g_pHypridle->m_iInhibitLocks > 0) { if (g_pHypridle->m_iInhibitLocks > 0) {
Debug::log(LOG, "Ignoring, inhibit locks: {}", g_pHypridle->m_iInhibitLocks); Debug::log(LOG, "Ignoring from onResumed(), inhibit locks: {}", g_pHypridle->m_iInhibitLocks);
return; return;
} }
@ -293,9 +293,13 @@ void CHypridle::onResumed(SIdleListener* pListener) {
void CHypridle::onInhibit(bool lock) { void CHypridle::onInhibit(bool lock) {
m_iInhibitLocks += lock ? 1 : -1; m_iInhibitLocks += lock ? 1 : -1;
if (m_iInhibitLocks < 0) if (m_iInhibitLocks < 0) {
Debug::log(WARN, "BUG THIS: inhibit locks < 0"); // what would be safer appending one or setting to 0?
else // what if would be equal -2?
// you have been warned.
m_iInhibitLocks = 0;
Debug::log(WARN, "BUG THIS: inhibit locks < 0. Brought back to 0.");
} else
Debug::log(LOG, "Inhibit locks: {}", m_iInhibitLocks); Debug::log(LOG, "Inhibit locks: {}", m_iInhibitLocks);
} }