Compare commits
40
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd4aa0a49d | ||
|
|
43fe2bb9b3 | ||
|
|
dda91b7178 | ||
|
|
4852993663 | ||
|
|
810a20f1ed | ||
|
|
28f5ca2a91 | ||
|
|
89b79bc9bc | ||
|
|
7d76db6693 | ||
|
|
204a422f2d | ||
|
|
c18cb04230 | ||
|
|
b1f8a7cb0a | ||
|
|
1c9b497b56 | ||
|
|
16742495eb | ||
|
|
459fd68ba8 | ||
|
|
7923effa02 | ||
|
|
602b148fb4 | ||
|
|
68bea125e3 | ||
|
|
0b3b3238af | ||
|
|
3a0e1361c9 | ||
|
|
b5c701994b | ||
|
|
30e4a57b62 | ||
|
|
f3909f85f2 | ||
|
|
1071979b83 | ||
|
|
f40145b6fa | ||
|
|
b171fb2cdf | ||
|
|
e2e534ea2f | ||
|
|
e3453c1bbb | ||
|
|
328ae08ee1 | ||
|
|
2843b9d3ce | ||
|
|
4795a68600 | ||
|
|
8d4756f7d2 | ||
|
|
22b9869ae8 | ||
|
|
0de8777d87 | ||
|
|
91b55bad5e | ||
|
|
90246cd7d3 | ||
|
|
a394e905ba | ||
|
|
3447946b1e | ||
|
|
823ea396a1 | ||
|
|
1321443898 | ||
|
|
6890ec4696 |
No files matched your search
+6
-1
@@ -1 +1,6 @@
|
|||||||
.log
|
# C++ generated headers
|
||||||
|
*.gch
|
||||||
|
|
||||||
|
# IDE-specific
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
@@ -1,21 +1,22 @@
|
|||||||
# Comfortable Swipe (Ubuntu)
|
# Comfortable Swipe (Ubuntu)
|
||||||
|
[](https://github.com/Hikari9/comfortable-swipe/releases)
|
||||||
[](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 `libinput-tools` and `libxdo-dev`
|
1. Install git, libinput, and g++
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt-get install libinput-tools libxdo-dev
|
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.git --depth 1
|
||||||
cd comfortable-swipe-ubuntu
|
cd comfortable-swipe
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Install
|
3. Install
|
||||||
@@ -24,62 +25,120 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
bash install
|
bash install
|
||||||
```
|
```
|
||||||
|
|
||||||
4. You may delete the downloaded `comfortable-swipe-ubuntu` folder after installation.
|
4. You may delete the downloaded `comfortable-swipe` folder after installation.
|
||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
Comfortable swipe should already be running as a service upon installation. Some notes:
|
1. You'll need some group permissions to read touchpad input data. Run
|
||||||
|
```bash
|
||||||
- The program makes use of **keyboard gestures** for swiping (e.g. `ctrl+alt+Right`)
|
sudo gpasswd -a $USER $(ls -l /dev/input/event* | awk '{print $4}' | head --line=1)
|
||||||
- By default, comfortable swipe uses Ubuntu workspace shortcuts (see [configurations](#configurations)).
|
```
|
||||||
|
2. ***Important***: After inputing your `sudo` password, log out then log back in
|
||||||
Useful References:
|
3. Run
|
||||||
|
```
|
||||||
- [Xdotool keycodes](https://www.linux.org/threads/xdotool-keyboard.10528/)
|
comfortable-swipe start
|
||||||
- [How to turn on Workspaces?](https://askubuntu.com/questions/260510/how-do-i-turn-on-workspaces-why-do-i-only-have-one-workspace)
|
```
|
||||||
- [How to set keyboard shortcuts in Ubuntu](https://help.ubuntu.com/stable/ubuntu-help/keyboard-shortcuts-set.html)
|
4. _Optional_: Automatically run on startup
|
||||||
|
```
|
||||||
### Other Commands
|
comfortable-swipe autostart
|
||||||
|
```
|
||||||
You can run `comfortable-swipe help` to see a list of commands:
|
5. Check the status of your application by running
|
||||||
|
```
|
||||||
|
comfortable-swipe status
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configurations
|
||||||
|
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
|
||||||
```
|
```
|
||||||
$ comfortable-swipe help
|
gedit $(comfortable-swipe config)
|
||||||
|
|
||||||
comfortable-swipe [start|stop|status|restart|buffer|help]
|
|
||||||
|
|
||||||
start - starts 3/4-finger gesture service
|
|
||||||
stop - stops 3/4-finger gesture service
|
|
||||||
status - shows the status of the program (service log)
|
|
||||||
restart - stops then starts 3/4-finger gesture service
|
|
||||||
buffer - parses output of libinput-debug-events
|
|
||||||
help - shows the help dialog
|
|
||||||
|
|
||||||
Configuration file can be found in /usr/local/share/comfortable-swipe.conf
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Configurations
|
Make sure to run after making changes:
|
||||||
The configuration file is located at `/usr/local/share/comfortable-swipe.conf`.
|
```
|
||||||
Run `comfortable-swipe restart` after making changes.
|
comfortable-swipe restart
|
||||||
|
```
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
Property | Description | Default Value | Default Behavior
|
||||||
--------- | ----------- | -------------- | -----
|
--------- | ----------- | -------------- | -----
|
||||||
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point | 0.0
|
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point (Note: Sky is the limit! Can be as large as 1000.0) | 0.0
|
||||||
left3 | 3-finger swipe left | ctrl+shift+Right | switch to right workspace
|
left3 | 3-finger swipe left | ctrl+alt+Right | switch to right workspace
|
||||||
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
||||||
right3 | 3-finger swipe right | ctrl+shift+Left | switch to left workspace
|
right3 | 3-finger swipe right | ctrl+alt+Left | switch to left workspace
|
||||||
right4 | 4-finger swipe right | ctrl+alt+shift+Left | move window to left workspace
|
right4 | 4-finger swipe right | ctrl+alt+shift+Left | move window to left workspace
|
||||||
up3 | 3-finger swipe up | ctrl+shift+Down | switch to bottom workspace
|
up3 | 3-finger swipe up | ctrl+alt+Down | switch to bottom workspace
|
||||||
up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace
|
up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace
|
||||||
down3 | 3-finger swipe down | ctrl+shift+Down | switch to above workspace
|
down3 | 3-finger swipe down | ctrl+alt+Down | switch to above workspace
|
||||||
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
||||||
|
|
||||||
|
Taken from `man xdotool`:
|
||||||
|
|
||||||
|
> Type a given keystroke. Examples being "alt+r", "Control_L+J",
|
||||||
|
> "ctrl+alt+n", "BackSpace".
|
||||||
|
>
|
||||||
|
> Generally, any valid X Keysym string will work. Multiple keys are
|
||||||
|
> separated by '+'. Aliases exist for "alt", "ctrl", "shift",
|
||||||
|
> "super", and "meta" which all map to Foo_L, such as Alt_L and
|
||||||
|
> Control_L, etc.
|
||||||
|
>
|
||||||
|
> In cases where your keyboard doesn't actually have the key you want
|
||||||
|
> to type, xdotool will automatically find an unused keycode and use
|
||||||
|
> that to type the key.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe debug
|
||||||
|
```
|
||||||
|
|
||||||
|
This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput.
|
||||||
|
|
||||||
|
A working swipe gesture will show the following:
|
||||||
|
|
||||||
|
```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
|
||||||
Clone the repository 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. Please make sure
|
Search in [Issues](https://github.com/Hikari9/comfortable-swipe/issues?utf8=%E2%9C%93&q=is%3Aissue) if the problem has already been solved.
|
||||||
to add the following to your issue:
|
|
||||||
|
|
||||||
1. Content of `.log` (found in the cloned folder)
|
Otherwise, [create a new issue](https://github.com/Hikari9/comfortable-swipe/issues/new) to report your bug.
|
||||||
2. Output of `comfortable-swipe status`
|
|
||||||
|
Please include the output of the following:
|
||||||
|
|
||||||
|
1. `lsb_release -a`
|
||||||
|
2. `g++ --version`
|
||||||
|
3. `ls -l /dev/input/event*`
|
||||||
|
3. `xinput list | grep touchpad -i`
|
||||||
|
4. `lsmod | grep hid`
|
||||||
|
5. `comfortable-swipe status`
|
||||||
|
6. `comfortable-swipe start` (if you can run it)
|
||||||
|
7. `comfortable-swipe debug` (try swiping if you can see `GESTURE_SWIPE_XXX`)
|
||||||
|
8. `cat $(comfortable-swipe config)`
|
||||||
Executable
+7
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
dir="$(dirname $0)"
|
||||||
|
g++ "$dir/comfortable-swipe.cpp" \
|
||||||
|
-o "$1" \
|
||||||
|
-std=c++11 \
|
||||||
|
-O2 -lxdo -Wno-unused-result \
|
||||||
|
-DCOMFORTABLE_SWIPE_VERSION="\"$(cat $dir/VERSION | tr -d '[:space:]')\""
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
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 <ios> // std::ios
|
||||||
|
#include <iostream> // std::cin, std::cout, std::cerr
|
||||||
|
#include <string> // std::string
|
||||||
|
#include "lib/comfortable_swipe"
|
||||||
|
|
||||||
|
/* MAIN DRIVER FUNCTION */
|
||||||
|
|
||||||
|
int main(int argc, char** args)
|
||||||
|
{
|
||||||
|
// improve buffering by decoupling loggers from stdio
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(0);
|
||||||
|
std::cout.tie(0);
|
||||||
|
std::cerr.tie(0);
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
std::string arg = args[1];
|
||||||
|
|
||||||
|
// select based on argument
|
||||||
|
if (arg == "start")
|
||||||
|
comfortable_swipe::service::start();
|
||||||
|
|
||||||
|
else if (arg == "stop")
|
||||||
|
comfortable_swipe::service::stop();
|
||||||
|
|
||||||
|
else if (arg == "restart")
|
||||||
|
comfortable_swipe::service::restart();
|
||||||
|
|
||||||
|
else if (arg == "buffer")
|
||||||
|
comfortable_swipe::service::buffer();
|
||||||
|
|
||||||
|
else if (arg == "autostart")
|
||||||
|
comfortable_swipe::service::autostart();
|
||||||
|
|
||||||
|
else if (arg == "config")
|
||||||
|
comfortable_swipe::service::config();
|
||||||
|
|
||||||
|
else if (arg == "debug")
|
||||||
|
comfortable_swipe::service::debug();
|
||||||
|
|
||||||
|
else if (arg == "status")
|
||||||
|
comfortable_swipe::service::status();
|
||||||
|
|
||||||
|
else /* if (arg == "help") */
|
||||||
|
comfortable_swipe::service::help();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
comfortable_swipe::service::help();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -13,6 +13,9 @@
|
|||||||
# Threshold
|
# Threshold
|
||||||
# Tweak this value depending on the sensitivity of your mousepad to perform
|
# Tweak this value depending on the sensitivity of your mousepad to perform
|
||||||
# gestures. A higher value means less sensitive.
|
# gestures. A higher value means less sensitive.
|
||||||
|
#
|
||||||
|
# (Note: Sky is the limit! Can be as large as 1000.0)
|
||||||
|
#
|
||||||
# Default: threshold = 0.0
|
# Default: threshold = 0.0
|
||||||
threshold = 0.0
|
threshold = 0.0
|
||||||
|
|
||||||
@@ -1,90 +1,93 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# prefer running as root
|
|
||||||
if [ $(id -u) != "0" ]; then
|
|
||||||
sudo bash "$0" "$@"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "
|
function install {
|
||||||
Install $(date)" >> .log
|
# prefer running as root
|
||||||
|
local dir="$(dirname $0)"
|
||||||
|
local program=comfortable-swipe
|
||||||
|
local program_exe=/usr/local/bin/$program
|
||||||
|
local compile_command="$dir/$program.compile.sh"
|
||||||
|
local conf_path=/usr/local/share/$program/$program.conf
|
||||||
|
local dconf_path="$dir/defaults.conf"
|
||||||
|
local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf"
|
||||||
|
|
||||||
DIR=$(dirname $0)
|
if [ -x "$(command -v $program_exe)" ]; then
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
# stop any running $program if it exists
|
||||||
CONF_PATH=/usr/local/share/comfortable-swipe.conf
|
$program_exe stop
|
||||||
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
|
||||||
DCONF_PATH=$DIR/src/defaults.conf
|
|
||||||
|
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
|
||||||
# stop any running comfortable-swipe if it exists
|
|
||||||
systemctl stop comfortable-swipe.service >> .log 2>> .log
|
|
||||||
systemctl disable comfortable-swipe.service >> .log 2>> .log
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p $(dirname $CONF_PATH)
|
|
||||||
|
|
||||||
# copy config file
|
|
||||||
if [ ! -f $CONF_PATH ]; then
|
|
||||||
if [ ! -f $OLD_CONF_PATH ]; then
|
|
||||||
# old config file not found, create from scratch
|
|
||||||
cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
|
||||||
else
|
|
||||||
# old config file found, move to the new path
|
|
||||||
echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH"
|
|
||||||
cp -a $OLD_CONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# config file found, ask user if overwrite
|
#copy config file
|
||||||
echo "Old conf file found in $CONF_PATH"
|
abort () {
|
||||||
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
exec echo "Installation aborted"
|
||||||
response=${response,,} # tolower
|
}
|
||||||
if [[ "$response" =~ ^(no|n)$ ]]; then
|
sudo mkdir -p "$(dirname $conf_path)" || abort
|
||||||
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
|
||||||
response=${response,,}
|
# check if "-y" or "--yes" is passed as an argument
|
||||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
YES=false
|
||||||
cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
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
|
||||||
|
# old config file not found, create from scratch
|
||||||
|
cat "$dconf_path" > "$conf_path" || abort
|
||||||
else
|
else
|
||||||
echo "Installation aborted." >> .log
|
# old config file found, move to the new path
|
||||||
exec echo "Installation aborted."
|
cat "$old_conf_path" > "$conf_path" || abort
|
||||||
|
echo "Configuration copied from $old_conf_path to $conf_path"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# config file found, ask user if overwrite
|
||||||
|
echo "Old conf file found in $conf_path"
|
||||||
|
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
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# install with g++
|
echo "Installing to $program_exe ..."
|
||||||
echo "Installing..."
|
|
||||||
echo "
|
|
||||||
Install $(date)" >> .log
|
|
||||||
echo "Running g++" >> .log
|
|
||||||
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM >> .log 2>> .log || exec echo "Installation aborted"
|
|
||||||
|
|
||||||
# add as service
|
# remove existing $program
|
||||||
SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service"
|
if [ -x "$(command -v $program_exe)" ]; then
|
||||||
|
sudo rm -f "$(which $program)"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "[Unit]
|
# compile library
|
||||||
Description=Comfortable 3 or 4 finger gestures
|
sudo "$compile_command" "$program_exe" || abort
|
||||||
After=display-manager.service keyboard-setup.service
|
|
||||||
|
|
||||||
[Service]
|
# add permissions to input group (defer)
|
||||||
Environment=DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY
|
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
||||||
ExecStart=$PROGRAM exec
|
|
||||||
Restart=always
|
|
||||||
RestartSec=2
|
|
||||||
|
|
||||||
[Install]
|
# turn on autostart by default
|
||||||
WantedBy=graphical.target" \
|
local autostart_status="$($program_exe autostart)"
|
||||||
> $SERVICE_PATH
|
if [[ "$autostart_status" == *off* ]]; then
|
||||||
|
autostart_status="$($program_exe autostart)"
|
||||||
|
fi
|
||||||
|
|
||||||
# run immediately
|
echo "Successfully installed $program $(cat $dir/VERSION | tr -d '[:space:]')"
|
||||||
systemctl daemon-reload >> .log 2>> .log
|
echo ""
|
||||||
systemctl enable comfortable-swipe.service >> .log 2>> .log
|
echo "$autostart_status"
|
||||||
systemctl start comfortable-swipe.service >> .log 2>> .log
|
echo "Edit configuration file: gedit \$($program config)"
|
||||||
sleep 1
|
echo ""
|
||||||
echo "Installation successful" >> .log
|
echo "Try running: $program start"
|
||||||
|
}
|
||||||
|
|
||||||
# prvide success message
|
install
|
||||||
echo ""
|
unset -f install
|
||||||
echo "Successfully installed comfortable-swipe. Try swiping and see if it works."
|
|
||||||
echo "Configuration file is located at $CONF_PATH"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "[Report bugs to https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new]"
|
|
||||||
echo ""
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__
|
||||||
|
#define __COMFORTABLE_SWIPE__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "index.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure to include all implementation (.cpp) files below to be ready for export.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "gesture/xdo_gesture.cpp"
|
||||||
|
#include "gesture/swipe_gesture.cpp"
|
||||||
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
|
#include "service/autostart.cpp"
|
||||||
|
#include "service/buffer.cpp"
|
||||||
|
#include "service/config.cpp"
|
||||||
|
#include "service/debug.cpp"
|
||||||
|
#include "service/help.cpp"
|
||||||
|
#include "service/restart.cpp"
|
||||||
|
#include "service/start.cpp"
|
||||||
|
#include "service/status.cpp"
|
||||||
|
#include "service/stop.cpp"
|
||||||
|
#include "util/autostart_filename.cpp"
|
||||||
|
#include "util/conf_filename.cpp"
|
||||||
|
#include "util/read_config_file.cpp"
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__ */
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_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 <string> // std::stoi, std::stof
|
||||||
|
#include <regex> // std::regex, std::regex_match, std::cmatch
|
||||||
|
#include "swipe_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 swipe gesture, given configurations for certain swipe events.
|
||||||
|
*/
|
||||||
|
swipe_gesture::swipe_gesture
|
||||||
|
(
|
||||||
|
const float threshold,
|
||||||
|
const char* left3 /* 000 */,
|
||||||
|
const char* left4 /* 001 */,
|
||||||
|
const char* right3 /* 010 */,
|
||||||
|
const char* right4 /* 011 */,
|
||||||
|
const char* up3 /* 100 */,
|
||||||
|
const char* up4 /* 101 */,
|
||||||
|
const char* down3 /* 110 */,
|
||||||
|
const char* down4 /* 111 */
|
||||||
|
):
|
||||||
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
|
threshold_squared(threshold*threshold),
|
||||||
|
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}),
|
||||||
|
flag_swiping(false)
|
||||||
|
{
|
||||||
|
// 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.
|
||||||
|
*/
|
||||||
|
swipe_gesture::~swipe_gesture()
|
||||||
|
{
|
||||||
|
delete[] commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture.
|
||||||
|
*/
|
||||||
|
void swipe_gesture::begin()
|
||||||
|
{
|
||||||
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
||||||
|
this->previous_gesture = swipe_gesture::FRESH;
|
||||||
|
this->x = 0;
|
||||||
|
this->y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
void swipe_gesture::update()
|
||||||
|
{
|
||||||
|
this->x += this->dx;
|
||||||
|
this->y += this->dy;
|
||||||
|
// scale threshold to 1/10 when gesture is not fresh
|
||||||
|
float scale = this->previous_gesture == swipe_gesture::FRESH
|
||||||
|
? 1.00f
|
||||||
|
: 0.01f; // square root of 1/10
|
||||||
|
static const float EPSILON = 1e-6f;
|
||||||
|
if (this->x * this->x + this->y * this->y
|
||||||
|
> this->threshold_squared * scale + EPSILON)
|
||||||
|
{
|
||||||
|
int mask = 0;
|
||||||
|
if (this->fingers == 3) mask |= swipe_gesture::MSK_THREE_FINGERS;
|
||||||
|
else if (this->fingers == 4) mask |= swipe_gesture::MSK_FOUR_FINGERS;
|
||||||
|
|
||||||
|
const float absx = x >= 0 ? x : -x;
|
||||||
|
const float absy = y >= 0 ? y : -y;
|
||||||
|
if (absx > absy)
|
||||||
|
{ // horizontal
|
||||||
|
mask |= swipe_gesture::MSK_HORIZONTAL;
|
||||||
|
if (x < 0)
|
||||||
|
mask |= swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= swipe_gesture::MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
else /* std::abs(x) <= std::abs(y) */
|
||||||
|
{ // vertical
|
||||||
|
mask |= swipe_gesture::MSK_VERTICAL;
|
||||||
|
if (y < 0)
|
||||||
|
mask |= swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= swipe_gesture::MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if (this->previous_gesture == swipe_gesture::FRESH
|
||||||
|
|| this->previous_gesture == (mask ^ swipe_gesture::MSK_POSITIVE))
|
||||||
|
{
|
||||||
|
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, swipe_gesture::commands[mask], 0);
|
||||||
|
this->x = this->y = 0;
|
||||||
|
this->previous_gesture = mask;
|
||||||
|
std::cout << "SWIPE " << swipe_gesture::command_map[mask] << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of 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
|
||||||
|
|| std::regex_match(line, matches, gesture_swipe_update) != 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;
|
||||||
|
const int swipe_gesture::MSK_NEGATIVE = 0;
|
||||||
|
const int swipe_gesture::MSK_POSITIVE = 2;
|
||||||
|
const int swipe_gesture::MSK_HORIZONTAL = 0;
|
||||||
|
const int swipe_gesture::MSK_VERTICAL = 4;
|
||||||
|
const int swipe_gesture::FRESH = -1;
|
||||||
|
const char * const swipe_gesture::command_map[8] = {
|
||||||
|
"left3",
|
||||||
|
"left4",
|
||||||
|
"right3",
|
||||||
|
"right4",
|
||||||
|
"up3",
|
||||||
|
"up4",
|
||||||
|
"down3",
|
||||||
|
"down4"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_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 swipe_gesture : protected xdo_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
swipe_gesture(
|
||||||
|
const float threshold,
|
||||||
|
const char* left3 /* 000 */,
|
||||||
|
const char* left4 /* 001 */,
|
||||||
|
const char* right3 /* 010 */,
|
||||||
|
const char* right4 /* 011 */,
|
||||||
|
const char* up3 /* 100 */,
|
||||||
|
const char* up4 /* 101 */,
|
||||||
|
const char* down3 /* 110 */,
|
||||||
|
const char* down4 /* 111 */
|
||||||
|
);
|
||||||
|
|
||||||
|
~swipe_gesture();
|
||||||
|
|
||||||
|
// fields for xdo
|
||||||
|
int fingers;
|
||||||
|
float dx, dy, udx, udy;
|
||||||
|
|
||||||
|
void begin() override;
|
||||||
|
void update() override;
|
||||||
|
void end() override;
|
||||||
|
bool parse_line(const char *) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// location of mouse
|
||||||
|
int screen_num, ix, iy;
|
||||||
|
|
||||||
|
// current location
|
||||||
|
float x, y, threshold_squared;
|
||||||
|
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;
|
||||||
|
static const int MSK_FOUR_FINGERS;
|
||||||
|
static const int MSK_NEGATIVE;
|
||||||
|
static const int MSK_POSITIVE;
|
||||||
|
static const int MSK_HORIZONTAL;
|
||||||
|
static const int MSK_VERTICAL;
|
||||||
|
static const int FRESH;
|
||||||
|
static const char * const command_map[8];
|
||||||
|
// 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_swipe_gesture_h__ */
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_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 "swipe_gesture.h"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for start of swipe.
|
||||||
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_SWIPE_BEGIN +34.33s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_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_SWIPE_END +35.03s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* swipe_gesture::GESTURE_END_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_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 and extracts 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 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)
|
||||||
|
* ^ ^ ^ ^ ^
|
||||||
|
* fingers dx dy udx udy
|
||||||
|
*/
|
||||||
|
const char* swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_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*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// delete macros
|
||||||
|
#undef CF_NUMBER_DIVISION
|
||||||
|
#undef CF_NUMBER_EXTRACT
|
||||||
|
#undef CF_NUMBER_REGEX
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ */
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__xdo_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__xdo_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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a new gesture handler with xdo.
|
||||||
|
*/
|
||||||
|
xdo_gesture::xdo_gesture():
|
||||||
|
xdo(xdo_new(NULL))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new swipe gesture with xdo.
|
||||||
|
*/
|
||||||
|
xdo_gesture::~xdo_gesture()
|
||||||
|
{
|
||||||
|
xdo_free(this->xdo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__xdo_gesture__ */
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__xdo_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__xdo_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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo_t
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe
|
||||||
|
{
|
||||||
|
namespace gesture
|
||||||
|
{
|
||||||
|
class xdo_gesture
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
xdo_t * xdo;
|
||||||
|
|
||||||
|
public:
|
||||||
|
xdo_gesture();
|
||||||
|
~xdo_gesture();
|
||||||
|
|
||||||
|
// hooks
|
||||||
|
virtual void begin() = 0;
|
||||||
|
virtual void update() = 0;
|
||||||
|
virtual void end() = 0;
|
||||||
|
virtual bool parse_line(const char *) = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__xdo_gesture_h__ */
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__index_hpp__
|
||||||
|
#define __COMFORTABLE_SWIPE__index_hpp__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// global defines
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__PROGRAM__
|
||||||
|
#define __COMFORTABLE_SWIPE__PROGRAM__ "/usr/local/bin/comfortable-swipe"
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__PROGRAM__ */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__CONFIG__
|
||||||
|
#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */
|
||||||
|
|
||||||
|
#ifndef COMFORTABLE_SWIPE_VERSION
|
||||||
|
#warning COMFORTABLE_SWIPE_VERSION is not defined
|
||||||
|
#define COMFORTABLE_SWIPE_VERSION "v(UNKNOWN)"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_VERSION */
|
||||||
|
|
||||||
|
#include <map> // std::map
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure to include your header files here so that they can be imported by other modules.
|
||||||
|
*/
|
||||||
|
#include "gesture/xdo_gesture.h"
|
||||||
|
#include "gesture/swipe_gesture.h"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
namespace comfortable_swipe
|
||||||
|
{
|
||||||
|
namespace util
|
||||||
|
{
|
||||||
|
const char* autostart_filename();
|
||||||
|
constexpr const char* conf_filename();
|
||||||
|
std::map<std::string, std::string> read_config_file(const char*);
|
||||||
|
}
|
||||||
|
namespace service
|
||||||
|
{
|
||||||
|
void autostart();
|
||||||
|
void buffer();
|
||||||
|
void config();
|
||||||
|
void debug();
|
||||||
|
void help();
|
||||||
|
void restart();
|
||||||
|
void start();
|
||||||
|
void status();
|
||||||
|
void stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__index_hpp__ */
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_autostart__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_autostart__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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::cerr, std::cout, std::endl
|
||||||
|
#include <fstream> // std::ifstream, std::ofstream
|
||||||
|
#include <string> // std::string
|
||||||
|
#include <cstdio> // std::remove
|
||||||
|
#include <cstdlib> // std::system
|
||||||
|
#include "../index.hpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Toggles automatic startup of comfortable swipe.
|
||||||
|
*/
|
||||||
|
void autostart()
|
||||||
|
{
|
||||||
|
using comfortable_swipe::util::autostart_filename;
|
||||||
|
|
||||||
|
const std::string& path = autostart_filename();
|
||||||
|
if (std::ifstream(path.data()).good())
|
||||||
|
{
|
||||||
|
// file found, delete it
|
||||||
|
if (std::remove(path.data()) != 0)
|
||||||
|
std::cerr << "Error: failed to switch off autostart. "
|
||||||
|
<< "Maybe the autostart file is in use?"
|
||||||
|
<< std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "Autostart switched off" << std::endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// file not found, create it
|
||||||
|
int result = std::system(("mkdir -p $(dirname " + path + ")").data());
|
||||||
|
std::ofstream fout(path.data());
|
||||||
|
if (result != 0 || !fout.good())
|
||||||
|
std::cerr << "Error: failed to switch on autostart. "
|
||||||
|
<< "Are you sure you have the permissions?"
|
||||||
|
<< std::endl;
|
||||||
|
else {
|
||||||
|
fout <<
|
||||||
|
"[Desktop Entry]\n"
|
||||||
|
"Type=Application\n"
|
||||||
|
"Exec=bash -c \""
|
||||||
|
__COMFORTABLE_SWIPE__PROGRAM__
|
||||||
|
" start\"\n"
|
||||||
|
"Hidden=false\n"
|
||||||
|
"NoDisplay=false\n"
|
||||||
|
"X-GNOME-Autostart-enabled=true\n"
|
||||||
|
"Name=Comfortable Swipe\n"
|
||||||
|
"Comment=3 or 4 touchpad gestures\n";
|
||||||
|
std::cout << "Autostart switched on" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_autostart__ */
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#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> // fgets_unlocked, stdin
|
||||||
|
#include <iostream> // std::ios, std::cout, std::cin
|
||||||
|
#include "../index.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
*/
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
void buffer()
|
||||||
|
{
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(0);
|
||||||
|
std::cout.tie(0);
|
||||||
|
std::cout.flush();
|
||||||
|
|
||||||
|
// 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()
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
// attempt to parse swipe gestures
|
||||||
|
swipe_gesture_handler.parse_line(line.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_config__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_config__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
#include <cstdio> // std::puts
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Prints where the config file of comfortable swipe is located.
|
||||||
|
*
|
||||||
|
* Usage: nano $(comfortable-swipe config)
|
||||||
|
*/
|
||||||
|
void config()
|
||||||
|
{
|
||||||
|
std::puts(comfortable_swipe::util::conf_filename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_config__ */
|
||||||
@@ -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("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep -v 'double tracking')\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_debug__ */
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_help__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_help__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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::puts, std::printf
|
||||||
|
#include "../index.hpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Shows the help window.
|
||||||
|
*/
|
||||||
|
void help()
|
||||||
|
{
|
||||||
|
using comfortable_swipe::util::conf_filename;
|
||||||
|
std::puts("comfortable-swipe " COMFORTABLE_SWIPE_VERSION " [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
||||||
|
std::puts("");
|
||||||
|
std::puts("start - starts 3/4-finger gesture service");
|
||||||
|
std::puts("stop - stops 3/4-finger gesture service");
|
||||||
|
std::puts("restart - stops then starts 3/4-finger gesture 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("config - locates the config file [/usr/share/comfortable-swipe/comfortable-swipe.conf]");
|
||||||
|
std::puts("debug - logs raw output from input events taken from libinput");
|
||||||
|
std::puts("status - checks status of program and autostart");
|
||||||
|
std::puts("");
|
||||||
|
std::printf("Configuration file can be found in %s\n", conf_filename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_help__ */
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_restart__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_restart__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Restarts the comfortable-swipe service.
|
||||||
|
*/
|
||||||
|
void restart()
|
||||||
|
{
|
||||||
|
comfortable_swipe::service::stop();
|
||||||
|
comfortable_swipe::service::start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_start__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_start__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
#include <cstdlib> // std::system
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
|
||||||
|
* for the technical implementation.
|
||||||
|
*/
|
||||||
|
void start()
|
||||||
|
{
|
||||||
|
(void) std::system(__COMFORTABLE_SWIPE__PROGRAM__ " debug | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_start__ */
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_status__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_status__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
|
#include <array> // std::array
|
||||||
|
#include <cstdlib> // std::atoi
|
||||||
|
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||||
|
#include <regex> // std::cmatch, std::regex, std::regex_match
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Prints the status of comfortable-swipe.
|
||||||
|
*/
|
||||||
|
void status()
|
||||||
|
{
|
||||||
|
// check if comfortable-swipe is running
|
||||||
|
bool running = false;
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
||||||
|
if (pipe && !std::feof(pipe.get()) && std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
|
||||||
|
{
|
||||||
|
int pid = std::atoi(buffer.data());
|
||||||
|
if (pid != getpid())
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if autostart is on
|
||||||
|
auto autostart_f = comfortable_swipe::util::autostart_filename();
|
||||||
|
bool autostart_on = access(autostart_f, F_OK) != -1;
|
||||||
|
|
||||||
|
std::puts(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// check status of configuration file
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// print threshold
|
||||||
|
if (config.count("threshold") > 0)
|
||||||
|
{
|
||||||
|
auto & threshold = config["threshold"];
|
||||||
|
|
||||||
|
// check if regex pattern matches threshold
|
||||||
|
std::cmatch matches;
|
||||||
|
bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
|
||||||
|
|
||||||
|
// print status of threshold
|
||||||
|
std::printf(" %9s is %s (%s)\n", "threshold", ok ? "OK" : "INVALID", threshold.data());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
std::printf(" %9s is OFF\n", "threshold");
|
||||||
|
|
||||||
|
// print swipe commands
|
||||||
|
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
|
||||||
|
{
|
||||||
|
if (config.count(command) > 0)
|
||||||
|
std::printf(" %9s is OK (%s)\n", command, config[command].data());
|
||||||
|
else
|
||||||
|
std::printf(" %9s is OFF\n", command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::runtime_error& e)
|
||||||
|
{
|
||||||
|
std::printf("config error: %s\n", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// print status
|
||||||
|
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
|
||||||
|
std::printf("comfortable-swipe program is %s\n", running ? "RUNNING" : "STOPPED");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_stop__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_stop__
|
||||||
|
|
||||||
|
#include <cstdio> // std::FILE, std::feof, std::fgets
|
||||||
|
#include <cstdlib> // std::atoi, std::system
|
||||||
|
#include <string> // std::string, std::to_string
|
||||||
|
/*
|
||||||
|
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 <stdexcept> // std::runtime_error
|
||||||
|
#include <unistd.h> // popen, pclose, getpid
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
|
#include <array> // std::array
|
||||||
|
#include <cstdlib> // std::atoi
|
||||||
|
#include <cstdio> // FILE, std::feof, std::fgets
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Stops all comfortable-swipe instances.
|
||||||
|
*/
|
||||||
|
void stop()
|
||||||
|
{
|
||||||
|
|
||||||
|
// read all service names from process (pgrep)
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
||||||
|
|
||||||
|
// make sure pipe exists
|
||||||
|
if (!pipe)
|
||||||
|
throw std::runtime_error("stop command failed");
|
||||||
|
|
||||||
|
// buffer what to kill
|
||||||
|
std::string kill = "kill";
|
||||||
|
|
||||||
|
// read until end of line
|
||||||
|
while (!std::feof(pipe.get()))
|
||||||
|
{
|
||||||
|
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
|
||||||
|
{
|
||||||
|
int pid = std::atoi(buffer.data());
|
||||||
|
if (pid != getpid())
|
||||||
|
{
|
||||||
|
kill += " ";
|
||||||
|
kill += std::to_string(pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run "kill {pid1} {pid2}..."
|
||||||
|
(void) std::system(kill.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_stop__ */
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__util_autostart_filename__
|
||||||
|
#define __COMFORTABLE_SWIPE__util_autostart_filename__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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::string
|
||||||
|
#include <unistd.h> // getenv
|
||||||
|
|
||||||
|
namespace comfortable_swipe::util
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The path where the autostart configuration is located.
|
||||||
|
*/
|
||||||
|
const char* autostart_filename()
|
||||||
|
{
|
||||||
|
static std::string filename;
|
||||||
|
if (filename.empty()) {
|
||||||
|
const char* xdg_config = getenv("XDG_CONFIG_HOME");
|
||||||
|
std::string config(
|
||||||
|
xdg_config == NULL
|
||||||
|
? std::string(getenv("HOME")) + "/.config"
|
||||||
|
: xdg_config
|
||||||
|
);
|
||||||
|
filename = config + "/autostart/comfortable-swipe.desktop";
|
||||||
|
}
|
||||||
|
return filename.data();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_autostart_filename__ */
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__util_conf_filename__
|
||||||
|
#define __COMFORTABLE_SWIPE__util_conf_filename__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../index.hpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::util
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The path where the configuration file is located.
|
||||||
|
*/
|
||||||
|
constexpr const char* conf_filename()
|
||||||
|
{
|
||||||
|
return __COMFORTABLE_SWIPE__CONFIG__;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_conf_filename__ */
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__util_read_config_file__
|
||||||
|
#define __COMFORTABLE_SWIPE__util_read_config_file__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <map> // std::map
|
||||||
|
#include <string> // std::string
|
||||||
|
#include <fstream> // std::ifstream
|
||||||
|
#include <sstream> // std::ostringstream
|
||||||
|
#include <iostream> // std::endl, std::getline
|
||||||
|
#include <cstdlib> // exit
|
||||||
|
#include <cctype> // std::isspace
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
|
||||||
|
namespace comfortable_swipe::util
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A utility method for reading the config file.
|
||||||
|
*
|
||||||
|
* @param filename (const char*) the path of the config file.
|
||||||
|
*/
|
||||||
|
std::map<std::string, std::string> read_config_file(const char* filename)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::map<std::string, std::string> conf;
|
||||||
|
std::ifstream fin(filename);
|
||||||
|
|
||||||
|
if (!fin.is_open())
|
||||||
|
{
|
||||||
|
throw std::runtime_error("config file does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string line, token[2];
|
||||||
|
int line_number = 0;
|
||||||
|
|
||||||
|
while (std::getline(fin, line))
|
||||||
|
{
|
||||||
|
++line_number;
|
||||||
|
token[0].clear();
|
||||||
|
token[1].clear();
|
||||||
|
int length = line.length();
|
||||||
|
int equal_flag = 0;
|
||||||
|
|
||||||
|
// tokenize comfig config
|
||||||
|
for (int i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
if (line[i] == '#') // skip comments
|
||||||
|
break;
|
||||||
|
if (line[i] == '=') // flag equal sign
|
||||||
|
{
|
||||||
|
if (++equal_flag > 1)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "error in conf file " << filename << std::endl;
|
||||||
|
stream << "multiple equal signs in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!std::isspace(line[i]))
|
||||||
|
{
|
||||||
|
// add to buffer
|
||||||
|
token[equal_flag].push_back(line[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore empty lines
|
||||||
|
if (equal_flag == 0 && token[0].length() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// no equal sign found in non-empty line
|
||||||
|
if (equal_flag == 0)
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "error in conf file: " << filename << std::endl;
|
||||||
|
stream << "equal sign expected in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// equal sign found, add to tokens
|
||||||
|
if (token[1].length() > 0)
|
||||||
|
conf[token[0]] = token[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_read_config_file__ */
|
||||||
@@ -1,368 +0,0 @@
|
|||||||
/*
|
|
||||||
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>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <map>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cmath>
|
|
||||||
#include <regex>
|
|
||||||
#include <chrono>
|
|
||||||
#include <ctime>
|
|
||||||
#include <unistd.h>
|
|
||||||
#define cstr const string&
|
|
||||||
#define PROGRAM "/usr/local/bin/comfortable-swipe"
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
// sudo apt install libxdo-dev
|
|
||||||
#include <xdo.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MASKS FOR GESTURES */
|
|
||||||
|
|
||||||
#define MSK_THREE_FINGERS 0
|
|
||||||
#define MSK_FOUR_FINGERS 1
|
|
||||||
#define MSK_NEGATIVE 0
|
|
||||||
#define MSK_POSITIVE 2
|
|
||||||
#define MSK_HORIZONTAL 0
|
|
||||||
#define MSK_VERTICAL 4
|
|
||||||
|
|
||||||
/* GESTURE MNEMONYMS */
|
|
||||||
#define FRESH -1
|
|
||||||
#define OPPOSITE (mask ^ MSK_POSITIVE)
|
|
||||||
|
|
||||||
/* FORWARD DECLARATIONS */
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
string join(cstr, string[], int);
|
|
||||||
string build_gesture_begin();
|
|
||||||
string build_gesture_update();
|
|
||||||
string build_gesture_end();
|
|
||||||
map<string, string> read_config_file(const char*);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace service {
|
|
||||||
void buffer();
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
void status();
|
|
||||||
void restart();
|
|
||||||
void help();
|
|
||||||
void exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MAIN DRIVER FUNCTION */
|
|
||||||
|
|
||||||
int main(int argc, char** args) {
|
|
||||||
if (argc > 1) {
|
|
||||||
string arg = args[1];
|
|
||||||
// select based on argument
|
|
||||||
if (arg == "start") service::start();
|
|
||||||
else if (arg == "stop") service::stop();
|
|
||||||
else if (arg == "status") service::status();
|
|
||||||
else if (arg == "restart") service::restart();
|
|
||||||
else if (arg == "buffer") service::buffer();
|
|
||||||
else if (arg == "exec") service::exec();
|
|
||||||
else service::help();
|
|
||||||
} else {
|
|
||||||
service::help();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct swipe_gesture {
|
|
||||||
string device, stamp, fingers;
|
|
||||||
string dx, dy, udx, udy;
|
|
||||||
xdo_t* xdo;
|
|
||||||
virtual void on_update() = 0;
|
|
||||||
virtual void on_begin() = 0;
|
|
||||||
virtual void on_end() = 0;
|
|
||||||
swipe_gesture(): xdo(xdo_new(NULL)) {}
|
|
||||||
~swipe_gesture() {xdo_free(xdo);}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* const command_map[] = {
|
|
||||||
"left 3",
|
|
||||||
"left 4",
|
|
||||||
"right 3",
|
|
||||||
"right 4",
|
|
||||||
"up 3",
|
|
||||||
"up 4",
|
|
||||||
"down 3",
|
|
||||||
"down 4"
|
|
||||||
};
|
|
||||||
|
|
||||||
struct swipe_gesture_impl : swipe_gesture {
|
|
||||||
int screen_num, ix, iy;
|
|
||||||
float x, y, threshold;
|
|
||||||
int previous_gesture;
|
|
||||||
const char** commands;
|
|
||||||
swipe_gesture_impl(
|
|
||||||
const float threshold,
|
|
||||||
const char* left3 /* 000 */,
|
|
||||||
const char* left4 /* 001 */,
|
|
||||||
const char* right3 /* 010 */,
|
|
||||||
const char* right4 /* 011 */,
|
|
||||||
const char* up3 /* 100 */,
|
|
||||||
const char* up4 /* 101 */,
|
|
||||||
const char* down3 /* 110 */,
|
|
||||||
const char* down4 /* 111 */
|
|
||||||
): swipe_gesture(), threshold(threshold) {
|
|
||||||
commands = new const char*[8];
|
|
||||||
commands[0] = left3;
|
|
||||||
commands[1] = left4;
|
|
||||||
commands[2] = right3;
|
|
||||||
commands[3] = right4;
|
|
||||||
commands[4] = up3;
|
|
||||||
commands[5] = up4;
|
|
||||||
commands[6] = down3;
|
|
||||||
commands[7] = down4;
|
|
||||||
}
|
|
||||||
~swipe_gesture_impl() {
|
|
||||||
delete[] commands;
|
|
||||||
}
|
|
||||||
void key(const char* cmd) const {
|
|
||||||
xdo_send_keysequence_window(xdo, CURRENTWINDOW, cmd, 0);
|
|
||||||
}
|
|
||||||
void on_begin() override {
|
|
||||||
xdo_get_mouse_location(xdo, &ix, &iy, &screen_num);
|
|
||||||
previous_gesture = FRESH;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
void on_update() override {
|
|
||||||
x += stof(dx);
|
|
||||||
y += stof(dy);
|
|
||||||
// scale threshold to 1/10 when gesture is not fresh
|
|
||||||
float scale = previous_gesture == FRESH ?
|
|
||||||
1.0f :
|
|
||||||
0.1f;
|
|
||||||
if (x*x + y*y > threshold*threshold*(scale*scale)) {
|
|
||||||
int mask = 0;
|
|
||||||
if (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
|
||||||
if (fingers == "4") mask |= MSK_FOUR_FINGERS;
|
|
||||||
if (abs(x) > abs(y)) {
|
|
||||||
mask |= MSK_HORIZONTAL;
|
|
||||||
if (x < 0) mask |= MSK_NEGATIVE;
|
|
||||||
else mask |= MSK_POSITIVE;
|
|
||||||
} else {
|
|
||||||
mask |= MSK_VERTICAL;
|
|
||||||
if (y < 0) mask |= MSK_NEGATIVE;
|
|
||||||
else mask |= MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
// send command on fresh OR opposite gesture
|
|
||||||
if (previous_gesture == FRESH or previous_gesture == OPPOSITE) {
|
|
||||||
x = y = 0;
|
|
||||||
previous_gesture = mask;
|
|
||||||
cout << "SWIPE " << command_map[mask] << endl;
|
|
||||||
key(commands[mask]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void on_end() override {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// path services
|
|
||||||
namespace service {
|
|
||||||
// get the full path of the .conf file
|
|
||||||
string conf_filename() {
|
|
||||||
static string *filename = NULL;
|
|
||||||
if (filename == NULL)
|
|
||||||
filename = new string("/usr/local/share/comfortable-swipe.conf");
|
|
||||||
return *filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace service {
|
|
||||||
void exec() {
|
|
||||||
sleep(1);
|
|
||||||
exit(system("/usr/bin/stdbuf -oL -eL /usr/bin/libinput-debug-events 2>&1 | " PROGRAM " buffer"));
|
|
||||||
}
|
|
||||||
// parses output from libinput-debug-events
|
|
||||||
void buffer() {
|
|
||||||
// check first if $user
|
|
||||||
ios::sync_with_stdio(false);
|
|
||||||
cin.tie(0); cout.tie(0);
|
|
||||||
const regex gesture_begin(util::build_gesture_begin());
|
|
||||||
const regex gesture_update(util::build_gesture_update());
|
|
||||||
const regex gesture_end(util::build_gesture_end());
|
|
||||||
string sentence;
|
|
||||||
// read config file
|
|
||||||
auto config = util::read_config_file(conf_filename().data());
|
|
||||||
// initialize gesture handler
|
|
||||||
swipe_gesture_impl swipe(
|
|
||||||
config.count("threshold") ? 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()
|
|
||||||
);
|
|
||||||
while (getline(cin, sentence)) {
|
|
||||||
auto data = sentence.data();
|
|
||||||
cmatch matches;
|
|
||||||
if (regex_match(data, matches, gesture_begin)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.on_begin();
|
|
||||||
}
|
|
||||||
else if (regex_match(data, matches, gesture_end)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.on_end();
|
|
||||||
}
|
|
||||||
else if (regex_match(data, matches, gesture_update)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.dx = matches[4];
|
|
||||||
swipe.dy = matches[5];
|
|
||||||
swipe.udx = matches[6];
|
|
||||||
swipe.udy = matches[7];
|
|
||||||
swipe.on_update();
|
|
||||||
} else if (sentence.find("Segmentation fault") != string::npos) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
} else if (sentence.find("Error") != string::npos) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// starts service
|
|
||||||
void start() {
|
|
||||||
exit(system("systemctl start comfortable-swipe.service"));
|
|
||||||
}
|
|
||||||
// stops service
|
|
||||||
void stop() {
|
|
||||||
exit(system("systemctl stop comfortable-swipe.service"));
|
|
||||||
}
|
|
||||||
// shows the status of the program
|
|
||||||
void status() {
|
|
||||||
exit(system("systemctl status comfortable-swipe.service"));
|
|
||||||
}
|
|
||||||
// stops then starts service
|
|
||||||
void restart() {
|
|
||||||
exit(system("systemctl restart comfortable-swipe.service"));
|
|
||||||
}
|
|
||||||
// shows help
|
|
||||||
void help() {
|
|
||||||
puts("comfortable-swipe [start|stop|status|restart|buffer|help]");
|
|
||||||
puts("");
|
|
||||||
puts("start - starts 3/4-finger gesture service");
|
|
||||||
puts("stop - stops 3/4-finger gesture service");
|
|
||||||
puts("status - shows the status of the program (service log)");
|
|
||||||
puts("restart - stops then starts 3/4-finger gesture service");
|
|
||||||
puts("buffer - parses output of libinput-debug-events");
|
|
||||||
puts("help - shows the help dialog");
|
|
||||||
puts("");
|
|
||||||
puts((("Configuration file can be found in ") + conf_filename()).data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* UTILITY FUNCTIONS */
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
string number_regex() {
|
|
||||||
return "-?\\d+(?:\\.\\d+)";
|
|
||||||
}
|
|
||||||
|
|
||||||
string join(cstr delim, string arr[], int n) {
|
|
||||||
string ans = arr[0];
|
|
||||||
for (int i = 1; i < n; ++i) {
|
|
||||||
ans += delim;
|
|
||||||
ans += arr[i];
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_begin() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_BEGIN\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
|
||||||
return join("\\s+", arr, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_update() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_UPDATE\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string num_1 = "\\s*(" + number_regex() + ")\\s*";
|
|
||||||
string num_2 = num_1;
|
|
||||||
string num_div = num_1 + "/" + num_2;
|
|
||||||
string num_accel = "\\s*\\(\\s*" + num_div + "\\s*unaccelerated\\s*\\)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers, num_div, num_accel};
|
|
||||||
return join("\\s+", arr, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_end() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_END\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
|
||||||
return join("\\s+", arr, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
map<string, string> read_config_file(const char* filename) {
|
|
||||||
map<string, string> conf;
|
|
||||||
ifstream fin(filename);
|
|
||||||
if (!fin.is_open()) {
|
|
||||||
cerr << "file \"" << filename << "\" does not exist!" << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
string line, key, token, buffer, value;
|
|
||||||
int line_number = 0;
|
|
||||||
while (getline(fin, line)) {
|
|
||||||
++line_number;
|
|
||||||
istringstream is(line);
|
|
||||||
buffer.clear();
|
|
||||||
while (is >> token) {
|
|
||||||
if (token[0] == '#')
|
|
||||||
break;
|
|
||||||
buffer += token;
|
|
||||||
}
|
|
||||||
if (buffer.empty())
|
|
||||||
continue;
|
|
||||||
auto id = buffer.find('=');
|
|
||||||
if (id == string::npos) {
|
|
||||||
cerr << "error in conf file: " << filename << endl;
|
|
||||||
cerr << "equal sign expected in line " << line_number << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
key = buffer.substr(0, id);
|
|
||||||
value = buffer.substr(id + 1);
|
|
||||||
conf[key] = value;
|
|
||||||
}
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DIR=$(dirname $0)
|
||||||
|
g++ -std=c++11 -O2 $DIR/test_regex.cpp -lxdo -o test.out || exec "Test aborted"
|
||||||
|
./test.out || rm test.out
|
||||||
|
rm test.out
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cassert>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
#include "../lib/gesture/swipe_gesture.h"
|
||||||
|
#include "../lib/gesture/swipe_gesture.regex.cpp"
|
||||||
|
|
||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace test
|
||||||
|
{
|
||||||
|
void gesture_begin_should_match_regex();
|
||||||
|
void gesture_update_should_match_regex();
|
||||||
|
void gesture_end_should_match_regex();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "(1) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_begin_should_match_regex();
|
||||||
|
|
||||||
|
std::cout << "(2) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_update_should_match_regex();
|
||||||
|
|
||||||
|
std::cout << "(3) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_end_should_match_regex();
|
||||||
|
std::cout << "ALL TEST PASSED" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace test
|
||||||
|
{
|
||||||
|
void gesture_begin_test(
|
||||||
|
const std::regex& matcher,
|
||||||
|
const char* data,
|
||||||
|
const char* expected_fingers)
|
||||||
|
{
|
||||||
|
std::cout << " testing against \"" << data << "\"...";
|
||||||
|
std::cmatch matches;
|
||||||
|
int result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string) matches[1] == expected_fingers);
|
||||||
|
std::cout << "PASSED" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_begin_should_match_regex()
|
||||||
|
{
|
||||||
|
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
||||||
|
test::gesture_begin_test(matcher, " event15 GESTURE_SWIPE_BEGIN +34.33s 3\n", "3");
|
||||||
|
test::gesture_begin_test(matcher, "-event4 GESTURE_SWIPE_BEGIN +3.12s 4\n", "4");
|
||||||
|
test::gesture_begin_test(matcher, "-event7 GESTURE_SWIPE_BEGIN +4.72s 3\n", "3");
|
||||||
|
test::gesture_begin_test(matcher, " event9 GESTURE_SWIPE_BEGIN +45.80s 4\n", "4");
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_update_should_match_regex()
|
||||||
|
{
|
||||||
|
const char* data = " event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)\n";
|
||||||
|
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
||||||
|
std::cmatch matches;
|
||||||
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string) matches[1] == "3");
|
||||||
|
assert((std::string) matches[2] == "-0.12");
|
||||||
|
assert((std::string) matches[3] == "4.99");
|
||||||
|
assert((std::string) matches[4] == "-0.33");
|
||||||
|
assert((std::string) matches[5] == "13.50");
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_end_should_match_regex()
|
||||||
|
{
|
||||||
|
const char* data = " event15 GESTURE_SWIPE_END +35.03s 3\n";
|
||||||
|
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
|
std::cmatch matches;
|
||||||
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string) matches[1] == "3");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
if [ $(id -u) != "0" ]; then
|
|
||||||
sudo bash "$0" "$@"
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
echo "Uninstalling..."
|
echo "Uninstalling..."
|
||||||
echo "
|
rm ${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop 2> /dev/null
|
||||||
Uninstall $(date)" >> .log
|
comfortable-swipe stop 2> /dev/null
|
||||||
|
rm $HOME/.local/bin/comfortable-swipe 2> /dev/null # compat
|
||||||
# stop service
|
sudo rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
||||||
systemctl stop comfortable-swipe.service >> .log 2>> .log
|
|
||||||
systemctl disable comfortable-swipe.service >> .log 2>> .log
|
|
||||||
systemctl daemon-reload
|
|
||||||
|
|
||||||
# remove service
|
|
||||||
SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service"
|
|
||||||
rm $SERVICE_PATH >> .log 2>> .log
|
|
||||||
|
|
||||||
# remove old program
|
|
||||||
OLD_PROGRAM=$HOME/.local/bin/comfortable-swipe
|
|
||||||
rm $OLD_PROGRAM >> .log 2>> .log # compat
|
|
||||||
|
|
||||||
# remove program
|
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
|
||||||
rm $PROGRAM >> .log 2>> .log
|
|
||||||
echo "Successfully uninstalled comfortable-swipe"
|
echo "Successfully uninstalled comfortable-swipe"
|
||||||
Reference in new issue
Block a user