From f6dd1ef9d61ad3a633939a3be2cd37c876979553 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 17 Feb 2024 23:48:54 +0000 Subject: [PATCH] dbus: handle before/after sleep in PrepareForSleep --- README.md | 1 + src/config/ConfigManager.cpp | 1 + src/core/Hypridle.cpp | 16 +++++++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a939370..a3b7880 100644 --- a/README.md +++ b/README.md @@ -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) } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 71954a8..f34e5b8 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -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(); diff --git a/src/core/Hypridle.cpp b/src/core/Hypridle.cpp index 124a8bd..f07eaec 100644 --- a/src/core/Hypridle.cpp +++ b/src/core/Hypridle.cpp @@ -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) {