Skip to content

Commit 7999f44

Browse files
authored
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 0c99899. * core: add --immediate and grace option deprecation warnings * core: review fixes for --immediate and --grace * core: review fixes for grace deprecation
1 parent a963898 commit 7999f44

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/config/ConfigManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ void CConfigManager::init() {
214214

215215
m_config.addConfigValue("general:text_trim", Hyprlang::INT{1});
216216
m_config.addConfigValue("general:hide_cursor", Hyprlang::INT{0});
217-
m_config.addConfigValue("general:grace", Hyprlang::INT{0});
218217
m_config.addConfigValue("general:ignore_empty_input", Hyprlang::INT{0});
219218
m_config.addConfigValue("general:immediate_render", Hyprlang::INT{0});
220219
m_config.addConfigValue("general:fractional_scaling", Hyprlang::INT{2});

src/core/hyprlock.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,17 @@ static void setMallocThreshold() {
3636
#endif
3737
}
3838

39-
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender) {
39+
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediateRender, const int graceSeconds) {
4040
setMallocThreshold();
4141

4242
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
4343
RASSERT(m_sWaylandState.display, "Couldn't connect to a wayland compositor");
4444

4545
g_pEGL = makeUnique<CEGL>(m_sWaylandState.display);
4646

47-
if (!immediate) {
48-
static const auto GRACE = g_pConfigManager->getValue<Hyprlang::INT>("general:grace");
49-
m_tGraceEnds = *GRACE ? std::chrono::system_clock::now() + std::chrono::seconds(*GRACE) : std::chrono::system_clock::from_time_t(0);
50-
} else
47+
if (graceSeconds > 0)
48+
m_tGraceEnds = std::chrono::system_clock::now() + std::chrono::seconds(graceSeconds);
49+
else
5150
m_tGraceEnds = std::chrono::system_clock::from_time_t(0);
5251

5352
static const auto IMMEDIATERENDER = g_pConfigManager->getValue<Hyprlang::INT>("general:immediate_render");

src/core/hyprlock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct SDMABUFModifier {
2929

3030
class CHyprlock {
3131
public:
32-
CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender);
32+
CHyprlock(const std::string& wlDisplay, const bool immediateRender, const int gracePeriod);
3333
~CHyprlock();
3434

3535
void run();

src/main.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void help() {
1313
" -q, --quiet - Disable logging\n"
1414
" -c FILE, --config FILE - Specify config file to use\n"
1515
" --display NAME - Specify the Wayland display to connect to\n"
16-
" --immediate - Lock immediately, ignoring any configured grace period\n"
16+
" --grace SECONDS - Set grace period in seconds before requiring authentication\n"
1717
" --immediate-render - Do not wait for resources before drawing the background\n"
1818
" --no-fade-in - Disable the fade-in animation when the lock screen appears\n"
1919
" -V, --version - Show version information\n"
@@ -40,9 +40,9 @@ static void printVersion() {
4040
int main(int argc, char** argv, char** envp) {
4141
std::string configPath;
4242
std::string wlDisplay;
43-
bool immediate = false;
4443
bool immediateRender = false;
4544
bool noFadeIn = false;
45+
int graceSeconds = 0;
4646

4747
std::vector<std::string> args(argv, argv + argc);
4848

@@ -77,8 +77,25 @@ int main(int argc, char** argv, char** envp) {
7777
else
7878
return 1;
7979

80-
} else if (arg == "--immediate")
81-
immediate = true;
80+
} else if (arg == "--grace" && i + 1 < (std::size_t)argc) {
81+
if (auto value = parseArg(args, arg, i); value) {
82+
try {
83+
graceSeconds = std::stoi(*value);
84+
if (graceSeconds < 0) {
85+
std::println(stderr, "Error: Grace period must be non-negative.");
86+
return 1;
87+
}
88+
} catch (const std::exception&) {
89+
std::println(stderr, "Error: Invalid grace period value: {}", *value);
90+
return 1;
91+
}
92+
} else
93+
return 1;
94+
95+
} else if (arg == "--immediate") {
96+
graceSeconds = 0;
97+
Debug::log(WARN, R"("--immediate" is deprecated. Use the "--grace" option instead.)");
98+
}
8299

83100
else if (arg == "--immediate-render")
84101
immediateRender = true;
@@ -107,11 +124,11 @@ int main(int argc, char** argv, char** envp) {
107124
return 1;
108125
}
109126

110-
if (noFadeIn || immediate)
127+
if (noFadeIn)
111128
g_pConfigManager->m_AnimationTree.setConfigForNode("fadeIn", false, 0.f, "default");
112129

113130
try {
114-
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediate, immediateRender);
131+
g_pHyprlock = makeUnique<CHyprlock>(wlDisplay, immediateRender, graceSeconds);
115132
g_pHyprlock->run();
116133
} catch (const std::exception& ex) {
117134
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());

0 commit comments

Comments
 (0)