Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd4aa0a49d | ||
|
|
43fe2bb9b3 | ||
|
|
dda91b7178 | ||
|
|
4852993663 | ||
|
|
810a20f1ed | ||
|
|
28f5ca2a91 | ||
|
|
89b79bc9bc | ||
|
|
7d76db6693 | ||
|
|
204a422f2d | ||
|
|
c18cb04230 | ||
|
|
b1f8a7cb0a |
No files matched your search
@@ -1,2 +1,6 @@
|
|||||||
# C++ generated headers
|
# C++ generated headers
|
||||||
*.gch
|
*.gch
|
||||||
|
|
||||||
|
# IDE-specific
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
# 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`.
|
||||||
@@ -14,8 +15,8 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
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,7 +25,7 @@ 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
|
||||||
|
|
||||||
@@ -41,24 +42,32 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
```
|
```
|
||||||
comfortable-swipe autostart
|
comfortable-swipe autostart
|
||||||
```
|
```
|
||||||
5. _Optional_: Change [configurations](#configurations) (see below). After making changes, run
|
5. Check the status of your application by running
|
||||||
```
|
```
|
||||||
comfortable-swipe restart
|
comfortable-swipe status
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configurations
|
## Configurations
|
||||||
Comfortable swipe makes use of keyboard shortcuts for configurations. The configuration file is located at `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`. Make sure to run `comfortable-swipe restart` after making changes.
|
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
|
||||||
|
```
|
||||||
|
gedit $(comfortable-swipe config)
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure to run 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 (Note: Sky is the limit! Can be as large as 1000.0) | 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`:
|
Taken from `man xdotool`:
|
||||||
@@ -80,7 +89,13 @@ Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete li
|
|||||||
|
|
||||||
## Debugging
|
## 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.
|
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:
|
A working swipe gesture will show the following:
|
||||||
|
|
||||||
@@ -112,4 +127,18 @@ 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.
|
Search in [Issues](https://github.com/Hikari9/comfortable-swipe/issues?utf8=%E2%9C%93&q=is%3Aissue) if the problem has already been solved.
|
||||||
|
|
||||||
|
Otherwise, [create a new issue](https://github.com/Hikari9/comfortable-swipe/issues/new) to report your bug.
|
||||||
|
|
||||||
|
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)`
|
||||||
@@ -1,2 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
g++ $(dirname $0)/comfortable-swipe.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1
|
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:]')\""
|
||||||
@@ -16,6 +16,8 @@ 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 <ios> // std::ios
|
||||||
|
#include <iostream> // std::cin, std::cout, std::cerr
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include "lib/comfortable_swipe"
|
#include "lib/comfortable_swipe"
|
||||||
|
|
||||||
@@ -23,6 +25,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
int main(int argc, char** args)
|
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)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
std::string arg = args[1];
|
std::string arg = args[1];
|
||||||
@@ -43,9 +51,15 @@ 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 == "config")
|
||||||
|
comfortable_swipe::service::config();
|
||||||
|
|
||||||
else if (arg == "debug")
|
else if (arg == "debug")
|
||||||
comfortable_swipe::service::debug();
|
comfortable_swipe::service::debug();
|
||||||
|
|
||||||
|
else if (arg == "status")
|
||||||
|
comfortable_swipe::service::status();
|
||||||
|
|
||||||
else /* if (arg == "help") */
|
else /* if (arg == "help") */
|
||||||
comfortable_swipe::service::help();
|
comfortable_swipe::service::help();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +1,93 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# prefer running as root
|
|
||||||
DIR=$(dirname $0)
|
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
|
||||||
COMPILE=$DIR/comfortable-swipe.compile.sh
|
|
||||||
CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf
|
|
||||||
DCONF_PATH=$DIR/defaults.conf
|
|
||||||
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
|
||||||
|
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
function install {
|
||||||
# stop any running comfortable-swipe if it exists
|
# prefer running as root
|
||||||
$PROGRAM stop
|
local dir="$(dirname $0)"
|
||||||
fi
|
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"
|
||||||
|
|
||||||
#copy config file
|
if [ -x "$(command -v $program_exe)" ]; then
|
||||||
abort () {
|
# stop any running $program if it exists
|
||||||
exec echo "Installation aborted"
|
$program_exe stop
|
||||||
}
|
|
||||||
sudo mkdir -p $(dirname $CONF_PATH) || abort
|
|
||||||
|
|
||||||
# check if "-y" or "--yes" is passed as an argument
|
|
||||||
YES=false
|
|
||||||
while test $# -gt 0
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
-y) YES=true
|
|
||||||
;;
|
|
||||||
--yes) YES=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
sudo chown $USER $(dirname $CONF_PATH)
|
|
||||||
if [ ! -f $CONF_PATH ]; then
|
|
||||||
if [ ! -f $OLD_CONF_PATH ]; then
|
|
||||||
# old config file not found, create from scratch
|
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
|
||||||
else
|
|
||||||
# old config file found, move to the new path
|
|
||||||
cat $OLD_CONF_PATH > $CONF_PATH || abort
|
|
||||||
echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH"
|
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# config file found, ask user if overwrite
|
#copy config file
|
||||||
echo "Old conf file found in $CONF_PATH"
|
abort () {
|
||||||
if [ $YES == false ]; then
|
exec echo "Installation aborted"
|
||||||
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
}
|
||||||
response=${response,,} # tolower
|
sudo mkdir -p "$(dirname $conf_path)" || abort
|
||||||
if [[ "$response" =~ ^(no|n)$ ]]; then
|
|
||||||
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
# check if "-y" or "--yes" is passed as an argument
|
||||||
response=${response,,}
|
YES=false
|
||||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
while test $# -gt 0
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
do
|
||||||
else
|
case "$1" in
|
||||||
abort
|
-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
|
||||||
|
# old config file found, move to the new path
|
||||||
|
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
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Installing..."
|
echo "Installing to $program_exe ..."
|
||||||
|
|
||||||
# remove existing comfortable-swipe
|
# remove existing $program
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
if [ -x "$(command -v $program_exe)" ]; then
|
||||||
sudo rm -f $(which comfortable-swipe)
|
sudo rm -f "$(which $program)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# compile library
|
# compile library
|
||||||
sudo $COMPILE $PROGRAM || abort
|
sudo "$compile_command" "$program_exe" || 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
|
||||||
|
|
||||||
# toggle autostart twice to refresh any changes
|
# turn on autostart by default
|
||||||
$PROGRAM autostart > /dev/null || abort
|
local autostart_status="$($program_exe autostart)"
|
||||||
$PROGRAM autostart > /dev/null || abort
|
if [[ "$autostart_status" == *off* ]]; then
|
||||||
|
autostart_status="$($program_exe autostart)"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Successfully installed comfortable-swipe."
|
echo "Successfully installed $program $(cat $dir/VERSION | tr -d '[:space:]')"
|
||||||
echo "Configuration file is located at $CONF_PATH"
|
echo ""
|
||||||
echo ""
|
echo "$autostart_status"
|
||||||
echo "Try running 'comfortable-swipe start' to test."
|
echo "Edit configuration file: gedit \$($program config)"
|
||||||
|
echo ""
|
||||||
|
echo "Try running: $program start"
|
||||||
|
}
|
||||||
|
|
||||||
|
install
|
||||||
|
unset -f install
|
||||||
@@ -30,10 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "gesture/swipe_gesture.regex.cpp"
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
#include "service/autostart.cpp"
|
#include "service/autostart.cpp"
|
||||||
#include "service/buffer.cpp"
|
#include "service/buffer.cpp"
|
||||||
|
#include "service/config.cpp"
|
||||||
#include "service/debug.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"
|
||||||
|
#include "service/status.cpp"
|
||||||
#include "service/stop.cpp"
|
#include "service/stop.cpp"
|
||||||
#include "util/autostart_filename.cpp"
|
#include "util/autostart_filename.cpp"
|
||||||
#include "util/conf_filename.cpp"
|
#include "util/conf_filename.cpp"
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ namespace comfortable_swipe::gesture
|
|||||||
):
|
):
|
||||||
comfortable_swipe::gesture::xdo_gesture(),
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
threshold_squared(threshold*threshold),
|
threshold_squared(threshold*threshold),
|
||||||
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4})
|
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
|
// improve responsiveness of first gesture by pre-empting xdotool runtime
|
||||||
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);
|
||||||
@@ -86,7 +87,9 @@ namespace comfortable_swipe::gesture
|
|||||||
float scale = this->previous_gesture == swipe_gesture::FRESH
|
float scale = this->previous_gesture == swipe_gesture::FRESH
|
||||||
? 1.00f
|
? 1.00f
|
||||||
: 0.01f; // square root of 1/10
|
: 0.01f; // square root of 1/10
|
||||||
if (this->x * this->x + this->y * this->y > this->threshold_squared * scale)
|
static const float EPSILON = 1e-6f;
|
||||||
|
if (this->x * this->x + this->y * this->y
|
||||||
|
> this->threshold_squared * scale + EPSILON)
|
||||||
{
|
{
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
if (this->fingers == 3) mask |= swipe_gesture::MSK_THREE_FINGERS;
|
if (this->fingers == 3) mask |= swipe_gesture::MSK_THREE_FINGERS;
|
||||||
@@ -115,10 +118,10 @@ namespace comfortable_swipe::gesture
|
|||||||
if (this->previous_gesture == swipe_gesture::FRESH
|
if (this->previous_gesture == swipe_gesture::FRESH
|
||||||
|| this->previous_gesture == (mask ^ swipe_gesture::MSK_POSITIVE))
|
|| 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->x = this->y = 0;
|
||||||
this->previous_gesture = mask;
|
this->previous_gesture = mask;
|
||||||
std::cout << "SWIPE " << swipe_gesture::command_map[mask] << std::endl;
|
std::cout << "SWIPE " << swipe_gesture::command_map[mask] << std::endl;
|
||||||
xdo_send_keysequence_window(xdo, CURRENTWINDOW, swipe_gesture::commands[mask], 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +177,8 @@ namespace comfortable_swipe::gesture
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// not swiping, check if swipe will begin
|
// not swiping, check if swipe will begin
|
||||||
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
|
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
|
// assign necessary variables for swipe begin
|
||||||
this->flag_swiping = true;
|
this->flag_swiping = true;
|
||||||
@@ -197,14 +201,14 @@ namespace comfortable_swipe::gesture
|
|||||||
const int swipe_gesture::MSK_VERTICAL = 4;
|
const int swipe_gesture::MSK_VERTICAL = 4;
|
||||||
const int swipe_gesture::FRESH = -1;
|
const int swipe_gesture::FRESH = -1;
|
||||||
const char * const swipe_gesture::command_map[8] = {
|
const char * const swipe_gesture::command_map[8] = {
|
||||||
"left 3",
|
"left3",
|
||||||
"left 4",
|
"left4",
|
||||||
"right 3",
|
"right3",
|
||||||
"right 4",
|
"right4",
|
||||||
"up 3",
|
"up3",
|
||||||
"up 4",
|
"up4",
|
||||||
"down 3",
|
"down3",
|
||||||
"down 4"
|
"down4"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ 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
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ extern "C"
|
|||||||
#include <xdo.h> // xdo, xdo_new
|
#include <xdo.h> // xdo, xdo_new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
namespace comfortable_swipe::gesture
|
namespace comfortable_swipe::gesture
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
||||||
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */
|
#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 <map> // std::map
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
|
|
||||||
@@ -50,10 +55,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
void autostart();
|
void autostart();
|
||||||
void buffer();
|
void buffer();
|
||||||
|
void config();
|
||||||
void debug();
|
void debug();
|
||||||
void help();
|
void help();
|
||||||
void restart();
|
void restart();
|
||||||
void start();
|
void start();
|
||||||
|
void status();
|
||||||
void stop();
|
void stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-5
@@ -19,7 +19,8 @@ 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 <cstdio> // std::fgets_unlocked, stdin
|
#include <cstdio> // fgets_unlocked, stdin
|
||||||
|
#include <iostream> // std::ios, std::cout, std::cin
|
||||||
#include "../index.hpp"
|
#include "../index.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +30,11 @@ namespace comfortable_swipe::service
|
|||||||
{
|
{
|
||||||
void buffer()
|
void buffer()
|
||||||
{
|
{
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(0);
|
||||||
|
std::cout.tie(0);
|
||||||
|
std::cout.flush();
|
||||||
|
|
||||||
// read config file
|
// read config file
|
||||||
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
@@ -47,14 +53,13 @@ namespace comfortable_swipe::service
|
|||||||
);
|
);
|
||||||
|
|
||||||
// prepare data containers
|
// prepare data containers
|
||||||
static const int MAX_LINE_LENGTH = 256;
|
std::array<char, 256> line;
|
||||||
static char data[MAX_LINE_LENGTH];
|
|
||||||
|
|
||||||
// start reading lines from input one by one
|
// start reading lines from input one by one
|
||||||
while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL)
|
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
||||||
{
|
{
|
||||||
// attempt to parse swipe gestures
|
// attempt to parse swipe gestures
|
||||||
swipe_gesture_handler.parse_line(data);
|
swipe_gesture_handler.parse_line(line.data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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__ */
|
||||||
@@ -28,7 +28,7 @@ namespace comfortable_swipe::service
|
|||||||
*/
|
*/
|
||||||
void debug()
|
void debug()
|
||||||
{
|
{
|
||||||
(void) std::system("stdbuf -oL -e0 libinput debug-events");
|
(void) std::system("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep -v 'double tracking')\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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|debug]");
|
std::puts("comfortable-swipe " COMFORTABLE_SWIPE_VERSION " [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
||||||
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,7 +38,9 @@ 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("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("debug - logs raw output from input events taken from libinput");
|
||||||
|
std::puts("status - checks status of program and autostart");
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace comfortable_swipe::service
|
|||||||
*/
|
*/
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
(void) std::system("stdbuf -oL -e0 libinput debug-events | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer");
|
(void) std::system(__COMFORTABLE_SWIPE__PROGRAM__ " debug | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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__ */
|
||||||
+10
-13
@@ -24,6 +24,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <stdexcept> // std::runtime_error
|
#include <stdexcept> // std::runtime_error
|
||||||
#include <unistd.h> // popen, pclose, getpid
|
#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
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -34,24 +38,22 @@ namespace comfortable_swipe::service
|
|||||||
{
|
{
|
||||||
|
|
||||||
// read all service names from process (pgrep)
|
// read all service names from process (pgrep)
|
||||||
char* buffer = new char[20];
|
std::array<char, 128> buffer;
|
||||||
FILE* pipe = popen("pgrep -f comfortable-swipe", "r");
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
||||||
|
|
||||||
// make sure pipe exists
|
// make sure pipe exists
|
||||||
if (pipe == NULL)
|
if (!pipe)
|
||||||
{
|
|
||||||
throw std::runtime_error("stop command failed");
|
throw std::runtime_error("stop command failed");
|
||||||
}
|
|
||||||
|
|
||||||
// buffer what to kill
|
// buffer what to kill
|
||||||
std::string kill = "kill";
|
std::string kill = "kill";
|
||||||
|
|
||||||
// read until end of line
|
// read until end of line
|
||||||
while (!std::feof(pipe))
|
while (!std::feof(pipe.get()))
|
||||||
{
|
{
|
||||||
if (std::fgets(buffer, 20, pipe) != NULL)
|
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
|
||||||
{
|
{
|
||||||
int pid = std::atoi(buffer);
|
int pid = std::atoi(buffer.data());
|
||||||
if (pid != getpid())
|
if (pid != getpid())
|
||||||
{
|
{
|
||||||
kill += " ";
|
kill += " ";
|
||||||
@@ -62,11 +64,6 @@ namespace comfortable_swipe::service
|
|||||||
|
|
||||||
// run "kill {pid1} {pid2}..."
|
// run "kill {pid1} {pid2}..."
|
||||||
(void) std::system(kill.data());
|
(void) std::system(kill.data());
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
// close the pipe
|
|
||||||
pclose(pipe);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <map> // std::map
|
#include <map> // std::map
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <fstream> // std::ifstream
|
#include <fstream> // std::ifstream
|
||||||
#include <iostream> // std::cerr, std::endl, std::getline
|
#include <sstream> // std::ostringstream
|
||||||
|
#include <iostream> // std::endl, std::getline
|
||||||
#include <cstdlib> // exit
|
#include <cstdlib> // exit
|
||||||
#include <cctype> // std::isspace
|
#include <cctype> // std::isspace
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
|
||||||
namespace comfortable_swipe::util
|
namespace comfortable_swipe::util
|
||||||
{
|
{
|
||||||
@@ -41,8 +43,7 @@ namespace comfortable_swipe::util
|
|||||||
|
|
||||||
if (!fin.is_open())
|
if (!fin.is_open())
|
||||||
{
|
{
|
||||||
std::cerr << "file \"" << filename << "\" does not exist!" << std::endl;
|
throw std::runtime_error("config file does not exist");
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string line, token[2];
|
static std::string line, token[2];
|
||||||
@@ -65,9 +66,10 @@ namespace comfortable_swipe::util
|
|||||||
{
|
{
|
||||||
if (++equal_flag > 1)
|
if (++equal_flag > 1)
|
||||||
{
|
{
|
||||||
std::cerr << "error in conf file " << filename << std::endl;
|
std::ostringstream stream;
|
||||||
std::cerr << "multiple equal signs in line " << line_number << std::endl;
|
stream << "error in conf file " << filename << std::endl;
|
||||||
exit(1);
|
stream << "multiple equal signs in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!std::isspace(line[i]))
|
else if (!std::isspace(line[i]))
|
||||||
@@ -84,9 +86,10 @@ namespace comfortable_swipe::util
|
|||||||
// no equal sign found in non-empty line
|
// no equal sign found in non-empty line
|
||||||
if (equal_flag == 0)
|
if (equal_flag == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "error in conf file: " << filename << std::endl;
|
std::ostringstream stream;
|
||||||
std::cerr << "equal sign expected in line " << line_number << std::endl;
|
stream << "error in conf file: " << filename << std::endl;
|
||||||
exit(1);
|
stream << "equal sign expected in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// equal sign found, add to tokens
|
// equal sign found, add to tokens
|
||||||
|
|||||||
Reference in new issue
Block a user