diff --git a/src/main.cpp b/src/main.cpp index e6dcf92..4b1a618 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -57,7 +58,7 @@ std::pair mapKeyEventToRowColumn(int keyEventNumber, const std::unorde std::string getConfigPathFromCliArguments(int argc, char *argv[]) { - std::string configPath = "config.yaml"; + std::string configPath; int opt; while ((opt = getopt(argc, argv, "c:")) != -1) { @@ -71,6 +72,18 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[]) exit(EXIT_FAILURE); } } + + if (configPath.empty()) { + const char *home = std::getenv("HOME"); + if (home != nullptr) { + configPath = std::string(home) + "/.config/usbMakroBoard.yaml"; + } + else { + std::cerr << "HOME environment variable is not set. Exiting.\n"; + exit(EXIT_FAILURE); + } + } + return configPath; }