From 0b3b3238affc0ec691d1a34fa8d326cd4eebe823 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Fri, 8 Feb 2019 16:58:27 +0800 Subject: [PATCH 1/7] Fix bug in restart service (#47) --- src/lib/service/restart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/service/restart.cpp b/src/lib/service/restart.cpp index 67bbaf0..28191c8 100644 --- a/src/lib/service/restart.cpp +++ b/src/lib/service/restart.cpp @@ -28,8 +28,8 @@ namespace comfortable_swipe::service */ void restart() { - comfortable_swipe::service::start(); comfortable_swipe::service::stop(); + comfortable_swipe::service::start(); } } From 68bea125e3621d1de2097489ad00294a7e51ff54 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 17:50:58 +0800 Subject: [PATCH 2/7] Improve responsiveness of initial gesture by pre-empting xdotool in swipe_gesture constructor (#49) --- src/lib/gesture/swipe_gesture.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/gesture/swipe_gesture.cpp b/src/lib/gesture/swipe_gesture.cpp index 1340a54..f2d0c02 100644 --- a/src/lib/gesture/swipe_gesture.cpp +++ b/src/lib/gesture/swipe_gesture.cpp @@ -49,7 +49,10 @@ namespace comfortable_swipe::gesture comfortable_swipe::gesture::xdo_gesture(), threshold_squared(threshold*threshold), commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}) - { } + { + // improve responsiveness of first gesture by pre-empting xdotool runtime + xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num); + } /** * Destructs this swipe gesture. From 602b148fb4157f29931261212a2f1ea9f577ae3d Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 19:04:31 +0800 Subject: [PATCH 3/7] Move library to root --- src/compile => compile.sh | 0 src/defaults.conf => defaults.conf | 0 install | 4 ++-- {src/lib => lib}/comfortable_swipe | 0 {src/lib => lib}/gesture/swipe_gesture.cpp | 0 {src/lib => lib}/gesture/swipe_gesture.h | 0 {src/lib => lib}/gesture/swipe_gesture.regex.cpp | 0 {src/lib => lib}/gesture/xdo_gesture.cpp | 0 {src/lib => lib}/gesture/xdo_gesture.h | 0 {src/lib => lib}/index.hpp | 0 {src/lib => lib}/service/autostart.cpp | 0 {src/lib => lib}/service/buffer.cpp | 0 {src/lib => lib}/service/help.cpp | 0 {src/lib => lib}/service/restart.cpp | 0 {src/lib => lib}/service/start.cpp | 0 {src/lib => lib}/service/stop.cpp | 0 {src/lib => lib}/util/autostart_filename.cpp | 0 {src/lib => lib}/util/conf_filename.cpp | 0 {src/lib => lib}/util/read_config_file.cpp | 0 src/main.cpp => main.cpp | 6 ++---- tests/test_regex.cpp | 4 ++-- 21 files changed, 6 insertions(+), 8 deletions(-) rename src/compile => compile.sh (100%) rename src/defaults.conf => defaults.conf (100%) rename {src/lib => lib}/comfortable_swipe (100%) rename {src/lib => lib}/gesture/swipe_gesture.cpp (100%) rename {src/lib => lib}/gesture/swipe_gesture.h (100%) rename {src/lib => lib}/gesture/swipe_gesture.regex.cpp (100%) rename {src/lib => lib}/gesture/xdo_gesture.cpp (100%) rename {src/lib => lib}/gesture/xdo_gesture.h (100%) rename {src/lib => lib}/index.hpp (100%) rename {src/lib => lib}/service/autostart.cpp (100%) rename {src/lib => lib}/service/buffer.cpp (100%) rename {src/lib => lib}/service/help.cpp (100%) rename {src/lib => lib}/service/restart.cpp (100%) rename {src/lib => lib}/service/start.cpp (100%) rename {src/lib => lib}/service/stop.cpp (100%) rename {src/lib => lib}/util/autostart_filename.cpp (100%) rename {src/lib => lib}/util/conf_filename.cpp (100%) rename {src/lib => lib}/util/read_config_file.cpp (100%) rename src/main.cpp => main.cpp (96%) diff --git a/src/compile b/compile.sh similarity index 100% rename from src/compile rename to compile.sh diff --git a/src/defaults.conf b/defaults.conf similarity index 100% rename from src/defaults.conf rename to defaults.conf diff --git a/install b/install index d81d328..6f9cf51 100755 --- a/install +++ b/install @@ -3,7 +3,7 @@ DIR=$(dirname $0) PROGRAM=/usr/local/bin/comfortable-swipe CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf -DCONF_PATH=$DIR/src/defaults.conf +DCONF_PATH=$DIR/defaults.conf OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf if [ -x "$(command -v $PROGRAM)" ]; then @@ -50,7 +50,7 @@ if [ -x "$(command -v $PROGRAM)" ]; then fi # compile library -sudo $DIR/src/compile $PROGRAM || abort +sudo $DIR/compile.sh $PROGRAM || abort # add permissions to input group (defer) # GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort diff --git a/src/lib/comfortable_swipe b/lib/comfortable_swipe similarity index 100% rename from src/lib/comfortable_swipe rename to lib/comfortable_swipe diff --git a/src/lib/gesture/swipe_gesture.cpp b/lib/gesture/swipe_gesture.cpp similarity index 100% rename from src/lib/gesture/swipe_gesture.cpp rename to lib/gesture/swipe_gesture.cpp diff --git a/src/lib/gesture/swipe_gesture.h b/lib/gesture/swipe_gesture.h similarity index 100% rename from src/lib/gesture/swipe_gesture.h rename to lib/gesture/swipe_gesture.h diff --git a/src/lib/gesture/swipe_gesture.regex.cpp b/lib/gesture/swipe_gesture.regex.cpp similarity index 100% rename from src/lib/gesture/swipe_gesture.regex.cpp rename to lib/gesture/swipe_gesture.regex.cpp diff --git a/src/lib/gesture/xdo_gesture.cpp b/lib/gesture/xdo_gesture.cpp similarity index 100% rename from src/lib/gesture/xdo_gesture.cpp rename to lib/gesture/xdo_gesture.cpp diff --git a/src/lib/gesture/xdo_gesture.h b/lib/gesture/xdo_gesture.h similarity index 100% rename from src/lib/gesture/xdo_gesture.h rename to lib/gesture/xdo_gesture.h diff --git a/src/lib/index.hpp b/lib/index.hpp similarity index 100% rename from src/lib/index.hpp rename to lib/index.hpp diff --git a/src/lib/service/autostart.cpp b/lib/service/autostart.cpp similarity index 100% rename from src/lib/service/autostart.cpp rename to lib/service/autostart.cpp diff --git a/src/lib/service/buffer.cpp b/lib/service/buffer.cpp similarity index 100% rename from src/lib/service/buffer.cpp rename to lib/service/buffer.cpp diff --git a/src/lib/service/help.cpp b/lib/service/help.cpp similarity index 100% rename from src/lib/service/help.cpp rename to lib/service/help.cpp diff --git a/src/lib/service/restart.cpp b/lib/service/restart.cpp similarity index 100% rename from src/lib/service/restart.cpp rename to lib/service/restart.cpp diff --git a/src/lib/service/start.cpp b/lib/service/start.cpp similarity index 100% rename from src/lib/service/start.cpp rename to lib/service/start.cpp diff --git a/src/lib/service/stop.cpp b/lib/service/stop.cpp similarity index 100% rename from src/lib/service/stop.cpp rename to lib/service/stop.cpp diff --git a/src/lib/util/autostart_filename.cpp b/lib/util/autostart_filename.cpp similarity index 100% rename from src/lib/util/autostart_filename.cpp rename to lib/util/autostart_filename.cpp diff --git a/src/lib/util/conf_filename.cpp b/lib/util/conf_filename.cpp similarity index 100% rename from src/lib/util/conf_filename.cpp rename to lib/util/conf_filename.cpp diff --git a/src/lib/util/read_config_file.cpp b/lib/util/read_config_file.cpp similarity index 100% rename from src/lib/util/read_config_file.cpp rename to lib/util/read_config_file.cpp diff --git a/src/main.cpp b/main.cpp similarity index 96% rename from src/main.cpp rename to main.cpp index 8698f1b..de1118b 100644 --- a/src/main.cpp +++ b/main.cpp @@ -16,8 +16,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -// Compile: g++ main.cpp -std=c++11 -lxdo - #include // std::string #include "lib/comfortable_swipe" @@ -28,7 +26,7 @@ int main(int argc, char** args) if (argc > 1) { std::string arg = args[1]; - + // select based on argument if (arg == "start") comfortable_swipe::service::start(); @@ -52,4 +50,4 @@ int main(int argc, char** args) comfortable_swipe::service::help(); return 0; -} \ No newline at end of file +} diff --git a/tests/test_regex.cpp b/tests/test_regex.cpp index a54fd2f..f2a524b 100644 --- a/tests/test_regex.cpp +++ b/tests/test_regex.cpp @@ -2,8 +2,8 @@ #include #include #include -#include "../src/lib/gesture/swipe_gesture.h" -#include "../src/lib/gesture/swipe_gesture.regex.cpp" +#include "../lib/gesture/swipe_gesture.h" +#include "../lib/gesture/swipe_gesture.regex.cpp" /* Comfortable Swipe From 7923effa021508060c90fcd2198d9002998701f2 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 19:07:30 +0800 Subject: [PATCH 4/7] Simplify compile command structure --- comfortable-swipe.compile.sh | 2 ++ main.cpp => comfortable-swipe.cpp | 0 compile.sh | 2 -- install | 3 ++- 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100755 comfortable-swipe.compile.sh rename main.cpp => comfortable-swipe.cpp (100%) delete mode 100755 compile.sh diff --git a/comfortable-swipe.compile.sh b/comfortable-swipe.compile.sh new file mode 100755 index 0000000..d839b64 --- /dev/null +++ b/comfortable-swipe.compile.sh @@ -0,0 +1,2 @@ +#!/bin/sh +g++ $(dirname $0)/comfortable-swipe.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1 diff --git a/main.cpp b/comfortable-swipe.cpp similarity index 100% rename from main.cpp rename to comfortable-swipe.cpp diff --git a/compile.sh b/compile.sh deleted file mode 100755 index d426b80..0000000 --- a/compile.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -g++ $(dirname $0)/main.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1 diff --git a/install b/install index 6f9cf51..bc8083b 100755 --- a/install +++ b/install @@ -2,6 +2,7 @@ # prefer running as root DIR=$(dirname $0) PROGRAM=/usr/local/bin/comfortable-swipe +COMPILE=$DIR/comfortable-swipe.compile.sh CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf DCONF_PATH=$DIR/defaults.conf OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf @@ -50,7 +51,7 @@ if [ -x "$(command -v $PROGRAM)" ]; then fi # compile library -sudo $DIR/compile.sh $PROGRAM || abort +sudo $COMPILE $PROGRAM || abort # add permissions to input group (defer) # GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort From 459fd68ba857ae81abc513d867758ecf83df51fd Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 19:28:53 +0800 Subject: [PATCH 5/7] Add parse_line method to decouple buffer from gesture handler (#50) --- lib/gesture/swipe_gesture.cpp | 63 ++++++++++++++++++++++++++++++++++- lib/gesture/swipe_gesture.h | 6 +++- lib/gesture/xdo_gesture.h | 1 + lib/service/buffer.cpp | 48 ++------------------------ 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/lib/gesture/swipe_gesture.cpp b/lib/gesture/swipe_gesture.cpp index f2d0c02..dc30766 100644 --- a/lib/gesture/swipe_gesture.cpp +++ b/lib/gesture/swipe_gesture.cpp @@ -20,7 +20,9 @@ along with this program. If not, see . */ #include // std::cout, std::endl -#include "xdo_gesture.h" +#include // std::stoi, std::stof +#include // std::regex, std::regex_match, std::cmatch +#include "swipe_gesture.h" extern "C" { @@ -127,6 +129,65 @@ namespace comfortable_swipe::gesture void swipe_gesture::end() { } + /** + * Dispatches begin/update/end depending on the regex pattern provided by this class. + * + * @param line the line from libinput debug-events to parse + * @return true if begin/update/end was dispatched + */ + bool swipe_gesture::parse_line(const char * line) + { + + // prepare regex matchers (will only load at most once) + static const std::regex gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN); + static const std::regex gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN); + static const std::regex gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN); + + // prepare holder for regex matches + static std::cmatch matches; + + if (this->flag_swiping) + { + // currently swiping + if (std::regex_match(line, matches, gesture_swipe_update) != 0) + { + // assign necessary variables for swipe update + this->fingers = std::stoi(matches[1]); + this->dx = std::stof(matches[2]); + this->dy = std::stof(matches[3]); + this->udx = std::stof(matches[4]); + this->udy = std::stof(matches[5]); + // dispatch update + this->update(); + return true; + } + else if (std::regex_match(line, matches, gesture_swipe_end) != 0) + { + // assign necessary variables for swipe end + this->flag_swiping = false; + this->fingers = std::stoi(matches[1]); + // dispatch end + this->end(); + return true; + } + } + else + { + // not swiping, check if swipe will begin + if (std::regex_match(line, matches, gesture_swipe_begin) != 0) + { + // assign necessary variables for swipe begin + this->flag_swiping = true; + this->fingers = std::stoi(matches[1]); + // dispatch begin + this->begin(); + return true; + } + } + + return false; + } + /* STATICS DEFINITIONS */ const int swipe_gesture::MSK_THREE_FINGERS = 0; const int swipe_gesture::MSK_FOUR_FINGERS = 1; diff --git a/lib/gesture/swipe_gesture.h b/lib/gesture/swipe_gesture.h index 4061aec..86ec3bd 100644 --- a/lib/gesture/swipe_gesture.h +++ b/lib/gesture/swipe_gesture.h @@ -52,7 +52,8 @@ namespace comfortable_swipe::gesture void begin() override; void update() override; void end() override; - + bool parse_line(const char *) override; + protected: // location of mouse int screen_num, ix, iy; @@ -62,6 +63,9 @@ namespace comfortable_swipe::gesture int previous_gesture; const char ** commands; + // optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched + bool flag_swiping; + public: // static constants static const int MSK_THREE_FINGERS; diff --git a/lib/gesture/xdo_gesture.h b/lib/gesture/xdo_gesture.h index ef9d181..37eb157 100644 --- a/lib/gesture/xdo_gesture.h +++ b/lib/gesture/xdo_gesture.h @@ -45,6 +45,7 @@ namespace comfortable_swipe virtual void begin() = 0; virtual void update() = 0; virtual void end() = 0; + virtual bool parse_line(const char *) = 0; }; } } diff --git a/lib/service/buffer.cpp b/lib/service/buffer.cpp index f3c9517..14b421a 100644 --- a/lib/service/buffer.cpp +++ b/lib/service/buffer.cpp @@ -19,9 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include // std::stoi, std::stof #include // std::fgets_unlocked, stdin -#include // std::regex, std::regex_match, std::cmatch #include "../index.hpp" /** @@ -34,13 +32,8 @@ namespace comfortable_swipe::service // read config file auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename()); - // pre-compile regex patterns - static const std::regex gesture_swipe_begin(comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN); - static const std::regex gesture_swipe_update(comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN); - static const std::regex gesture_swipe_end(comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN); - // initialize swipe gesture handler - comfortable_swipe::gesture::swipe_gesture swipe + comfortable_swipe::gesture::swipe_gesture swipe_gesture_handler ( config.count("threshold") ? std::stof(config["threshold"]) : 0.0, config["left3"].c_str(), @@ -56,47 +49,12 @@ namespace comfortable_swipe::service // prepare data containers static const int MAX_LINE_LENGTH = 256; static char data[MAX_LINE_LENGTH]; - static std::cmatch matches; - - // optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched - bool flag_swiping = false; // start reading lines from input one by one while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL) { - if (flag_swiping) - { - // currently swiping - if (std::regex_match(data, matches, gesture_swipe_update) != 0) - { - // update swipe - swipe.fingers = std::stoi(matches[1]); - swipe.dx = std::stof(matches[2]); - swipe.dy = std::stof(matches[3]); - swipe.udx = std::stof(matches[4]); - swipe.udy = std::stof(matches[5]); - swipe.update(); - } - else if (std::regex_match(data, matches, gesture_swipe_end) != 0) - { - // end swipe - flag_swiping = false; - swipe.fingers = std::stoi(matches[1]); - swipe.end(); - } - } - else /* !flag_swiping */ - { - // not swiping, check if swipe will begin - if (std::regex_match(data, matches, gesture_swipe_begin) != 0) - { - // begin swipe - flag_swiping = true; - swipe.fingers = std::stoi(matches[1]); - swipe.begin(); - } - } - + // attempt to parse swipe gestures + swipe_gesture_handler.parse_line(data); } } } From 16742495eb98076158e844085b7aff57aa227204 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 20:18:15 +0800 Subject: [PATCH 6/7] Add debug command (#51) * Add debug command * Update README to include debugging --- README.md | 39 ++++++++++++++++++++++++++++++++++----- comfortable-swipe.cpp | 3 +++ lib/comfortable_swipe | 1 + lib/index.hpp | 1 + lib/service/debug.cpp | 35 +++++++++++++++++++++++++++++++++++ lib/service/help.cpp | 3 ++- 6 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 lib/service/debug.cpp diff --git a/README.md b/README.md index d487f8c..afd62d5 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ # Comfortable Swipe (Ubuntu) -[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) +[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures for Ubuntu 14.04 LTS and beyond. May work for other Linux distros that support `libinput`. ## Installation 1. Install git, libinput, and g++ - + ```bash sudo apt-get install git libinput-tools libxdo-dev g++ ``` 2. Clone this repository - + ```bash git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git cd comfortable-swipe-ubuntu @@ -41,7 +41,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures ``` comfortable-swipe autostart ``` -5. _Optional_: Change keyboard [configurations](#configurations). After making changes, run +5. _Optional_: Change [configurations](#configurations) (see below). After making changes, run ``` comfortable-swipe restart ``` @@ -78,9 +78,38 @@ Taken from `man xdotool`: Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use. +## 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. + +A working swipe gesture will show the following: + +```bash +$ comfortable-swipe debug +... +-event9 DEVICE_ADDED TouchPad seat0 default group7 cap:pg size 70x50mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on +... +event9 GESTURE_SWIPE_BEGIN +2.03s 3 + event9 GESTURE_SWIPE_UPDATE +2.03s 3 -9.95/ 2.64 (-26.90/ 7.12 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.03s 3 -10.44/ 3.19 (-28.22/ 8.62 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.04s 3 -9.71/ 2.64 (-26.25/ 7.12 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.05s 3 -8.98/ 2.64 (-24.28/ 7.12 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.06s 3 -7.40/ 2.36 (-20.01/ 6.37 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.06s 3 -6.31/ 2.50 (-17.06/ 6.75 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.07s 3 -5.34/ 1.80 (-14.44/ 4.87 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.08s 3 -4.61/ 2.08 (-12.47/ 5.62 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.09s 3 -4.49/ 1.53 (-12.14/ 4.12 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.09s 3 -4.01/ 1.25 (-10.83/ 3.37 unaccelerated) + event9 GESTURE_SWIPE_UPDATE +2.10s 3 -4.13/ 0.42 (-11.15/ 1.12 unaccelerated) + event9 GESTURE_SWIPE_END +2.11s 3 + ... +``` + +If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supports multi-touch swipe gestures. ## Uninstall -Download the `uninstall` script then run `bash uninstall` +Download the `uninstall` script then run `bash uninstall` + ## Bug Reports Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug. diff --git a/comfortable-swipe.cpp b/comfortable-swipe.cpp index de1118b..a880311 100644 --- a/comfortable-swipe.cpp +++ b/comfortable-swipe.cpp @@ -43,6 +43,9 @@ int main(int argc, char** args) else if (arg == "autostart") comfortable_swipe::service::autostart(); + else if (arg == "debug") + comfortable_swipe::service::debug(); + else /* if (arg == "help") */ comfortable_swipe::service::help(); } diff --git a/lib/comfortable_swipe b/lib/comfortable_swipe index eaa0a08..3316ca4 100644 --- a/lib/comfortable_swipe +++ b/lib/comfortable_swipe @@ -30,6 +30,7 @@ along with this program. If not, see . #include "gesture/swipe_gesture.regex.cpp" #include "service/autostart.cpp" #include "service/buffer.cpp" +#include "service/debug.cpp" #include "service/help.cpp" #include "service/restart.cpp" #include "service/start.cpp" diff --git a/lib/index.hpp b/lib/index.hpp index b0c7e2e..21a36a7 100644 --- a/lib/index.hpp +++ b/lib/index.hpp @@ -50,6 +50,7 @@ extern "C" { void autostart(); void buffer(); + void debug(); void help(); void restart(); void start(); diff --git a/lib/service/debug.cpp b/lib/service/debug.cpp new file mode 100644 index 0000000..cb95936 --- /dev/null +++ b/lib/service/debug.cpp @@ -0,0 +1,35 @@ +#ifndef __COMFORTABLE_SWIPE__service_debug__ +#define __COMFORTABLE_SWIPE__service_debug__ + +/* +Comfortable Swipe +by Rico Tiongson + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include // std::system + +namespace comfortable_swipe::service +{ + /** + * Debugs output from `libinput debug-events`. + */ + void debug() + { + (void) std::system("stdbuf -oL -e0 libinput debug-events"); + } +} + +#endif /* __COMFORTABLE_SWIPE__service_debug__ */ diff --git a/lib/service/help.cpp b/lib/service/help.cpp index c73baf7..e1355e6 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]"); + std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|debug]"); std::puts(""); std::puts("start - starts 3/4-finger gesture service"); std::puts("stop - stops 3/4-finger gesture service"); @@ -38,6 +38,7 @@ namespace comfortable_swipe::service std::puts("autostart - automatically run on startup (toggleable)"); std::puts("buffer - parses output of libinput debug-events"); std::puts("help - shows the help dialog"); + std::puts("debug - logs raw output from input events taken from libinput"); std::puts(""); std::printf("Configuration file can be found in %s\n", conf_filename()); } From 1c9b497b563edb301b0ef8cd800dfdab2b3dbdb1 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 12 Feb 2019 21:13:40 +0800 Subject: [PATCH 7/7] Add default -y flag to install --- install | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/install b/install index bc8083b..9de80c6 100755 --- a/install +++ b/install @@ -17,6 +17,20 @@ abort () { exec echo "Installation aborted" } sudo mkdir -p $(dirname $CONF_PATH) || abort + +# check if "-y" or "--yes" is passed as an argument +YES=false +while test $# -gt 0 +do + case "$1" in + -y) YES=true + ;; + --yes) YES=true + ;; + esac + shift +done + sudo chown $USER $(dirname $CONF_PATH) if [ ! -f $CONF_PATH ]; then if [ ! -f $OLD_CONF_PATH ]; then @@ -30,15 +44,17 @@ if [ ! -f $CONF_PATH ]; then else # config file found, ask user if overwrite echo "Old conf file found in $CONF_PATH" - read -r -p "Keep the old conf file? (default: yes) [Y/n] " response - response=${response,,} # tolower - if [[ "$response" =~ ^(no|n)$ ]]; then - read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response - response=${response,,} - if [[ "$response" =~ ^(yes|y)$ ]]; then - cat $DCONF_PATH > $CONF_PATH || abort - else - abort + if [ $YES == false ]; then + read -r -p "Keep the old conf file? (default: yes) [Y/n] " response + response=${response,,} # tolower + if [[ "$response" =~ ^(no|n)$ ]]; then + read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response + response=${response,,} + if [[ "$response" =~ ^(yes|y)$ ]]; then + cat $DCONF_PATH > $CONF_PATH || abort + else + abort + fi fi fi fi