core: fix dbus inhibit lock counting (#175)

Fixes #74 (root cause)

Fixes #111
This commit is contained in:
slowsage 2025-11-01 16:00:41 -04:00 committed by GitHub
parent f158b2fe92
commit f3d1f3b232
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 13 deletions

View file

@ -371,15 +371,8 @@ bool CHypridle::unregisterDbusInhibitCookie(const CHypridle::SDbusInhibitCookie&
return true;
}
bool CHypridle::unregisterDbusInhibitCookies(const std::string& ownerID) {
const auto IT = std::remove_if(m_sDBUSState.inhibitCookies.begin(), m_sDBUSState.inhibitCookies.end(),
[&ownerID](const CHypridle::SDbusInhibitCookie& item) { return item.ownerID == ownerID; });
if (IT == m_sDBUSState.inhibitCookies.end())
return false;
m_sDBUSState.inhibitCookies.erase(IT, m_sDBUSState.inhibitCookies.end());
return true;
size_t CHypridle::unregisterDbusInhibitCookies(const std::string& ownerID) {
return std::erase_if(m_sDBUSState.inhibitCookies, [&ownerID](const CHypridle::SDbusInhibitCookie& item) { return item.ownerID == ownerID; });
}
static void handleDbusLogin(sdbus::Message msg) {
@ -461,6 +454,7 @@ static void handleDbusBlockInhibitsPropertyChanged(sdbus::Message msg) {
static uint32_t handleDbusScreensaver(std::string app, std::string reason, uint32_t cookie, bool inhibit, const char* sender) {
std::string ownerID = sender;
bool cookieFound = false;
if (!inhibit) {
Debug::log(TRACE, "Read uninhibit cookie: {}", cookie);
@ -471,6 +465,7 @@ static uint32_t handleDbusScreensaver(std::string app, std::string reason, uint3
app = COOKIE.app;
reason = COOKIE.reason;
ownerID = COOKIE.ownerID;
cookieFound = true;
if (!g_pHypridle->unregisterDbusInhibitCookie(COOKIE))
Debug::log(WARN, "BUG THIS: attempted to unregister unknown cookie");
@ -481,7 +476,7 @@ static uint32_t handleDbusScreensaver(std::string app, std::string reason, uint3
if (inhibit)
g_pHypridle->onInhibit(true);
else
else if (cookieFound)
g_pHypridle->onInhibit(false);
static uint32_t cookieID = 1337;
@ -506,8 +501,10 @@ static void handleDbusNameOwnerChanged(sdbus::Message msg) {
if (!newOwner.empty())
return;
if (g_pHypridle->unregisterDbusInhibitCookies(oldOwner)) {
size_t removed = g_pHypridle->unregisterDbusInhibitCookies(oldOwner);
if (removed > 0) {
Debug::log(LOG, "App with owner {} disconnected", oldOwner);
for (size_t i = 0; i < removed; i++)
g_pHypridle->onInhibit(false);
}
}

View file

@ -44,7 +44,7 @@ class CHypridle {
SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
bool unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);
bool unregisterDbusInhibitCookies(const std::string& ownerID);
size_t unregisterDbusInhibitCookies(const std::string& ownerID);
void handleInhibitOnDbusSleep(bool toSleep);
void inhibitSleep();