dbus: handle before/after sleep in PrepareForSleep

This commit is contained in:
Vaxry 2024-02-17 23:48:54 +00:00
parent cd592840ff
commit f6dd1ef9d6
3 changed files with 13 additions and 5 deletions

View file

@ -16,6 +16,7 @@ general {
lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session) lock_cmd = notify-send "lock!" # dbus/sysd lock command (loginctl lock-session)
unlock_cmd = notify-send "unlock!" # same as above, but unlock unlock_cmd = notify-send "unlock!" # same as above, but unlock
before_sleep_cmd = notify-send "Zzz" # command ran before sleep 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) ignore_dbus_inhibit = false # whether to ignore dbus-sent idle-inhibit requests (used by e.g. firefox or steam)
} }

View file

@ -27,6 +27,7 @@ void CConfigManager::init() {
m_config.addConfigValue("general:lock_cmd", Hyprlang::STRING{""}); m_config.addConfigValue("general:lock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:unlock_cmd", Hyprlang::STRING{""}); m_config.addConfigValue("general:unlock_cmd", Hyprlang::STRING{""});
m_config.addConfigValue("general:before_sleep_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.addConfigValue("general:ignore_dbus_inhibit", Hyprlang::INT{0});
m_config.commence(); m_config.commence();

View file

@ -331,15 +331,21 @@ void handleDbusSleep(sdbus::Message& msg) {
if (MEMBER != "PrepareForSleep") if (MEMBER != "PrepareForSleep")
return; 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; return;
Debug::log(LOG, "Running before-sleep: {}", *PSLEEPCMD); Debug::log(LOG, "Running: {}", cmd);
spawn(*PSLEEPCMD); spawn(cmd);
} }
void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) { void handleDbusScreensaver(sdbus::MethodCall call, bool inhibit) {