mirror of
https://github.com/hyprwm/hypridle.git
synced 2024-12-22 13:39:47 +01:00
dbus: Actually register inhibit cookies (#14)
* Actually register inhibit cookies * Add unregistering logic * Fix code style
This commit is contained in:
parent
da2624628b
commit
158c52c4a7
2 changed files with 17 additions and 0 deletions
|
@ -316,6 +316,16 @@ void CHypridle::registerDbusInhibitCookie(CHypridle::SDbusInhibitCookie& cookie)
|
||||||
m_sDBUSState.inhibitCookies.push_back(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) {
|
void handleDbusLogin(sdbus::Message& msg) {
|
||||||
// lock & unlock
|
// lock & unlock
|
||||||
static auto* const PLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:lock_cmd");
|
static auto* const PLOCKCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:lock_cmd");
|
||||||
|
@ -373,12 +383,14 @@ void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {
|
||||||
} else {
|
} else {
|
||||||
uint32_t cookie = 0;
|
uint32_t cookie = 0;
|
||||||
call >> cookie;
|
call >> cookie;
|
||||||
|
Debug::log(TRACE, "Read uninhibit cookie: {}", cookie);
|
||||||
const auto COOKIE = g_pHypridle->getDbusInhibitCookie(cookie);
|
const auto COOKIE = g_pHypridle->getDbusInhibitCookie(cookie);
|
||||||
if (COOKIE.cookie == 0) {
|
if (COOKIE.cookie == 0) {
|
||||||
Debug::log(WARN, "No cookie in uninhibit");
|
Debug::log(WARN, "No cookie in uninhibit");
|
||||||
} else {
|
} else {
|
||||||
app = COOKIE.app;
|
app = COOKIE.app;
|
||||||
reason = COOKIE.reason;
|
reason = COOKIE.reason;
|
||||||
|
g_pHypridle->unregisterDbusInhibitCookie(COOKIE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,11 +408,15 @@ void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {
|
||||||
static int cookieID = 1337;
|
static int cookieID = 1337;
|
||||||
|
|
||||||
if (inhibit) {
|
if (inhibit) {
|
||||||
|
auto cookie = CHypridle::SDbusInhibitCookie{uint32_t{cookieID}, app, reason};
|
||||||
|
|
||||||
auto reply = call.createReply();
|
auto reply = call.createReply();
|
||||||
reply << uint32_t{cookieID++};
|
reply << uint32_t{cookieID++};
|
||||||
reply.send();
|
reply.send();
|
||||||
|
|
||||||
Debug::log(LOG, "Cookie {} sent", cookieID - 1);
|
Debug::log(LOG, "Cookie {} sent", cookieID - 1);
|
||||||
|
|
||||||
|
g_pHypridle->registerDbusInhibitCookie(cookie);
|
||||||
} else {
|
} else {
|
||||||
auto reply = call.createReply();
|
auto reply = call.createReply();
|
||||||
reply.send();
|
reply.send();
|
||||||
|
|
|
@ -34,6 +34,7 @@ class CHypridle {
|
||||||
|
|
||||||
SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
|
SDbusInhibitCookie getDbusInhibitCookie(uint32_t cookie);
|
||||||
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
|
void registerDbusInhibitCookie(SDbusInhibitCookie& cookie);
|
||||||
|
void unregisterDbusInhibitCookie(const SDbusInhibitCookie& cookie);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupDBUS();
|
void setupDBUS();
|
||||||
|
|
Loading…
Reference in a new issue