2024-02-19 00:08:03 +01:00
|
|
|
|
|
|
|
#include "config/ConfigManager.hpp"
|
|
|
|
#include "core/hyprlock.hpp"
|
2024-06-25 20:09:52 +02:00
|
|
|
#include <cstddef>
|
2024-02-19 00:08:03 +01:00
|
|
|
|
2024-03-03 03:19:25 +01:00
|
|
|
void help() {
|
|
|
|
std::cout << "Usage: hyprlock [options]\n\n"
|
|
|
|
"Options:\n"
|
|
|
|
" -v, --verbose - Enable verbose logging\n"
|
|
|
|
" -q, --quiet - Disable logging\n"
|
2024-03-18 16:04:39 +01:00
|
|
|
" -c FILE, --config FILE - Specify config file to use\n"
|
2024-03-03 03:19:25 +01:00
|
|
|
" --display (display) - Specify the Wayland display to connect to\n"
|
2024-03-07 19:39:27 +01:00
|
|
|
" --immediate - Lock immediately, ignoring any configured grace period\n"
|
2024-03-03 03:19:25 +01:00
|
|
|
" -h, --help - Show this help message\n";
|
2024-02-27 16:10:15 +01:00
|
|
|
}
|
2024-06-25 20:09:52 +02:00
|
|
|
|
|
|
|
std::optional<std::string> parseArg(const std::vector<std::string>& args, const std::string& flag, std::size_t& i) {
|
|
|
|
if (i + 1 < args.size()) {
|
|
|
|
return args[++i];
|
|
|
|
} else {
|
|
|
|
std::cerr << "Error: Missing value for " << flag << " option.\n";
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-19 16:20:52 +01:00
|
|
|
int main(int argc, char** argv, char** envp) {
|
2024-06-25 20:09:52 +02:00
|
|
|
std::string configPath;
|
|
|
|
std::string wlDisplay;
|
|
|
|
bool immediate = false;
|
|
|
|
bool showHelp = false;
|
2024-02-19 16:20:52 +01:00
|
|
|
|
2024-06-25 20:09:52 +02:00
|
|
|
std::vector<std::string> args(argv, argv + argc);
|
|
|
|
|
|
|
|
for (std::size_t i = 1; i < args.size(); ++i) {
|
|
|
|
const std::string arg = argv[i];
|
2024-02-19 00:08:03 +01:00
|
|
|
|
|
|
|
if (arg == "--verbose" || arg == "-v")
|
|
|
|
Debug::verbose = true;
|
|
|
|
|
|
|
|
else if (arg == "--quiet" || arg == "-q")
|
|
|
|
Debug::quiet = true;
|
2024-02-19 16:20:52 +01:00
|
|
|
|
2024-06-25 20:09:52 +02:00
|
|
|
else if ((arg == "--config" || arg == "-c") && i + 1 < (std::size_t)argc) {
|
|
|
|
if (auto value = parseArg(args, arg, i); value)
|
|
|
|
configPath = *value;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (arg == "--display" && i + 1 < (std::size_t)argc) {
|
|
|
|
if (auto value = parseArg(args, arg, i); value)
|
|
|
|
wlDisplay = *value;
|
|
|
|
else
|
|
|
|
return 1;
|
2024-03-18 16:04:39 +01:00
|
|
|
|
2024-06-25 20:09:52 +02:00
|
|
|
} else if (arg == "--immediate")
|
2024-03-07 19:39:27 +01:00
|
|
|
immediate = true;
|
2024-06-25 20:09:52 +02:00
|
|
|
|
|
|
|
else if (arg == "--help" || arg == "-h") {
|
|
|
|
showHelp = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
std::cerr << "Unknown option: " << arg << "\n";
|
2024-02-27 16:10:15 +01:00
|
|
|
help();
|
2024-06-25 20:09:52 +02:00
|
|
|
return 1;
|
2024-02-27 16:10:15 +01:00
|
|
|
}
|
2024-02-19 00:08:03 +01:00
|
|
|
}
|
|
|
|
|
2024-06-25 20:09:52 +02:00
|
|
|
if (showHelp) {
|
|
|
|
help();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-19 00:08:03 +01:00
|
|
|
try {
|
2024-06-28 18:57:38 +02:00
|
|
|
g_pConfigManager = std::make_unique<CConfigManager>(configPath);
|
|
|
|
g_pConfigManager->init();
|
2024-06-25 20:09:52 +02:00
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
Debug::log(CRIT, "ConfigManager threw: {}", ex.what());
|
|
|
|
if (std::string(ex.what()).contains("File does not exist"))
|
2024-02-19 00:08:03 +01:00
|
|
|
Debug::log(NONE, " Make sure you have a config.");
|
2024-06-25 20:09:52 +02:00
|
|
|
|
2024-02-19 00:08:03 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-06-25 20:09:52 +02:00
|
|
|
try {
|
2024-06-28 18:57:38 +02:00
|
|
|
g_pHyprlock = std::make_unique<CHyprlock>(wlDisplay, immediate);
|
2024-06-25 20:09:52 +02:00
|
|
|
g_pHyprlock->run();
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
Debug::log(CRIT, "Hyprlock threw: {}", ex.what());
|
|
|
|
return 1;
|
|
|
|
}
|
2024-02-19 00:08:03 +01:00
|
|
|
|
|
|
|
return 0;
|
2024-02-27 16:10:15 +01:00
|
|
|
}
|