Merge current branch with upstream 'master'
This commit is contained in:
commit
0fdf94b723
39
README.md
39
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.
|
||||
|
||||
2
comfortable-swipe.compile.sh
Executable file
2
comfortable-swipe.compile.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
g++ $(dirname $0)/comfortable-swipe.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1
|
||||
@ -16,8 +16,6 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// Compile: g++ main.cpp -std=c++11 -lxdo
|
||||
|
||||
#include <string> // 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();
|
||||
}
|
||||
39
install
39
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
|
||||
|
||||
@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#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"
|
||||
@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <iostream> // std::cout, std::endl
|
||||
#include <regex> // 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)
|
||||
@ -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;
|
||||
@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <regex> // std::regex, std::regex_match
|
||||
#include <string> // 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;
|
||||
@ -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;
|
||||
@ -50,6 +50,7 @@ extern "C"
|
||||
{
|
||||
void autostart();
|
||||
void buffer();
|
||||
void debug();
|
||||
void help();
|
||||
void restart();
|
||||
void start();
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
lib/service/debug.cpp
Normal file
35
lib/service/debug.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cstdlib> // 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__ */
|
||||
@ -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());
|
||||
}
|
||||
@ -28,8 +28,8 @@ namespace comfortable_swipe::service
|
||||
*/
|
||||
void restart()
|
||||
{
|
||||
comfortable_swipe::service::start();
|
||||
comfortable_swipe::service::stop();
|
||||
comfortable_swipe::service::start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
g++ $(dirname $0)/main.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1
|
||||
@ -2,8 +2,8 @@
|
||||
#include <cassert>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user