From 9aa11635d288be35f8d6d887ac2bdc17190e268c Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Tue, 21 Apr 2020 04:40:46 +0800 Subject: [PATCH] Update dispatch script --- README.md | 133 ++++++++++++++++++++++++---------------------- comfortable-swipe | 120 ++++++++++++++++++++++++++--------------- install | 4 -- uninstall | 1 - 4 files changed, 146 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 93159f9..1d90e51 100644 --- a/README.md +++ b/README.md @@ -64,44 +64,66 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures ```basha $> comfortable-swipe status - - autostart is ON - comfortable-swipe program is RUNNING + Autostart is ON + Program is RUNNING ``` ## List of Commands -1. Run / stop the program +1. Program ``` comfortable-swipe start comfortable-swipe stop comfortable-swipe restart + comfortable-swipe status ``` -1. Show help / version +1. Help / version ``` comfortable-swipe --help comfortable-swipe --version ``` -1. Show path to configuration file - - ```bash - comfortable-swipe config - ``` - -1. Toggle autostart +1. Autostart ```bash comfortable-swipe autostart [on|off|toggle|status|path] ``` -1) (Advanced) Run program buffer +1. Configurations ```bash - comfortable-swipe buffer + # configuration value + comfortable-swipe config get + comfortable-swipe config set [=] + + # list all configurations + comfortable-swipe config list [] + + # remove configuration value + comfortable-swipe config delete + + ``` + +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 @@ -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`. 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: @@ -140,11 +147,11 @@ comfortable-swipe restart > **Note**: For v1.1.0 below, the configuration file is located at > `/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 -| Key | Value | Examples | +| Key | Value | Example | | --------- | :--------------------------------------------------------------------: | ------------------------------------------------------------ | | left3 | 3-finger swipe left | ctrl+alt+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 | | down3 | 3-finger swipe down | ctrl+alt+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 | -| mouse3 | holds 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) | +| thresmouse | mouse movement pixels that trigger a swipe (can be as large as 1000.0) | 0.0, 240.0, 1000.0 | +| mouse3 | mouses a mouse button when 3 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`: @@ -184,13 +191,13 @@ Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete li ## 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) ```bash - left3 = ctrl+alt+Right - right3 = ctrl+alt+Left + comfortable-swipe config set left3 = ctrl+alt+Right + comfortable-swipe config set right3 = ctrl+alt+Left ``` 1. Switch workspace (vertical) @@ -289,60 +296,56 @@ Keys: - hold3 (deprecated) - old equivalent of mouse3 - hold4 (deprecated) - old equivalent of mouse4 -We have included simple mouse gestures on swipe by setting `hold3` and `hold4`. - Possible Values: -- button1 - hold left click on finger swipe -- button2 - hold middle click on finger swipe -- button3 - hold right click on finger swipe -- button4 - wheel up on finger swipe (experimental) -- button5 - wheel down on finger swipe (experimental) -- move - just move the mouse cursor with the fingers +- button1 - left click +- button2 - middle click +- button3 - right click +- button4 - wheel up (experimental) +- button5 - wheel down (experimental) +- move - just move the mouse cursor while fingers are down - scroll - 3/4 finger natural scroll (no acceleration, very experimental) - scroll_reverse - 3/4 finger reverse scroll (no acceleration, very experimental) Examples: -- 3-finger drag +- 3/4-finger drag + ```bash + mouse3 = button1 + ``` + ```bash + mouse4 = button1 + ``` +- 3/4-finger natural scroll ```bash - hold3 = button1 + mouse3 = scroll ``` -- 4-finger drag (with middle click) - ```bash - hold4 = button2 + mouse4 = scroll ``` -- 3-finger natural scroll +- 3/4-finger reverse scroll ```bash - hold3 = scroll + mouse3 = scroll_reverse ``` -- 4-finger reverse scroll - ```bash - hold4 = scroll_reverse + mouse4 = scroll_reverse ``` -- Just move the cursor +- Move 3/4-fingers with the cursor ```bash - hold3 = move - hold4 = move + mouse3 = move ``` - -- Any other command will disable the mouse hold - ```bash - hold3 = disabled - hold4 = nothing + mouse4 = move ``` -**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 @@ -381,6 +384,8 @@ If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supp ## Uninstall +Run the following script: + ```bash wget -qO - https://raw.githubusercontent.com/Hikari9/comfortable-swipe/master/uninstall | bash ``` diff --git a/comfortable-swipe b/comfortable-swipe index 3b51a7c..94d2136 100755 --- a/comfortable-swipe +++ b/comfortable-swipe @@ -7,13 +7,27 @@ set -e DIR="$(dirname "$0")" BASENAME="$(basename "$0")" 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 <] +Configuration: + + $BASENAME gets configuration property + $BASENAME [=] sets configuration to a value + +EOF +} # show help function help { + usage cat < [] + +Global Options: -h, --help show this help text -v, --version print the program version @@ -28,16 +42,16 @@ Commands: restart restarts 3/4-finger gesture service - autostart [] + edit + edits the configuration file with gedit + + autostart <[on|off|toggle|status|path]> toggle to automatically run on startup automatically run on startup (toggleable) buffer parses output of libinput debug-events - help - shows the help dialog - - config [...] + config <[get|set|delete|list|properties|path]> [...] shows the location of the config file debug @@ -60,12 +74,12 @@ function start { # stop running comfortable-swipe commands (except self) function stop { - function stop_name { + function stop_prop { pgrep -f "${1:?}" | fgrep -v $$ | xargs kill -- } - stop_name "$BASENAME" - stop_name "$(which comfortable-swipe)" - stop_name "$(which comfortable-swipe-buffer)" + stop_prop "$BASENAME" + stop_prop "$(which comfortable-swipe)" + 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 function config { local CONFIG="$HOME/.config/comfortable-swipe.conf" - local KEYS="left3|left4|right3|right4|up3|up4|down3|down4|threshold|mouse3|mouse4" - local DEPRECATED="hold3|hold4" - local USAGE="Usage: $BASENAME config [get|set|delete|list|keys|path]..." + function usage { + echo "Usage: $BASENAME config [get|set|delete|list|keys|edit|path]..." + } # show path to config function path { echo "$CONFIG" } + # eit configuration with gedit + function edit { + gedit "$CONFIG" + } # get all keys from config, without comments # and show only last among duplicates function list { @@ -135,12 +164,12 @@ function config { echo "$KEYS" | sed 's/|/\n/g' } # Get a specific key in the config - # Usage: comfortable-swipe config get + # Usage: comfortable-swipe config get function get { # helper function to print usage function usage { - echo "Usage: $BASENAME config get " - echo -n "Keys: " + echo "Usage: $BASENAME config get " + echo -n "Props: " echo "$KEYS" | sed 's/|/, /g' } # no next argument: show list @@ -151,13 +180,13 @@ function config { local KEY="$1" # check if key is valid if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then - echo "'$KEY' is an invalid key" >&2 + echo "'$KEY' is an invalid property" >&2 echo >&2 usage >&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 " $BASENAME config list $@" + echo " $BASENAME config list $@" >&2 echo >&2 exit 1 fi @@ -168,11 +197,11 @@ function config { function delete { # helper function to print usage function usage { - echo "Usage: $BASENAME config delete [...]" + echo "Usage: $BASENAME config delete [...]" } # no next argument: show help if [[ $# -eq 0 ]]; then - echo "Key is required!" >&2 + echo "Property name is required!" >&2 # no key; show usage usage >&2 exit 1 @@ -196,13 +225,13 @@ function config { function set { # helper function to print usage function usage { - echo "Usage: $BASENAME config set [=] " - echo -n "Valid keys: " + echo "Usage: $BASENAME config set [=] " + echo -n "Valid properties: " echo "$KEYS" | sed 's/|/, /g' } # no next argument: show help if [[ $# -eq 0 ]]; then - echo "Key is required!" >&2 + echo "Property name is required!" >&2 echo >&2 # no key; show usage usage >&2 @@ -221,7 +250,7 @@ function config { *) # default: just get from next arguments combined if [[ $# -eq 1 ]]; then - echo "Value is required!" >&2 + echo "Property value is required!" >&2 usage >&2 echo >&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')" # check if key is valid if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then - echo "'$KEY' is an invalid key" >&2 + echo "'$KEY' is an invalid property name" >&2 echo >&2 usage exit 1 @@ -269,8 +298,8 @@ function config { } # dispatch subcommands if [[ $# -eq 0 ]]; then - # no options; just show path - path + # no options; just show usage + usage elif declare -f "$1" >/dev/null 2>&1; then # invoke subcommand function, passing arguments through # 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 # #################### @@ -378,7 +395,24 @@ elif declare -f "$1" >/dev/null 2>&1; then # TODO: unset all nonlocal functions "$@" # same as "$1" "$2" "$3" ... for full argument list else - echo "Error: function $1 not recognized" >&2 - echo "Usage: $BASENAME [--help|--version] [start|stop|restart|config|autostart|buffer|debug|status] []" >&2 - exit 1 + # try to invoke config set / get depending on number of arguments + if [[ $# -eq 1 ]]; then + # 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 diff --git a/install b/install index 6eb26ab..b869c30 100755 --- a/install +++ b/install @@ -175,9 +175,5 @@ cat <