diff --git a/README.md b/README.md index afd62d5..e472dce 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,10 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures ``` comfortable-swipe restart ``` +6. You can check the status of your application by running + ``` + comfortable-swipe status + ``` ## Configurations Comfortable swipe makes use of keyboard shortcuts for configurations. The configuration file is located at `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`. Make sure to run `comfortable-swipe restart` after making changes. @@ -80,7 +84,13 @@ Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete li ## Debugging -You can check your touchpad driver by running `comfortable-swipe debug`. This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput. +You can check your touchpad driver by running + +```bash +comfortable-swipe debug +``` + +This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput. A working swipe gesture will show the following: diff --git a/lib/gesture/swipe_gesture.cpp b/lib/gesture/swipe_gesture.cpp index 7e4e20b..137d02a 100644 --- a/lib/gesture/swipe_gesture.cpp +++ b/lib/gesture/swipe_gesture.cpp @@ -198,14 +198,14 @@ namespace comfortable_swipe::gesture const int swipe_gesture::MSK_VERTICAL = 4; const int swipe_gesture::FRESH = -1; const char * const swipe_gesture::command_map[8] = { - "left 3", - "left 4", - "right 3", - "right 4", - "up 3", - "up 4", - "down 3", - "down 4" + "left3", + "left4", + "right3", + "right4", + "up3", + "up4", + "down3", + "down4" }; } diff --git a/lib/service/help.cpp b/lib/service/help.cpp index 6514f24..73096aa 100644 --- a/lib/service/help.cpp +++ b/lib/service/help.cpp @@ -30,7 +30,7 @@ namespace comfortable_swipe::service void help() { using comfortable_swipe::util::conf_filename; - std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|debug]"); + std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|debug|status]"); std::puts(""); std::puts("start - starts 3/4-finger gesture service"); std::puts("stop - stops 3/4-finger gesture service"); diff --git a/lib/service/status.cpp b/lib/service/status.cpp index 7894e76..8bbc82f 100644 --- a/lib/service/status.cpp +++ b/lib/service/status.cpp @@ -26,6 +26,7 @@ along with this program. If not, see . #include // std::array #include // std::atoi #include // FILE, std::feof, std::fgets, std::printf +#include // std::cmatch, std::regex, std::regex_match namespace comfortable_swipe::service { @@ -52,6 +53,44 @@ namespace comfortable_swipe::service // print status std::printf("program is %s\n", running ? "ON" : "OFF"); std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF"); + std::printf("config file at %s\n", comfortable_swipe::util::conf_filename()); + + // check status of configuration file + try + { + auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename()); + + // print keys and values of config file + std::printf("\nConfigurations:\n"); + + // print threshold + if (config.count("threshold") > 0) + { + auto & threshold = config["threshold"]; + + // check if regex pattern matches threshold + std::cmatch matches; + bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0); + + // print status of threshold + std::printf(" %9s is %s (%s)\n", "threshold", ok ? "OK" : "INVALID", threshold.data()); + } + else + std::printf(" %9s is OFF\n", "threshold"); + + // print swipe commands + for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map) + { + if (config.count(command) > 0) + std::printf(" %9s is OK (%s)\n", command, config[command].data()); + else + std::printf(" %9s is OFF\n", command); + } + } + catch (const std::runtime_error& e) + { + std::printf("config error: %s\n", e.what()); + } } } diff --git a/lib/util/read_config_file.cpp b/lib/util/read_config_file.cpp index d3eafb7..9fd5f0b 100644 --- a/lib/util/read_config_file.cpp +++ b/lib/util/read_config_file.cpp @@ -22,32 +22,33 @@ along with this program. If not, see . #include // std::map #include // std::string #include // std::ifstream -#include // std::cerr, std::endl, std::getline +#include // std::ostringstream +#include // std::endl, std::getline #include // exit #include // std::isspace +#include // std::runtime_error namespace comfortable_swipe::util { /** * A utility method for reading the config file. - * + * * @param filename (const char*) the path of the config file. */ std::map read_config_file(const char* filename) { - + std::map conf; std::ifstream fin(filename); if (!fin.is_open()) { - std::cerr << "file \"" << filename << "\" does not exist!" << std::endl; - exit(1); + throw std::runtime_error("config file does not exist"); } static std::string line, token[2]; int line_number = 0; - + while (std::getline(fin, line)) { ++line_number; @@ -55,7 +56,7 @@ namespace comfortable_swipe::util token[1].clear(); int length = line.length(); int equal_flag = 0; - + // tokenize comfig config for (int i = 0; i < length; ++i) { @@ -65,9 +66,10 @@ namespace comfortable_swipe::util { if (++equal_flag > 1) { - std::cerr << "error in conf file " << filename << std::endl; - std::cerr << "multiple equal signs in line " << line_number << std::endl; - exit(1); + std::ostringstream stream; + stream << "error in conf file " << filename << std::endl; + stream << "multiple equal signs in line " << line_number << std::endl; + throw std::runtime_error(stream.str()); } } else if (!std::isspace(line[i])) @@ -84,16 +86,17 @@ namespace comfortable_swipe::util // no equal sign found in non-empty line if (equal_flag == 0) { - std::cerr << "error in conf file: " << filename << std::endl; - std::cerr << "equal sign expected in line " << line_number << std::endl; - exit(1); + std::ostringstream stream; + stream << "error in conf file: " << filename << std::endl; + stream << "equal sign expected in line " << line_number << std::endl; + throw std::runtime_error(stream.str()); } // equal sign found, add to tokens if (token[1].length() > 0) conf[token[0]] = token[1]; } - + return conf; } }