mirror of
https://github.com/hyprwm/hyprlock.git
synced 2026-05-08 13:58:02 +02:00
core: replace grace option with --grace cli argument
This commit is contained in:
parent
f9d8dfab7a
commit
6c3ba296c1
4 changed files with 21 additions and 6 deletions
|
|
@ -214,7 +214,6 @@ void CConfigManager::init() {
|
|||
|
||||
m_config.addConfigValue("general:text_trim", Hyprlang::INT{1});
|
||||
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:ignore_empty_input", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:immediate_render", Hyprlang::INT{0});
|
||||
m_config.addConfigValue("general:fractional_scaling", Hyprlang::INT{2});
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ static void setMallocThreshold() {
|
|||
#endif
|
||||
}
|
||||
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender) {
|
||||
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender, const int graceSeconds) {
|
||||
setMallocThreshold();
|
||||
|
||||
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
|
||||
|
|
@ -44,8 +44,7 @@ CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const b
|
|||
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
|
||||
|
||||
if (!immediate) {
|
||||
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace");
|
||||
m_tGraceEnds = *GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(*GRACE) : std::chrono::system_clock::from_time_t(0);
|
||||
m_tGraceEnds = graceSeconds ? std::chrono::system_clock::now() + std::chrono::seconds(graceSeconds) : std::chrono::system_clock::from_time_t(0);
|
||||
} else
|
||||
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ struct SDMABUFModifier {
|
|||
|
||||
class CHyprlock {
|
||||
public:
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender);
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender, const int gracePeriod);
|
||||
~CHyprlock();
|
||||
|
||||
void run();
|
||||
|
|
|
|||
19
src/main.cpp
19
src/main.cpp
|
|
@ -13,6 +13,7 @@ void help() {
|
|||
" -q, --quiet - Disable logging\n"
|
||||
" -c FILE, --config FILE - Specify config file to use\n"
|
||||
" --display NAME - Specify the Wayland display to connect to\n"
|
||||
" --grace SECONDS - Set grace period in seconds before requiring authentication\n"
|
||||
" --immediate - Lock immediately, ignoring any configured grace period\n"
|
||||
" --immediate-render - Do not wait for resources before drawing the background\n"
|
||||
" --no-fade-in - Disable the fade-in animation when the lock screen appears\n"
|
||||
|
|
@ -43,6 +44,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
bool immediate = false;
|
||||
bool immediateRender = false;
|
||||
bool noFadeIn = false;
|
||||
int graceSeconds = 0;
|
||||
|
||||
std::vector<std::string> args(argv, argv + argc);
|
||||
|
||||
|
|
@ -77,6 +79,21 @@ int main(int argc, char** argv, char** envp) {
|
|||
else
|
||||
return 1;
|
||||
|
||||
} else if (arg == "--grace" && i + 1 < (std::size_t)argc) {
|
||||
if (auto value = parseArg(args, arg, i); value) {
|
||||
try {
|
||||
graceSeconds = std::stoi(*value);
|
||||
if (graceSeconds < 0) {
|
||||
std::println(stderr, "Error: Grace period must be non-negative.");
|
||||
return 1;
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
std::println(stderr, "Error: Invalid grace period value: {}", *value);
|
||||
return 1;
|
||||
}
|
||||
} else
|
||||
return 1;
|
||||
|
||||
} else if (arg == "--immediate")
|
||||
immediate = true;
|
||||
|
||||
|
|
@ -111,7 +128,7 @@ int main(int argc, char** argv, char** envp) {
|
|||
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
|
||||
|
||||
try {
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
|
||||
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender, graceSeconds);
|
||||
g_pHyprlock->run();
|
||||
} catch (const std::exception& ex) {
|
||||
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue