mirror of
https://github.com/hyprwm/hypridle.git
synced 2024-12-22 05:29:49 +01:00
dbus: handle before/after sleep in PrepareForSleep
This commit is contained in:
parent
cd592840ff
commit
f6dd1ef9d6
3 changed files with 13 additions and 5 deletions
|
@ -16,6 +16,7 @@ general {
|
|||
lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session)
|
||||
unlock_cmd = notify-send "unlock!" # same as above, but unlock
|
||||
before_sleep_cmd = notify-send "Zzz" # command ran before sleep
|
||||
after_sleep_cmd = notify-send "Awake!" # command ran after sleep
|
||||
ignore_dbus_inhibit = false # whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ void CConfigManager::init() {
|
|||
m_config.addConfigValue("general:lock_cmd", Hyprlang::STRING{""});
|
||||
m_config.addConfigValue("general:unlock_cmd", Hyprlang::STRING{""});
|
||||
m_config.addConfigValue("general:before_sleep_cmd", Hyprlang::STRING{""});
|
||||
m_config.addConfigValue("general:after_sleep_cmd", Hyprlang::STRING{""});
|
||||
m_config.addConfigValue("general:ignore_dbus_inhibit", Hyprlang::INT{0});
|
||||
|
||||
m_config.commence();
|
||||
|
|
|
@ -331,15 +331,21 @@ void handleDbusSleep(sdbus::Message& msg) {
|
|||
if (MEMBER != "PrepareForSleep")
|
||||
return;
|
||||
|
||||
static auto* const PSLEEPCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:before_sleep_cmd");
|
||||
bool toSleep = true;
|
||||
msg >> toSleep;
|
||||
|
||||
Debug::log(LOG, "Got PrepareForSleep from dbus");
|
||||
static auto* const PSLEEPCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:before_sleep_cmd");
|
||||
static auto* const PAFTERSLEEPCMD = (Hyprlang::STRING const*)g_pConfigManager->getValuePtr("general:after_sleep_cmd");
|
||||
|
||||
if (std::string{*PSLEEPCMD}.empty())
|
||||
Debug::log(LOG, "Got PrepareForSleep from dbus with sleep {}", toSleep);
|
||||
|
||||
std::string cmd = toSleep ? *PSLEEPCMD : *PAFTERSLEEPCMD;
|
||||
|
||||
if (cmd.empty())
|
||||
return;
|
||||
|
||||
Debug::log(LOG, "Running before-sleep: {}", *PSLEEPCMD);
|
||||
spawn(*PSLEEPCMD);
|
||||
Debug::log(LOG, "Running: {}", cmd);
|
||||
spawn(cmd);
|
||||
}
|
||||
|
||||
void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {
|
||||
|
|
Loading…
Reference in a new issue