Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually register inhibit cookies #14

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/core/Hypridle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ void CHypridle::registerDbusInhibitCookie(CHypridle::SDbusInhibitCookie& cookie)
m_sDBUSState.inhibitCookies.push_back(cookie);
}

void CHypridle::unregisterDbusInhibitCookie(const CHypridle::SDbusInhibitCookie& cookie) {
const auto IT = std::find_if(m_sDBUSState.inhibitCookies.begin(), m_sDBUSState.inhibitCookies.end(),
[&cookie](const CHypridle::SDbusInhibitCookie& item) { return item.cookie == cookie.cookie; });

if (IT == m_sDBUSState.inhibitCookies.end())
Debug::log(WARN, "BUG THIS: attempted to unregister unknown cookie");
else
m_sDBUSState.inhibitCookies.erase(IT);
}

void handleDbusLogin(sdbus::Message& msg) {
// lock & unlock
static auto* const PLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:lock_cmd");
Expand Down Expand Up @@ -373,12 +383,14 @@ void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {
} else {
uint32_t cookie = 0;
call >> cookie;
Debug::log(TRACE, "Read uninhibit cookie: {}", cookie);
const auto COOKIE = g_pHypridle->getDbusInhibitCookie(cookie);
if (COOKIE.cookie == 0) {
Debug::log(WARN, "No cookie in uninhibit");
} else {
app = COOKIE.app;
reason = COOKIE.reason;
g_pHypridle->unregisterDbusInhibitCookie(COOKIE);
}
}

Expand All @@ -396,11 +408,15 @@ void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {
static int cookieID = 1337;

if (inhibit) {
auto cookie = CHypridle::SDbusInhibitCookie{uint32_t{cookieID}, app, reason};

auto reply = call.createReply();
reply << uint32_t{cookieID++};
reply.send();

Debug::log(LOG, "Cookie {} sent", cookieID - 1);

g_pHypridle->registerDbusInhibitCookie(cookie);
} else {
auto reply = call.createReply();
reply.send();
Expand Down
1 change: 1 addition & 0 deletions src/core/Hypridle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CHypridle {

SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
void unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);

private:
void setupDBUS();
Expand Down
Loading