From 6021ec89f56297772c617ae51b83def38302fb97 Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 10:04:38 +0100 Subject: [PATCH 1/6] feat: add default config path --- src/main.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e6dcf92..d3b18f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,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) { @@ -67,16 +67,12 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[]) configPath = optarg; break; default: - std::cerr << "Usage: " << argv[0] << " [-c config_file_path]\n"; - exit(EXIT_FAILURE); + std::cout << "No config path provided. Using default config path: $HOME/.config/UsbMakroBoard.yaml\n"; + configPath = "$HOME/.config/UsbMakroBoard.yaml"; } } - return configPath; -} -YAML::Node loadConfig(const std::string &configPath) -{ - return YAML::LoadFile(configPath); + return configPath; } int openDevice(const std::string &devicePath) -- 2.49.1 From 65bc8e9b18da3bd6778d11b0e29dc5a23f5a9abb Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 10:06:54 +0100 Subject: [PATCH 2/6] docs: regarding config --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 95eba79..b4f590d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ For info that with "EVIOCGRAB" the keyboard events can be consumed exclusively b ## 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 -- 2.49.1 From eebd03bb4e3dbd8fabeea5ed432eb624239216b8 Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 10:09:32 +0100 Subject: [PATCH 3/6] change default config file name --- README.md | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4f590d..b37aa5d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ For info that with "EVIOCGRAB" the keyboard events can be consumed exclusively b ## Configuration -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. +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). diff --git a/src/main.cpp b/src/main.cpp index d3b18f8..12b54dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,8 +67,8 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[]) configPath = optarg; break; default: - std::cout << "No config path provided. Using default config path: $HOME/.config/UsbMakroBoard.yaml\n"; - configPath = "$HOME/.config/UsbMakroBoard.yaml"; + std::cout << "No config path provided. Using default config path: $HOME/.config/usbMakroBoard.yaml\n"; + configPath = "$HOME/.config/usbMakroBoard.yaml"; } } -- 2.49.1 From e8891983d9c77dc379006b5c04c5900f702cadcf Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 13:11:59 +0100 Subject: [PATCH 4/6] Revert "change default config file name" This reverts commit eebd03bb4e3dbd8fabeea5ed432eb624239216b8. --- README.md | 2 +- src/main.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b37aa5d..b4f590d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ For info that with "EVIOCGRAB" the keyboard events can be consumed exclusively b ## Configuration -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. +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). diff --git a/src/main.cpp b/src/main.cpp index 12b54dd..d3b18f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,8 +67,8 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[]) configPath = optarg; break; default: - std::cout << "No config path provided. Using default config path: $HOME/.config/usbMakroBoard.yaml\n"; - configPath = "$HOME/.config/usbMakroBoard.yaml"; + std::cout << "No config path provided. Using default config path: $HOME/.config/UsbMakroBoard.yaml\n"; + configPath = "$HOME/.config/UsbMakroBoard.yaml"; } } -- 2.49.1 From 3052bb199f8f71002d190575632a40cc768f0ff8 Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 13:12:02 +0100 Subject: [PATCH 5/6] Revert "feat: add default config path" This reverts commit 6021ec89f56297772c617ae51b83def38302fb97. --- src/main.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d3b18f8..e6dcf92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,7 @@ std::pair mapKeyEventToRowColumn(int keyEventNumber, const std::unorde std::string getConfigPathFromCliArguments(int argc, char *argv[]) { - std::string configPath = ""; + std::string configPath = "config.yaml"; int opt; while ((opt = getopt(argc, argv, "c:")) != -1) { @@ -67,14 +67,18 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[]) configPath = optarg; break; default: - std::cout << "No config path provided. Using default config path: $HOME/.config/UsbMakroBoard.yaml\n"; - configPath = "$HOME/.config/UsbMakroBoard.yaml"; + std::cerr << "Usage: " << argv[0] << " [-c config_file_path]\n"; + exit(EXIT_FAILURE); } } - return configPath; } +YAML::Node loadConfig(const std::string &configPath) +{ + return YAML::LoadFile(configPath); +} + int openDevice(const std::string &devicePath) { int fdKeyboard = open(devicePath.c_str(), O_RDONLY); -- 2.49.1 From 57b7dc8412814a650c0fa779db68b5c34ea94dcd Mon Sep 17 00:00:00 2001 From: Timo Behrendt Date: Sat, 27 Dec 2025 13:17:00 +0100 Subject: [PATCH 6/6] feat: add default config fallback --- src/main.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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; } -- 2.49.1