Update dispatch script

This commit is contained in:
Rico Tiongson 2020-04-21 04:40:46 +08:00
parent c7eeb66dfa
commit 9aa11635d2
4 changed files with 146 additions and 112 deletions

133
README.md
View File

@ -64,44 +64,66 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
```basha ```basha
$> comfortable-swipe status $> comfortable-swipe status
Autostart is ON
autostart is ON Program is RUNNING
comfortable-swipe program is RUNNING
``` ```
## List of Commands ## List of Commands
1. Run / stop the program 1. Program
``` ```
comfortable-swipe start comfortable-swipe start
comfortable-swipe stop comfortable-swipe stop
comfortable-swipe restart comfortable-swipe restart
comfortable-swipe status
``` ```
1. Show help / version 1. Help / version
``` ```
comfortable-swipe --help comfortable-swipe --help
comfortable-swipe --version comfortable-swipe --version
``` ```
1. Show path to configuration file 1. Autostart
```bash
comfortable-swipe config
```
1. Toggle autostart
```bash ```bash
comfortable-swipe autostart [on|off|toggle|status|path] comfortable-swipe autostart [on|off|toggle|status|path]
``` ```
1) (Advanced) Run program buffer 1. Configurations
```bash ```bash
comfortable-swipe buffer # configuration value
comfortable-swipe config get <KEY>
comfortable-swipe config set <KEY> [=] <VALUE>
# list all configurations
comfortable-swipe config list [<pattern>]
# remove configuration value
comfortable-swipe config delete <KEY>
```
1. Configuration extras
```bash
# show all possible configuration keys
comfortable-swipe config keys
# show path to config
comfortable-swipe config path
# open config file with editor
comfortable-swipe config edit
```
1. (Advanced) Run program buffer
```bash
./my-custom-runner | comfortable-swipe buffer
``` ```
## Configuring Swipe Gestures ## Configuring Swipe Gestures
@ -109,21 +131,6 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
The default configuration file is located at `~/.config/comfortable-swipe.conf`. The default configuration file is located at `~/.config/comfortable-swipe.conf`.
Comfortable swipe makes use of keyboard shortcuts to perform swipes through `xdotool`. Comfortable swipe makes use of keyboard shortcuts to perform swipes through `xdotool`.
An example:
```bash
# File: ~/.config/comfortable-swipe.conf
left3 = ctrl+alt+Right
left4 = ctrl+alt+shift+Right
right3 = ctrl+alt+Left
right4 = ctrl+alt+shift+Left
up3 = ctrl+alt+Down
up4 = ctrl+alt+shift+Down
down3 = ctrl+alt+Up
down4 = ctrl+alt+shift+Up
threshold = 0.0
```
Edit configurations by running: Edit configurations by running:
@ -140,11 +147,11 @@ comfortable-swipe restart
> **Note**: For v1.1.0 below, the configuration file is located at > **Note**: For v1.1.0 below, the configuration file is located at
> `/usr/local/share/comfortable-swipe/comfortable-swipe.conf` > `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`
> **Note**: You can locate your configuration by running `comfortable-swipe config` > **Note**: You can locate your configuration by running `comfortable-swipe config path`
## Configuration Reference ## Configuration Reference
| Key | Value | Examples | | Key | Value | Example |
| --------- | :--------------------------------------------------------------------: | ------------------------------------------------------------ | | --------- | :--------------------------------------------------------------------: | ------------------------------------------------------------ |
| left3 | 3-finger swipe left | ctrl+alt+Right | | left3 | 3-finger swipe left | ctrl+alt+Right |
| left4 | 4-finger swipe left | ctrl+alt+shift+Right | | left4 | 4-finger swipe left | ctrl+alt+shift+Right |
@ -154,9 +161,9 @@ comfortable-swipe restart
| up4 | 4-finger swipe up | ctrl+alt+shift+Down | | up4 | 4-finger swipe up | ctrl+alt+shift+Down |
| down3 | 3-finger swipe down | ctrl+alt+Up | | down3 | 3-finger swipe down | ctrl+alt+Up |
| down4 | 4-finger swipe down | ctrl+alt+shift+Up | | down4 | 4-finger swipe down | ctrl+alt+shift+Up |
| threshold | mouse movement pixels that trigger a swipe (can be as large as 1000.0) | 0.0, 240.0, 1000.0 | | thresmouse | mouse movement pixels that trigger a swipe (can be as large as 1000.0) | 0.0, 240.0, 1000.0 |
| mouse3 | holds a mouse button when 3 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental)) | | | mouse3 | mouses a mouse button when 3 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental)) | |
| mouse4 | holds a mouse button when 4 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental) | | mouse4 | mouses a mouse button when 4 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental) |
Taken from `man xdotool`: Taken from `man xdotool`:
@ -184,13 +191,13 @@ Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete li
## Example Configurations ## Example Configurations
This section includes some example configurations for `~/.config/comfortable-swipe.conf` which you can use for your swipe experience. This section includes some example configurations which you can use for your swipe experience.
1. Switch workspace (horizontal) 1. Switch workspace (horizontal)
```bash ```bash
left3 = ctrl+alt+Right comfortable-swipe config set left3 = ctrl+alt+Right
right3 = ctrl+alt+Left comfortable-swipe config set right3 = ctrl+alt+Left
``` ```
1. Switch workspace (vertical) 1. Switch workspace (vertical)
@ -289,60 +296,56 @@ Keys:
- hold3 (deprecated) - old equivalent of mouse3 - hold3 (deprecated) - old equivalent of mouse3
- hold4 (deprecated) - old equivalent of mouse4 - hold4 (deprecated) - old equivalent of mouse4
We have included simple mouse gestures on swipe by setting `hold3` and `hold4`.
Possible Values: Possible Values:
- button1 - hold left click on finger swipe - button1 - left click
- button2 - hold middle click on finger swipe - button2 - middle click
- button3 - hold right click on finger swipe - button3 - right click
- button4 - wheel up on finger swipe (experimental) - button4 - wheel up (experimental)
- button5 - wheel down on finger swipe (experimental) - button5 - wheel down (experimental)
- move - just move the mouse cursor with the fingers - move - just move the mouse cursor while fingers are down
- scroll - 3/4 finger natural scroll (no acceleration, very experimental) - scroll - 3/4 finger natural scroll (no acceleration, very experimental)
- scroll_reverse - 3/4 finger reverse scroll (no acceleration, very experimental) - scroll_reverse - 3/4 finger reverse scroll (no acceleration, very experimental)
Examples: Examples:
- 3-finger drag - 3/4-finger drag
```bash
mouse3 = button1
```
```bash
mouse4 = button1
```
- 3/4-finger natural scroll
```bash ```bash
hold3 = button1 mouse3 = scroll
``` ```
- 4-finger drag (with middle click)
```bash ```bash
hold4 = button2 mouse4 = scroll
``` ```
- 3-finger natural scroll - 3/4-finger reverse scroll
```bash ```bash
hold3 = scroll mouse3 = scroll_reverse
``` ```
- 4-finger reverse scroll
```bash ```bash
hold4 = scroll_reverse mouse4 = scroll_reverse
``` ```
- Just move the cursor - Move 3/4-fingers with the cursor
```bash ```bash
hold3 = move mouse3 = move
hold4 = move
``` ```
- Any other command will disable the mouse hold
```bash ```bash
hold3 = disabled mouse4 = move
hold4 = nothing
``` ```
**Note**: Applying any mouse-hold configuration will disable up/left/right/down behavior to avoid gesture conflicts. The logic of this will be improved in the future. **Note**: Applying any mouse-mouse configuration may disable up/left/right/down behavior to avoid gesture conflicts. The logic of this will be improved in the future.
## Debugging ## Debugging
@ -381,6 +384,8 @@ If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supp
## Uninstall ## Uninstall
Run the following script:
```bash ```bash
wget -qO - https://raw.githubusercontent.com/Hikari9/comfortable-swipe/master/uninstall | bash wget -qO - https://raw.githubusercontent.com/Hikari9/comfortable-swipe/master/uninstall | bash
``` ```

View File

@ -7,13 +7,27 @@ set -e
DIR="$(dirname "$0")" DIR="$(dirname "$0")"
BASENAME="$(basename "$0")" BASENAME="$(basename "$0")"
VERSION="$(cat "$DIR/VERSION" | tr -d '[:space:]')" # note: this will be hardcoded upon install VERSION="$(cat "$DIR/VERSION" | tr -d '[:space:]')" # note: this will be hardcoded upon install
KEYS="left3|left4|right3|right4|up3|up4|down3|down4|threshold|mouse3|mouse4"
DEPRECATED="hold3|hold4"
function usage {
cat <<EOF
Usage: $BASENAME [--help|--version] [start|stop|restart|config|autostart|buffer|debug|status] [<args>]
Configuration:
$BASENAME <PROPERTY> gets configuration property
$BASENAME <PROPERTY> [=] <VALUE> sets configuration to a value
EOF
}
# show help # show help
function help { function help {
usage
cat <<EOF cat <<EOF
Usage: $BASENAME [--help|--version] <command> [<args>]
Global Options:
-h, --help show this help text -h, --help show this help text
-v, --version print the program version -v, --version print the program version
@ -28,16 +42,16 @@ Commands:
restart restart
restarts 3/4-finger gesture service restarts 3/4-finger gesture service
autostart [<on|off|toggle|status|path>] edit
edits the configuration file with gedit
autostart <[on|off|toggle|status|path]>
toggle to automatically run on startup automatically run on startup (toggleable) toggle to automatically run on startup automatically run on startup (toggleable)
buffer buffer
parses output of libinput debug-events parses output of libinput debug-events
help config <[get|set|delete|list|properties|path]> [...]
shows the help dialog
config [<get|set|delete|list|keys|path>...]
shows the location of the config file shows the location of the config file
debug debug
@ -60,12 +74,12 @@ function start {
# stop running comfortable-swipe commands (except self) # stop running comfortable-swipe commands (except self)
function stop { function stop {
function stop_name { function stop_prop {
pgrep -f "${1:?}" | fgrep -v $$ | xargs kill -- pgrep -f "${1:?}" | fgrep -v $$ | xargs kill --
} }
stop_name "$BASENAME" stop_prop "$BASENAME"
stop_name "$(which comfortable-swipe)" stop_prop "$(which comfortable-swipe)"
stop_name "$(which comfortable-swipe-buffer)" stop_prop "$(which comfortable-swipe-buffer)"
} }
@ -97,16 +111,31 @@ function buffer {
} }
# verbosely show comfortable-swipe status
function status {
# TODO: show configuration status as well
echo "Autostart is $("$BASENAME" autostart status)"
if pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1; then
echo "Program is RUNNING"
else
echo "Program is STOPPED"
fi
}
# get location of configuration file # get location of configuration file
function config { function config {
local CONFIG="$HOME/.config/comfortable-swipe.conf" local CONFIG="$HOME/.config/comfortable-swipe.conf"
local KEYS="left3|left4|right3|right4|up3|up4|down3|down4|threshold|mouse3|mouse4" function usage {
local DEPRECATED="hold3|hold4" echo "Usage: $BASENAME config [get|set|delete|list|keys|edit|path]..."
local USAGE="Usage: $BASENAME config [get|set|delete|list|keys|path]..." }
# show path to config # show path to config
function path { function path {
echo "$CONFIG" echo "$CONFIG"
} }
# eit configuration with gedit
function edit {
gedit "$CONFIG"
}
# get all keys from config, without comments # get all keys from config, without comments
# and show only last among duplicates # and show only last among duplicates
function list { function list {
@ -135,12 +164,12 @@ function config {
echo "$KEYS" | sed 's/|/\n/g' echo "$KEYS" | sed 's/|/\n/g'
} }
# Get a specific key in the config # Get a specific key in the config
# Usage: comfortable-swipe config get <key> # Usage: comfortable-swipe config get <PROP>
function get { function get {
# helper function to print usage # helper function to print usage
function usage { function usage {
echo "Usage: $BASENAME config get <KEY>" echo "Usage: $BASENAME config get <PROP>"
echo -n "Keys: " echo -n "Props: "
echo "$KEYS" | sed 's/|/, /g' echo "$KEYS" | sed 's/|/, /g'
} }
# no next argument: show list # no next argument: show list
@ -151,13 +180,13 @@ function config {
local KEY="$1" local KEY="$1"
# check if key is valid # check if key is valid
if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then
echo "'$KEY' is an invalid key" >&2 echo "'$KEY' is an invalid property" >&2
echo >&2 echo >&2
usage >&2 usage >&2
echo >&2 echo >&2
echo "If you want to filter keys, you can instead try:" >&2 echo "If you want to filter properties, you can instead try:" >&2
echo >&2 echo >&2
echo " $BASENAME config list $@" echo " $BASENAME config list $@" >&2
echo >&2 echo >&2
exit 1 exit 1
fi fi
@ -168,11 +197,11 @@ function config {
function delete { function delete {
# helper function to print usage # helper function to print usage
function usage { function usage {
echo "Usage: $BASENAME config delete [<KEYS>...]" echo "Usage: $BASENAME config delete [<PROPERTY>...]"
} }
# no next argument: show help # no next argument: show help
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
echo "Key is required!" >&2 echo "Property name is required!" >&2
# no key; show usage # no key; show usage
usage >&2 usage >&2
exit 1 exit 1
@ -196,13 +225,13 @@ function config {
function set { function set {
# helper function to print usage # helper function to print usage
function usage { function usage {
echo "Usage: $BASENAME config set <KEY> [=] <VALUE>" echo "Usage: $BASENAME config set <PROPERTY> [=] <VALUE>"
echo -n "Valid keys: " echo -n "Valid properties: "
echo "$KEYS" | sed 's/|/, /g' echo "$KEYS" | sed 's/|/, /g'
} }
# no next argument: show help # no next argument: show help
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
echo "Key is required!" >&2 echo "Property name is required!" >&2
echo >&2 echo >&2
# no key; show usage # no key; show usage
usage >&2 usage >&2
@ -221,7 +250,7 @@ function config {
*) *)
# default: just get from next arguments combined # default: just get from next arguments combined
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
echo "Value is required!" >&2 echo "Property value is required!" >&2
usage >&2 usage >&2
echo >&2 echo >&2
echo "If you want to set value to blank, explicitly pass a blank string:" >&2 echo "If you want to set value to blank, explicitly pass a blank string:" >&2
@ -243,7 +272,7 @@ function config {
VALUE="$(echo "$VALUE" | awk '{$1=$1};1')" VALUE="$(echo "$VALUE" | awk '{$1=$1};1')"
# check if key is valid # check if key is valid
if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then
echo "'$KEY' is an invalid key" >&2 echo "'$KEY' is an invalid property name" >&2
echo >&2 echo >&2
usage usage
exit 1 exit 1
@ -269,8 +298,8 @@ function config {
} }
# dispatch subcommands # dispatch subcommands
if [[ $# -eq 0 ]]; then if [[ $# -eq 0 ]]; then
# no options; just show path # no options; just show usage
path usage
elif declare -f "$1" >/dev/null 2>&1; then elif declare -f "$1" >/dev/null 2>&1; then
# invoke subcommand function, passing arguments through # invoke subcommand function, passing arguments through
# TODO: unset all nonlocal functions # TODO: unset all nonlocal functions
@ -335,18 +364,6 @@ function autostart {
} }
# verbosely show comfortable-swipe status
function status {
# TODO: show configuration status as well
echo "Autostart is $("$BASENAME" autostart status)"
if pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1; then
echo "comfortable-swipe program is RUNNING"
else
echo "comfortable-swipe program is STOPPED"
fi
}
#################### ####################
# COMMAND OPTIONS # # COMMAND OPTIONS #
#################### ####################
@ -378,7 +395,24 @@ elif declare -f "$1" >/dev/null 2>&1; then
# TODO: unset all nonlocal functions # TODO: unset all nonlocal functions
"$@" # same as "$1" "$2" "$3" ... for full argument list "$@" # same as "$1" "$2" "$3" ... for full argument list
else else
echo "Error: function $1 not recognized" >&2 # try to invoke config set / get depending on number of arguments
echo "Usage: $BASENAME [--help|--version] [start|stop|restart|config|autostart|buffer|debug|status] [<args>]" >&2 if [[ $# -eq 1 ]]; then
exit 1 # one argument, use shorthand get
"$BASENAME" config get "$1" 2> /dev/null
retval=$?
else
# multiple arguments, use shorthand set
config set "$@" 2> /dev/null
retval=$?
fi
if $retval; then
exit $retval
else
echo "Error: $1 not recognized" >&2
echo >&2
usage >&2
echo -n "Valid props: " >&2
echo "$KEYS" | sed 's/|/, /g' >&2
fi
exit $retval
fi fi

View File

@ -175,9 +175,5 @@ cat <<EOF
Successfully installed comfortable-swipe $VERSION Successfully installed comfortable-swipe $VERSION
Autostart switched $("$TARGET" autostart status) Autostart switched $("$TARGET" autostart status)
Edit configuration file with:
gedit \$(comfortable-swipe config)
Try running: comfortable-swipe start Try running: comfortable-swipe start
EOF EOF

View File

@ -33,6 +33,5 @@ if [ -f "$CONF_TARGET" ]; then
fi fi
cat <<EOF cat <<EOF
Successfully uninstalled comfortable-swipe Successfully uninstalled comfortable-swipe
EOF EOF