From b17d66654895274a1df14c995ce593a29335e079 Mon Sep 17 00:00:00 2001 From: Kenton Groombridge Date: Thu, 7 Mar 2024 13:39:27 -0500 Subject: [PATCH] core: add commandline switch to lock immediately (#145) Fixes: https://github.com/hyprwm/hyprlock/issues/143 --- src/core/hyprlock.cpp | 10 +++++++--- src/core/hyprlock.hpp | 2 +- src/main.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 4ca74d0..e14b74b 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -17,7 +17,7 @@ #include #include -CHyprlock::CHyprlock(const std::string& wlDisplay) { +CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate) { m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str()); if (!m_sWaylandState.display) { Debug::log(CRIT, "Couldn't connect to a wayland compositor"); @@ -30,8 +30,12 @@ CHyprlock::CHyprlock(const std::string& wlDisplay) { if (!m_pXKBContext) Debug::log(ERR, "Failed to create xkb context"); - const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace"); - m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0); + if (!immediate) { + const auto GRACE = (Hyprlang::INT* const*)g_pConfigManager->getValuePtr("general:grace"); + m_tGraceEnds = **GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(**GRACE) : std::chrono::system_clock::from_time_t(0); + } else { + m_tGraceEnds = std::chrono::system_clock::from_time_t(0); + } } // wl_seat diff --git a/src/core/hyprlock.hpp b/src/core/hyprlock.hpp index d21e381..77a5cd8 100644 --- a/src/core/hyprlock.hpp +++ b/src/core/hyprlock.hpp @@ -28,7 +28,7 @@ struct SDMABUFModifier { class CHyprlock { public: - CHyprlock(const std::string& wlDisplay); + CHyprlock(const std::string& wlDisplay, const bool immediate); void run(); diff --git a/src/main.cpp b/src/main.cpp index 6fb97e1..094c946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,10 +8,12 @@ void help() { " -v, --verbose - Enable verbose logging\n" " -q, --quiet - Disable logging\n" " --display (display) - Specify the Wayland display to connect to\n" + " --immediate - Lock immediately, ignoring any configured grace period\n" " -h, --help - Show this help message\n"; } int main(int argc, char** argv, char** envp) { std::string wlDisplay; + bool immediate = false; for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; @@ -25,6 +27,9 @@ int main(int argc, char** argv, char** envp) { else if (arg == "--display" && i + 1 < argc) { wlDisplay = argv[i + 1]; i++; + } + else if (arg == "--immediate") { + immediate = true; } else if (arg == "--help" || arg == "-h") { help(); return 0; @@ -42,7 +47,7 @@ int main(int argc, char** argv, char** envp) { return 1; } - g_pHyprlock = std::make_unique(wlDisplay); + g_pHyprlock = std::make_unique(wlDisplay, immediate); g_pHyprlock->run(); return 0;