Compare commits
11
Commits
v1.0.1
...
feature-pinch
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a47c7f8115 | ||
|
|
0fdf94b723 | ||
|
|
1c9b497b56 | ||
|
|
16742495eb | ||
|
|
459fd68ba8 | ||
|
|
7923effa02 | ||
|
|
602b148fb4 | ||
|
|
bf09ee79f5 | ||
|
|
7b0502c0b7 | ||
|
|
48a79607dc | ||
|
|
e7573938b4 |
No files matched your search
@@ -1,2 +1,5 @@
|
|||||||
# C++ generated headers
|
# C++ generated headers
|
||||||
*.gch
|
*.gch
|
||||||
|
|
||||||
|
# IDE-specific
|
||||||
|
.vscode
|
||||||
@@ -1,18 +1,18 @@
|
|||||||
# Comfortable Swipe (Ubuntu)
|
# 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`.
|
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
|
## Installation
|
||||||
|
|
||||||
1. Install git, libinput, and g++
|
1. Install git, libinput, and g++
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt-get install git libinput-tools libxdo-dev g++
|
sudo apt-get install git libinput-tools libxdo-dev g++
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Clone this repository
|
2. Clone this repository
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git
|
git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git
|
||||||
cd comfortable-swipe-ubuntu
|
cd comfortable-swipe-ubuntu
|
||||||
@@ -41,7 +41,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
```
|
```
|
||||||
comfortable-swipe autostart
|
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
|
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.
|
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
|
## Uninstall
|
||||||
Download the `uninstall` script then run `bash uninstall`
|
Download the `uninstall` script then run `bash uninstall`
|
||||||
|
|
||||||
|
|
||||||
## Bug Reports
|
## Bug Reports
|
||||||
Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug.
|
Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug.
|
||||||
Executable
+2
@@ -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/>.
|
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 <string> // std::string
|
||||||
#include "lib/comfortable_swipe"
|
#include "lib/comfortable_swipe"
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ int main(int argc, char** args)
|
|||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
std::string arg = args[1];
|
std::string arg = args[1];
|
||||||
|
|
||||||
// select based on argument
|
// select based on argument
|
||||||
if (arg == "start")
|
if (arg == "start")
|
||||||
comfortable_swipe::service::start();
|
comfortable_swipe::service::start();
|
||||||
@@ -45,6 +43,9 @@ int main(int argc, char** args)
|
|||||||
else if (arg == "autostart")
|
else if (arg == "autostart")
|
||||||
comfortable_swipe::service::autostart();
|
comfortable_swipe::service::autostart();
|
||||||
|
|
||||||
|
else if (arg == "debug")
|
||||||
|
comfortable_swipe::service::debug();
|
||||||
|
|
||||||
else /* if (arg == "help") */
|
else /* if (arg == "help") */
|
||||||
comfortable_swipe::service::help();
|
comfortable_swipe::service::help();
|
||||||
}
|
}
|
||||||
@@ -52,4 +53,4 @@ int main(int argc, char** args)
|
|||||||
comfortable_swipe::service::help();
|
comfortable_swipe::service::help();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
File renamed without changes.
@@ -2,8 +2,9 @@
|
|||||||
# prefer running as root
|
# prefer running as root
|
||||||
DIR=$(dirname $0)
|
DIR=$(dirname $0)
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
PROGRAM=/usr/local/bin/comfortable-swipe
|
||||||
|
COMPILE=$DIR/comfortable-swipe.compile.sh
|
||||||
CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf
|
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
|
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
||||||
|
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
if [ -x "$(command -v $PROGRAM)" ]; then
|
||||||
@@ -16,6 +17,20 @@ abort () {
|
|||||||
exec echo "Installation aborted"
|
exec echo "Installation aborted"
|
||||||
}
|
}
|
||||||
sudo mkdir -p $(dirname $CONF_PATH) || abort
|
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)
|
sudo chown $USER $(dirname $CONF_PATH)
|
||||||
if [ ! -f $CONF_PATH ]; then
|
if [ ! -f $CONF_PATH ]; then
|
||||||
if [ ! -f $OLD_CONF_PATH ]; then
|
if [ ! -f $OLD_CONF_PATH ]; then
|
||||||
@@ -29,15 +44,17 @@ if [ ! -f $CONF_PATH ]; then
|
|||||||
else
|
else
|
||||||
# config file found, ask user if overwrite
|
# config file found, ask user if overwrite
|
||||||
echo "Old conf file found in $CONF_PATH"
|
echo "Old conf file found in $CONF_PATH"
|
||||||
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
if [ $YES == false ]; then
|
||||||
response=${response,,} # tolower
|
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
||||||
if [[ "$response" =~ ^(no|n)$ ]]; then
|
response=${response,,} # tolower
|
||||||
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
if [[ "$response" =~ ^(no|n)$ ]]; then
|
||||||
response=${response,,}
|
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
||||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
response=${response,,}
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
||||||
else
|
cat $DCONF_PATH > $CONF_PATH || abort
|
||||||
abort
|
else
|
||||||
|
abort
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -50,7 +67,7 @@ if [ -x "$(command -v $PROGRAM)" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# compile library
|
# compile library
|
||||||
sudo $DIR/src/compile $PROGRAM || abort
|
sudo $COMPILE $PROGRAM || abort
|
||||||
|
|
||||||
# add permissions to input group (defer)
|
# add permissions to input group (defer)
|
||||||
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "gesture/xdo_gesture.cpp"
|
#include "gesture/xdo_gesture.cpp"
|
||||||
#include "gesture/swipe_gesture.cpp"
|
#include "gesture/swipe_gesture.cpp"
|
||||||
#include "gesture/swipe_gesture.regex.cpp"
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
|
#include "gesture/pinch_gesture.cpp"
|
||||||
|
#include "gesture/pinch_gesture.regex.cpp"
|
||||||
#include "service/autostart.cpp"
|
#include "service/autostart.cpp"
|
||||||
#include "service/buffer.cpp"
|
#include "service/buffer.cpp"
|
||||||
|
#include "service/debug.cpp"
|
||||||
#include "service/help.cpp"
|
#include "service/help.cpp"
|
||||||
#include "service/restart.cpp"
|
#include "service/restart.cpp"
|
||||||
#include "service/start.cpp"
|
#include "service/start.cpp"
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
/* WARNING: pinch gestures are experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <iostream> // std::cout, std::endl
|
||||||
|
#include <regex> // std::regex, std::cmatch, std::regex_match
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
#include "pinch_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a new pinch gesture, given configurations for certain pinch events.
|
||||||
|
*/
|
||||||
|
pinch_gesture::pinch_gesture
|
||||||
|
(
|
||||||
|
const float threshold,
|
||||||
|
const char* pinch_in3,
|
||||||
|
const char* pinch_in4,
|
||||||
|
const char* pinch_out3,
|
||||||
|
const char* pinch_out4
|
||||||
|
):
|
||||||
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
|
threshold(threshold),
|
||||||
|
commands(new const char*[4]{pinch_in3, pinch_in4, pinch_out3, pinch_out4})
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this pinch gesture.
|
||||||
|
*/
|
||||||
|
pinch_gesture::~pinch_gesture()
|
||||||
|
{
|
||||||
|
delete[] commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of pinch gesture.
|
||||||
|
*/
|
||||||
|
inline void pinch_gesture::begin()
|
||||||
|
{
|
||||||
|
this->previous_gesture = pinch_gesture::FRESH;
|
||||||
|
this->previous_radius = this->radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
inline void pinch_gesture::update()
|
||||||
|
{
|
||||||
|
float delta_radius = this->radius - this->previous_radius;
|
||||||
|
this->previous_radius = this->radius;
|
||||||
|
|
||||||
|
// TODO: use a different epsilon threshold
|
||||||
|
const float EPSILON = this->threshold;
|
||||||
|
if (delta_radius > EPSILON)
|
||||||
|
{
|
||||||
|
if (this->previous_gesture != 0)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
std::cout << "PINCH OUT" << std::endl;
|
||||||
|
this->previous_gesture = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (delta_radius < -EPSILON)
|
||||||
|
{
|
||||||
|
if (this->previous_gesture != 1)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
std::cout << "PINCH IN" << std::endl;
|
||||||
|
this->previous_gesture = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
inline void pinch_gesture::end()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an output line and dispatches pinch begin/update/end upon match.
|
||||||
|
* Uses GESTURE_BEGIN_REGEX_PATTERN for begin,
|
||||||
|
* GESTURE_UPDATE_REGEX_PATTERN for update,
|
||||||
|
* GESTURE_END_REGEX_PATTERN for end.
|
||||||
|
*
|
||||||
|
* @param line the output line from libinput debug-events
|
||||||
|
* @return true if line matches this gesture
|
||||||
|
*/
|
||||||
|
inline bool pinch_gesture::parse_line(const char * line)
|
||||||
|
{
|
||||||
|
// pre-compile regex patterns
|
||||||
|
static const std::regex gesture_swipe_begin(pinch_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_update(pinch_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_end(pinch_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
|
std::cmatch matches;
|
||||||
|
if (this->flag_pinching)
|
||||||
|
{
|
||||||
|
// currently pinching
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_update) != 0)
|
||||||
|
{
|
||||||
|
// update pinch
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->radius = std::stof(matches[2]);
|
||||||
|
this->update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (std::regex_match(line, matches, gesture_swipe_end) != 0)
|
||||||
|
{
|
||||||
|
// end pinch
|
||||||
|
this->flag_pinching = false;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->end();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* if (!this->flag_pinching) */
|
||||||
|
{
|
||||||
|
// not swiping, check if swipe will begin
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
|
||||||
|
{
|
||||||
|
// begin swipe
|
||||||
|
this->flag_pinching = true;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->begin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* STATICS DEFINITIONS */
|
||||||
|
const int pinch_gesture::MSK_THREE_FINGERS = 0;
|
||||||
|
const int pinch_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
|
const int pinch_gesture::MSK_NEGATIVE = 0;
|
||||||
|
const int pinch_gesture::MSK_POSITIVE = 2;
|
||||||
|
const int pinch_gesture::FRESH = -1;
|
||||||
|
const char * const pinch_gesture::command_map[4] = {
|
||||||
|
"pinch_in 3",
|
||||||
|
"pinch_in 4",
|
||||||
|
"pinch_out 3",
|
||||||
|
"pinch_out 4"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture__ */
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/* WARNING: experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "xdo_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class pinch_gesture : protected xdo_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
pinch_gesture(
|
||||||
|
const float threshold,
|
||||||
|
const char* pinch_in3,
|
||||||
|
const char* pinch_in4,
|
||||||
|
const char* pinch_out3,
|
||||||
|
const char* pinch_out4
|
||||||
|
);
|
||||||
|
|
||||||
|
~pinch_gesture();
|
||||||
|
int fingers;
|
||||||
|
float radius;
|
||||||
|
|
||||||
|
inline void begin() override;
|
||||||
|
inline void update() override;
|
||||||
|
inline void end() override;
|
||||||
|
inline bool parse_line(const char *) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// current location
|
||||||
|
float previous_radius;
|
||||||
|
float threshold;
|
||||||
|
int previous_gesture;
|
||||||
|
bool flag_pinching;
|
||||||
|
const char ** commands;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// static constants
|
||||||
|
static const int MSK_THREE_FINGERS;
|
||||||
|
static const int MSK_FOUR_FINGERS;
|
||||||
|
static const int MSK_NEGATIVE;
|
||||||
|
static const int MSK_POSITIVE;
|
||||||
|
static const int FRESH;
|
||||||
|
static const char * const command_map[4];
|
||||||
|
// regex patterns
|
||||||
|
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_END_REGEX_PATTERN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__ */
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/* WARNING: pinch gestures are experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "pinch_gesture.h"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for start of pinch.
|
||||||
|
* Extracts one match for the number of fingers used during the pionch.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_PINCH_BEGIN +34.33s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_BEGIN_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_BEGIN" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for the end of swipe.
|
||||||
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_PINCH_END +35.03s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_END_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_END" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// matches signed decimal numbers (eg. "6.02" "-1.1")
|
||||||
|
#define CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
||||||
|
|
||||||
|
// matches a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
||||||
|
#define CF_NUMBER_DIVISION "\\s*" CF_NUMBER_REGEX "/\\s*" CF_NUMBER_REGEX
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for during a pinch.
|
||||||
|
* Extracts number of fingers used and the speed (normal and accelerated) of the pinch.
|
||||||
|
* Extracts radius and rotational velocity of the pinch motion as well.
|
||||||
|
*
|
||||||
|
* eg. event8 GESTURE_PINCH_UPDATE +128.15s 3 -1.64/ 2.08 (-4.43/ 5.62 unaccelerated) 1.40 @ -0.14
|
||||||
|
* ^ ^ ^ ^ ^ ^ ^
|
||||||
|
* fingers dx dy udx udy radius omega
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_UPDATE_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_UPDATE" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
||||||
|
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
||||||
|
"\\s+(" CF_NUMBER_REGEX ")" // radius
|
||||||
|
" @\\s+" CF_NUMBER_REGEX "" // angular velocity (omega)
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// delete macros
|
||||||
|
#undef CF_NUMBER_DIVISION
|
||||||
|
#undef CF_NUMBER_EXTRACT
|
||||||
|
#undef CF_NUMBER_REGEX
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__ */
|
||||||
@@ -20,7 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream> // std::cout, std::endl
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <regex> // std::regex, std::regex_match
|
||||||
|
#include <string> // std::stof, std::stoi
|
||||||
#include "xdo_gesture.h"
|
#include "xdo_gesture.h"
|
||||||
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
@@ -65,7 +68,7 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on begin of swipe gesture.
|
* Hook on begin of swipe gesture.
|
||||||
*/
|
*/
|
||||||
void swipe_gesture::begin()
|
inline void swipe_gesture::begin()
|
||||||
{
|
{
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
||||||
this->previous_gesture = swipe_gesture::FRESH;
|
this->previous_gesture = swipe_gesture::FRESH;
|
||||||
@@ -76,7 +79,7 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on update of swipe gesture.
|
* Hook on update of swipe gesture.
|
||||||
*/
|
*/
|
||||||
void swipe_gesture::update()
|
inline void swipe_gesture::update()
|
||||||
{
|
{
|
||||||
this->x += this->dx;
|
this->x += this->dx;
|
||||||
this->y += this->dy;
|
this->y += this->dy;
|
||||||
@@ -124,9 +127,67 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on end of swipe gesture.
|
* Hook on end of swipe gesture.
|
||||||
*/
|
*/
|
||||||
void swipe_gesture::end()
|
inline void swipe_gesture::end()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an output line and dispatches swipe begin/update/end upon match.
|
||||||
|
* Uses GESTURE_BEGIN_REGEX_PATTERN for begin,
|
||||||
|
* GESTURE_UPDATE_REGEX_PATTERN for update,
|
||||||
|
* GESTURE_END_REGEX_PATTERN for end.
|
||||||
|
*
|
||||||
|
* @param line the output line from libinput debug-events
|
||||||
|
* @return true if line matches this gesture
|
||||||
|
*/
|
||||||
|
inline bool swipe_gesture::parse_line(const char * line)
|
||||||
|
{
|
||||||
|
// pre-compile regex patterns
|
||||||
|
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);
|
||||||
|
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 /* if (!this->flag_swiping) */
|
||||||
|
{
|
||||||
|
// 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 */
|
/* STATICS DEFINITIONS */
|
||||||
const int swipe_gesture::MSK_THREE_FINGERS = 0;
|
const int swipe_gesture::MSK_THREE_FINGERS = 0;
|
||||||
const int swipe_gesture::MSK_FOUR_FINGERS = 1;
|
const int swipe_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
@@ -49,10 +49,11 @@ namespace comfortable_swipe::gesture
|
|||||||
int fingers;
|
int fingers;
|
||||||
float dx, dy, udx, udy;
|
float dx, dy, udx, udy;
|
||||||
|
|
||||||
void begin() override;
|
inline void begin() override;
|
||||||
void update() override;
|
inline void update() override;
|
||||||
void end() override;
|
inline void end() override;
|
||||||
|
inline bool parse_line(const char *) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// location of mouse
|
// location of mouse
|
||||||
int screen_num, ix, iy;
|
int screen_num, ix, iy;
|
||||||
@@ -62,6 +63,9 @@ namespace comfortable_swipe::gesture
|
|||||||
int previous_gesture;
|
int previous_gesture;
|
||||||
const char ** commands;
|
const char ** commands;
|
||||||
|
|
||||||
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
|
bool flag_swiping;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// static constants
|
// static constants
|
||||||
static const int MSK_THREE_FINGERS;
|
static const int MSK_THREE_FINGERS;
|
||||||
@@ -19,12 +19,14 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
namespace comfortable_swipe::gesture
|
namespace comfortable_swipe::gesture
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Regex pattern for the libinput entry for start of swipe.
|
* Regex pattern for the libinput entry for start of swipe.
|
||||||
* Extracts one match for the number of fingers used during the swipe.
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
*
|
*
|
||||||
* eg. event15 GESTURE_SWIPE_BEGIN +34.33s 3
|
* eg. event15 GESTURE_SWIPE_BEGIN +34.33s 3
|
||||||
* ^
|
* ^
|
||||||
* fingers
|
* fingers
|
||||||
@@ -41,7 +43,7 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Regex pattern for the libinput entry for the end of swipe.
|
* Regex pattern for the libinput entry for the end of swipe.
|
||||||
* Extracts one match for the number of fingers used during the swipe.
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
*
|
*
|
||||||
* eg. event15 GESTURE_SWIPE_END +35.03s 3
|
* eg. event15 GESTURE_SWIPE_END +35.03s 3
|
||||||
* ^
|
* ^
|
||||||
* fingers
|
* fingers
|
||||||
@@ -64,7 +66,7 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Regex pattern for the libinput entry for during a swipe.
|
* Regex pattern for the libinput entry for during a swipe.
|
||||||
* Extracts number of fingers used and the speed (normal and accelerated) of the swipe.
|
* Extracts number of fingers used and the speed (normal and accelerated) of the swipe.
|
||||||
*
|
*
|
||||||
* eg. event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)
|
* eg. event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)
|
||||||
* ^ ^ ^ ^ ^
|
* ^ ^ ^ ^ ^
|
||||||
* fingers dx dy udx udy
|
* fingers dx dy udx udy
|
||||||
File renamed without changes.
@@ -42,9 +42,10 @@ namespace comfortable_swipe
|
|||||||
~xdo_gesture();
|
~xdo_gesture();
|
||||||
|
|
||||||
// hooks
|
// hooks
|
||||||
virtual void begin() = 0;
|
virtual inline void begin() = 0;
|
||||||
virtual void update() = 0;
|
virtual inline void update() = 0;
|
||||||
virtual void end() = 0;
|
virtual inline void end() = 0;
|
||||||
|
virtual inline bool parse_line(const char *) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
#include "gesture/xdo_gesture.h"
|
#include "gesture/xdo_gesture.h"
|
||||||
#include "gesture/swipe_gesture.h"
|
#include "gesture/swipe_gesture.h"
|
||||||
|
#include "gesture/pinch_gesture.h"
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
namespace comfortable_swipe
|
namespace comfortable_swipe
|
||||||
@@ -50,6 +51,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
void autostart();
|
void autostart();
|
||||||
void buffer();
|
void buffer();
|
||||||
|
void debug();
|
||||||
void help();
|
void help();
|
||||||
void restart();
|
void restart();
|
||||||
void start();
|
void start();
|
||||||
File renamed without changes.
@@ -0,0 +1,70 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_buffer__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <cstdio> // std::fgets_unlocked, stdin
|
||||||
|
#include "../index.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
*/
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
void buffer()
|
||||||
|
{
|
||||||
|
// read config file
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// initialize swipe gesture handler
|
||||||
|
comfortable_swipe::gesture::swipe_gesture swipe_gesture_handler
|
||||||
|
(
|
||||||
|
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
||||||
|
config["left3"].c_str(),
|
||||||
|
config["left4"].c_str(),
|
||||||
|
config["right3"].c_str(),
|
||||||
|
config["right4"].c_str(),
|
||||||
|
config["up3"].c_str(),
|
||||||
|
config["up4"].c_str(),
|
||||||
|
config["down3"].c_str(),
|
||||||
|
config["down4"].c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
comfortable_swipe::gesture::pinch_gesture pinch_gesture_handler
|
||||||
|
(
|
||||||
|
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
||||||
|
config["pinch_in3"].c_str(),
|
||||||
|
config["pinch_in4"].c_str(),
|
||||||
|
config["pinch_out3"].c_str(),
|
||||||
|
config["pinch_out4"].c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
// prepare data containers
|
||||||
|
std::array<char, 256> line;
|
||||||
|
|
||||||
|
// start reading lines from input one by one
|
||||||
|
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
||||||
|
{
|
||||||
|
swipe_gesture_handler.parse_line(line.data()) ||
|
||||||
|
pinch_gesture_handler.parse_line(line.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
||||||
@@ -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()
|
void help()
|
||||||
{
|
{
|
||||||
using comfortable_swipe::util::conf_filename;
|
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("");
|
||||||
std::puts("start - starts 3/4-finger gesture service");
|
std::puts("start - starts 3/4-finger gesture service");
|
||||||
std::puts("stop - stops 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("autostart - automatically run on startup (toggleable)");
|
||||||
std::puts("buffer - parses output of libinput debug-events");
|
std::puts("buffer - parses output of libinput debug-events");
|
||||||
std::puts("help - shows the help dialog");
|
std::puts("help - shows the help dialog");
|
||||||
|
std::puts("debug - logs raw output from input events taken from libinput");
|
||||||
std::puts("");
|
std::puts("");
|
||||||
std::printf("Configuration file can be found in %s\n", conf_filename());
|
std::printf("Configuration file can be found in %s\n", conf_filename());
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,2 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
g++ $(dirname $0)/main.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_buffer__
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 <string> // std::stoi, std::stof
|
|
||||||
#include <cstdio> // std::fgets_unlocked, stdin
|
|
||||||
#include <regex> // std::regex, std::regex_match, std::cmatch
|
|
||||||
#include "../index.hpp"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
|
||||||
*/
|
|
||||||
namespace comfortable_swipe::service
|
|
||||||
{
|
|
||||||
void buffer()
|
|
||||||
{
|
|
||||||
// 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
|
|
||||||
(
|
|
||||||
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
|
||||||
config["left3"].c_str(),
|
|
||||||
config["left4"].c_str(),
|
|
||||||
config["right3"].c_str(),
|
|
||||||
config["right4"].c_str(),
|
|
||||||
config["up3"].c_str(),
|
|
||||||
config["up4"].c_str(),
|
|
||||||
config["down3"].c_str(),
|
|
||||||
config["down4"].c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
|
||||||
+1
-1
@@ -3,4 +3,4 @@
|
|||||||
DIR=$(dirname $0)
|
DIR=$(dirname $0)
|
||||||
g++ -std=c++11 -O2 $DIR/test_regex.cpp -lxdo -o test.out || exec "Test aborted"
|
g++ -std=c++11 -O2 $DIR/test_regex.cpp -lxdo -o test.out || exec "Test aborted"
|
||||||
./test.out || rm test.out
|
./test.out || rm test.out
|
||||||
rm test.out
|
rm test.out
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../src/lib/gesture/swipe_gesture.h"
|
#include "../lib/gesture/swipe_gesture.h"
|
||||||
#include "../src/lib/gesture/swipe_gesture.regex.cpp"
|
#include "../lib/gesture/swipe_gesture.regex.cpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
|
|||||||
Reference in new issue
Block a user