feat: add default config path (#4)
Reviewed-on: #4 Co-authored-by: Timo Behrendt <t.behrendt@t00n.de> Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #4.
This commit is contained in:
@@ -12,7 +12,9 @@ For info that with "EVIOCGRAB" the keyboard events can be consumed exclusively b
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
The configuration can be
|
The configuration can be provided by either specifying a config file path via the `-c` parameter. If no parameter is provided, the default config path under `$HOME/.config/UsbMakroBoard.yaml` is used.
|
||||||
|
|
||||||
|
Find the config schema in [schemas/config.schema.json](./schemas/config.schema.json) as well as a default config in [config.yaml](./config.yaml).
|
||||||
|
|
||||||
## Allowing non-root access to the device
|
## Allowing non-root access to the device
|
||||||
|
|
||||||
|
|||||||
15
src/main.cpp
15
src/main.cpp
@@ -7,6 +7,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
#include <spdlog/sinks/stdout_sinks.h>
|
#include <spdlog/sinks/stdout_sinks.h>
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
@@ -57,7 +58,7 @@ std::pair<int, int> mapKeyEventToRowColumn(int keyEventNumber, const std::unorde
|
|||||||
|
|
||||||
std::string getConfigPathFromCliArguments(int argc, char *argv[])
|
std::string getConfigPathFromCliArguments(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::string configPath = "config.yaml";
|
std::string configPath;
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "c:")) != -1)
|
while ((opt = getopt(argc, argv, "c:")) != -1)
|
||||||
{
|
{
|
||||||
@@ -71,6 +72,18 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[])
|
|||||||
exit(EXIT_FAILURE);
|
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;
|
return configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user