core: replace grace option with --grace cli argument (#802)

* core: replace grace option with --grace cli argument

* core: remove --immediate option

not necessary anymore, grace is not a configuration option

* Revert "core: remove --immediate option"

This reverts commit 0c99899157.

* core: add --immediate and grace option deprecation warnings

* core: review fixes for --immediate and --grace

* core: review fixes for grace deprecation
This commit is contained in:
davc0n 2025-06-26 09:35:25 +02:00 committed by GitHub
parent a9638986c3
commit 7999f448d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 13 deletions

View file

@ -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});

View file

@ -36,7 +36,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 immediateRender, const int graceSeconds) {
setMallocThreshold();
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
@ -44,10 +44,9 @@ 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);
} else
if (graceSeconds > 0)
m_tGraceEnds = std::chrono::system_clock::now() + std::chrono::seconds(graceSeconds);
else
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
static const auto IMMEDIATERENDER = g_pConfigManager->getValue<Hyprlang::INT>("general:immediate_render");

View file

@ -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 immediateRender, const int gracePeriod);
~CHyprlock();
void run();

View file

@ -13,7 +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"
" --immediate - Lock immediately, ignoring any configured grace period\n"
" --grace SECONDS - Set grace period in seconds before requiring authentication\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"
" -V, --version - Show version information\n"
@ -40,9 +40,9 @@ static void printVersion() {
int main(int argc, char** argv, char** envp) {
std::string configPath;
std::string wlDisplay;
bool immediate = false;
bool immediateRender = false;
bool noFadeIn = false;
int graceSeconds = 0;
std::vector<std::string> args(argv, argv + argc);
@ -77,8 +77,25 @@ int main(int argc, char** argv, char** envp) {
else
return 1;
} else if (arg == "--immediate")
immediate = true;
} 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") {
graceSeconds = 0;
Debug::log(WARN, R"("--immediate" is deprecated. Use the "--grace" option instead.)");
}
else if (arg == "--immediate-render")
immediateRender = true;
@ -107,11 +124,11 @@ int main(int argc, char** argv, char** envp) {
return 1;
}
if (noFadeIn || immediate)
if (noFadeIn)
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
try {
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediateRender, graceSeconds);
g_pHyprlock->run();
} catch (const std::exception& ex) {
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());