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)
-[](https://www.gnu.org/licenses/gpl-3.0)
+[](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.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/src/main.cpp b/comfortable-swipe.cpp
similarity index 94%
rename from src/main.cpp
rename to comfortable-swipe.cpp
index 6137a06..a880311 100644
--- a/src/main.cpp
+++ b/comfortable-swipe.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();
@@ -45,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/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..9de80c6 100755
--- a/install
+++ b/install
@@ -2,8 +2,9 @@
# 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/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
@@ -16,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
@@ -29,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
@@ -50,7 +67,7 @@ if [ -x "$(command -v $PROGRAM)" ]; then
fi
# compile library
-sudo $DIR/src/compile $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
diff --git a/src/lib/comfortable_swipe b/lib/comfortable_swipe
similarity index 97%
rename from src/lib/comfortable_swipe
rename to lib/comfortable_swipe
index eaa0a08..3316ca4 100644
--- a/src/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/src/lib/gesture/pinch_gesture.cpp b/lib/gesture/pinch_gesture.cpp
similarity index 98%
rename from src/lib/gesture/pinch_gesture.cpp
rename to lib/gesture/pinch_gesture.cpp
index 22beba1..f32f144 100644
--- a/src/lib/gesture/pinch_gesture.cpp
+++ b/lib/gesture/pinch_gesture.cpp
@@ -24,6 +24,7 @@ along with this program. If not, see .
#include // std::cout, std::endl
#include // std::regex, std::cmatch, std::regex_match
#include "xdo_gesture.h"
+#include "pinch_gesture.h"
extern "C"
{
@@ -129,7 +130,7 @@ namespace comfortable_swipe::gesture
return true;
}
}
- else /* !flag_swiping */
+ else /* if (!this->flag_pinching) */
{
// not swiping, check if swipe will begin
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
diff --git a/src/lib/gesture/pinch_gesture.h b/lib/gesture/pinch_gesture.h
similarity index 98%
rename from src/lib/gesture/pinch_gesture.h
rename to lib/gesture/pinch_gesture.h
index 1123cf5..c2ad253 100644
--- a/src/lib/gesture/pinch_gesture.h
+++ b/lib/gesture/pinch_gesture.h
@@ -49,10 +49,10 @@ namespace comfortable_swipe::gesture
inline void update() override;
inline void end() override;
inline bool parse_line(const char *) override;
-
+
protected:
// current location
- float previous_radius;
+ float previous_radius;
float threshold;
int previous_gesture;
bool flag_pinching;
diff --git a/src/lib/gesture/pinch_gesture.regex.cpp b/lib/gesture/pinch_gesture.regex.cpp
similarity index 100%
rename from src/lib/gesture/pinch_gesture.regex.cpp
rename to lib/gesture/pinch_gesture.regex.cpp
diff --git a/src/lib/gesture/swipe_gesture.cpp b/lib/gesture/swipe_gesture.cpp
similarity index 92%
rename from src/lib/gesture/swipe_gesture.cpp
rename to lib/gesture/swipe_gesture.cpp
index 5fb4a00..3d3d946 100644
--- a/src/lib/gesture/swipe_gesture.cpp
+++ b/lib/gesture/swipe_gesture.cpp
@@ -23,6 +23,7 @@ along with this program. If not, see .
#include // std::regex, std::regex_match
#include // std::stof, std::stoi
#include "xdo_gesture.h"
+#include "swipe_gesture.h"
extern "C"
{
@@ -51,7 +52,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.
@@ -147,40 +151,43 @@ namespace comfortable_swipe::gesture
// currently swiping
if (std::regex_match(line, matches, gesture_swipe_update) != 0)
{
- // update swipe
+ // 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)
{
- // end swipe
+ // assign necessary variables for swipe end
this->flag_swiping = false;
this->fingers = std::stoi(matches[1]);
+ // dispatch end
this->end();
return true;
}
}
- else /* !flag_swiping */
+ else /* if (!this->flag_swiping) */
{
// not swiping, check if swipe will begin
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
{
- // begin swipe
+ // 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/src/lib/gesture/swipe_gesture.h b/lib/gesture/swipe_gesture.h
similarity index 96%
rename from src/lib/gesture/swipe_gesture.h
rename to lib/gesture/swipe_gesture.h
index 9f341e4..b55f774 100644
--- a/src/lib/gesture/swipe_gesture.h
+++ b/lib/gesture/swipe_gesture.h
@@ -53,7 +53,7 @@ namespace comfortable_swipe::gesture
inline void update() override;
inline void end() override;
inline bool parse_line(const char *) override;
-
+
protected:
// location of mouse
int screen_num, ix, iy;
@@ -61,9 +61,11 @@ namespace comfortable_swipe::gesture
// current location
float x, y, threshold_squared;
int previous_gesture;
- bool flag_swiping;
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/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 98%
rename from src/lib/index.hpp
rename to lib/index.hpp
index b0c7e2e..21a36a7 100644
--- a/src/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/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 86%
rename from src/lib/service/buffer.cpp
rename to lib/service/buffer.cpp
index c2299bb..14b421a 100644
--- a/src/lib/service/buffer.cpp
+++ b/lib/service/buffer.cpp
@@ -33,7 +33,7 @@ namespace comfortable_swipe::service
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
// 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(),
@@ -48,12 +48,13 @@ namespace comfortable_swipe::service
// prepare data containers
static const int MAX_LINE_LENGTH = 256;
- static char line[MAX_LINE_LENGTH];
+ static char data[MAX_LINE_LENGTH];
// start reading lines from input one by one
- while (fgets_unlocked(line, MAX_LINE_LENGTH, stdin) != NULL)
+ while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL)
{
- swipe.parse_line(line);
+ // attempt to parse swipe gestures
+ swipe_gesture_handler.parse_line(data);
}
}
}
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/src/lib/service/help.cpp b/lib/service/help.cpp
similarity index 93%
rename from src/lib/service/help.cpp
rename to lib/service/help.cpp
index c73baf7..e1355e6 100644
--- a/src/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());
}
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
index 67bbaf0..28191c8 100644
--- a/src/lib/service/restart.cpp
+++ b/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();
}
}
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/compile b/src/compile
deleted file mode 100755
index d426b80..0000000
--- a/src/compile
+++ /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/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