mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
core: add commandline switch to lock immediately (#145)
Fixes: https://github.com/hyprwm/hyprlock/issues/143
This commit is contained in:
parent
90e94dee86
commit
b17d666548
3 changed files with 14 additions and 5 deletions
|
@ -17,7 +17,7 @@
|
|||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
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
|
||||
|
|
|
@ -28,7 +28,7 @@ struct SDMABUFModifier {
|
|||
|
||||
class CHyprlock {
|
||||
public:
|
||||
CHyprlock(const std::string& wlDisplay);
|
||||
CHyprlock(const std::string& wlDisplay, const bool immediate);
|
||||
|
||||
void run();
|
||||
|
||||
|
|
|
@ -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<CHyprlock>(wlDisplay);
|
||||
g_pHyprlock = std::make_unique<CHyprlock>(wlDisplay, immediate);
|
||||
g_pHyprlock->run();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue