Compare commits

..

16 Commits

Author SHA1 Message Date
gobborg
bc117c0ab5
Print abort() echo 'Installation aborted' to stdout. Allow \n (ENTER)… (#109)
* Print abort() echo 'Installation aborted' to stdout. Allow \n (ENTER) to be the printed default: yes.

* Actually handling the null response instead of galaxy brained putting a 'continue' as a placeholder in a conditional tree.
2023-10-21 13:01:15 +08:00
Rico Tiongson
4cf3bf3d8d
Update README.md 2020-05-12 10:06:23 +08:00
Rico Tiongson
9393a96d3f
Update README.md 2020-05-12 10:03:10 +08:00
Rico Tiongson
179083a152
Update README.md 2020-05-12 10:00:10 +08:00
Rico Tiongson
99f659c9db
Add guard for root bash install (#92)
* Add guard for root bash install

* Bump to version 1.2.5
2020-05-12 09:46:31 +08:00
Rico Tiongson
7728495350
Improve install permissions (#91)
* Improve install command

* Update README

* Add go+x permissions to C++ program

* Specify group permissions for comfortable-swipe-buffer

* Bump to version 1.2.4
2020-05-12 09:26:44 +08:00
Rico Tiongson
9d25f1cc9f
Update README.md 2020-05-08 01:13:01 +08:00
Rico Tiongson
9deaf2da2c
Specify disabled swipes (#86)
* Configure swipes ok for mouse3/4 = move

* Use filled heavy check mark
2020-05-08 00:03:18 +08:00
Rico Tiongson
6bd7603694 Add more examples to README 2020-05-07 23:44:16 +08:00
Rico Tiongson
57a6e4f217 Fix ordered list in README 2020-05-07 23:39:55 +08:00
Rico Tiongson
404e8febcc Update README 2020-05-07 23:39:00 +08:00
Rico Tiongson
b2d1674ba4 Update README 2020-05-07 23:33:13 +08:00
Rico Tiongson
548199bc38
Improve comfortable-swipe status and trysudo (#85) 2020-05-07 22:39:47 +08:00
Rico Tiongson
cb018bf335
Catch-all for std::invalid_argument for g++<8 (#84) 2020-05-07 21:37:43 +08:00
Rico Tiongson
859d3f3c3c Update README 2020-05-02 03:13:31 +08:00
Rico Tiongson
f56e0a69d3 Fix README install library 2020-05-02 03:01:51 +08:00
6 changed files with 340 additions and 194 deletions

401
README.md
View File

@ -11,7 +11,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
## Installation ## Installation
1. Install git and g++ 1. Install git and g++ &geq; 7.5
```bash ```bash
sudo apt install git g++ sudo apt install git g++
@ -20,7 +20,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
1. Install libinput-tools and C libraries 1. Install libinput-tools and C libraries
```bash ```bash
sudo apt install libinput-tools libconfuse-dev libxdo-dev sudo apt install libinput-tools libinih-dev libxdo-dev
``` ```
1. Clone this repository 1. Clone this repository
@ -48,8 +48,6 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
1. **_Important_**: After inputing your `sudo` password, log out then log back in 1. **_Important_**: After inputing your `sudo` password, log out then log back in
## List of Commands
1. Start the Program 1. Start the Program
``` ```
@ -63,103 +61,111 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
Comfortable swipe is RUNNING in the background Comfortable swipe is RUNNING in the background
``` ```
1. Autostart (this is turned on by default) 1. (Optional) Toggle autostart
```bash ```bash
comfortable-swipe autostart [on|off|toggle|status|path] comfortable-swipe autostart on
``` ```
1. List configurations 1. (Optional) Stop the Program
```
comfortable-swipe stop
```
1. (Optional) See program status
```bash ```bash
If you want to list down configurations, you can run: comfortable-swipe status
```
Example:
```
$ comfortable-swipe status
Autostart is ON
Program is RUNNING
--------------------
Configuration: /home/user/.config/comfortable-swipe.conf
left3 is VALID (ctrl+super+Right)
left4 is VALID (ctrl+super+shift+Right)
right3 is VALID (ctrl+super+Left)
right4 is VALID (ctrl+super+shift+Left)
up3 is VALID (ctrl+F12)
up4 is VALID (super+d)
down3 is VALID (ctrl+F12)
down4 is VALID (super+d)
threshold is VALID (1.0)
mouse3 is NOTSET
mouse4 is NOTSET
```
1. (Optional) Get config
```
comfortable-swipe <PROPERTY>
```
```bash
comfortable-swipe left3
comfortable-swipe left4
comfortable-swipe right3
comfortable-swipe right4
comfortable-swipe up3
comfortable-swipe up4
comfortable-swipe down3
comfortable-swipe down4
comfortable-swipe threshold
comfortable-swipe mouse3
comfortable-swipe mouse4
```
1. (Optional) Set config
```bash
comfortable-swipe <PROPERTY> [=] <VALUES>
```
```bash
comfortable-swipe left3 = super+Right
comfortable-swipe right3 = super+Left
comfortable-swipe right4 = ctrl+alt+Left
comfortable-swipe down4 = super+d
comfortable-swipe up3 = ctrl+shift+Up
```
<details>
<summary><b>Other Commands</b></summary>
1. All Configuration commands
```bash
comfortable-swipe config list comfortable-swipe config list
comfortable-swipe config get <PROPERTY>
Configuration: comfortable-swipe config set <PROPERTY> [=] <VALUE>
comfortable-swipe config path
comfortable-swipe <PROPERTY> gets configuration property comfortable-swipe config keys
comfortable-swipe <PROPERTY> [=] <VALUE> sets configuration to a value
Valid props: left3, left4, right3, right4, up3, up4, down3, down4, threshold, mouse3, mouse4
``` ```
1. Get config (examples) 1. Help and Version
```bash ```bash
$ comfortable-swipe left3 comfortable-swipe --version
ctrl+alt+Right comfortable-swipe --help
$ comfortable-swipe left4
ctrl+alt+shift+Right
$ comfortable-swipe right3
ctrl+alt+Left
$ comfortable-swipe right4
ctrl+alt+shift+Left
$ comfortable-swipe up3
ctrl+alt+Down
$ comfortable-swipe up4
ctrl+alt+shift+Down
$ comfortable-swipe down3
ctrl+alt+Up
$ comfortable-swipe down4
ctrl+alt+shift+Up
$ comfortable-swipe threshold
1.0
``` ```
1. Set config (examples) 1. Autostart commands
```bash ```bash
$ comfortable-swipe left3 = super+Right comfortable-swipe autostart on
left3 = super+Right comfortable-swipe autostart off
comfortable-swipe autostart toggle
$ comfortable-swipe right3 = super+Left comfortable-swipe autostart status
right3 = super+Left comfortable-swipe autostart path
$ comfortable-swipe right4 = super + Left + alt
right4 = super+Left+alt
``` ```
1. Delete config 1. Show output with `--attach`
```bash
$ comfortable-swipe config delete mouse3
Deleted:
mouse3 = button1
```
1. List all cofigurations
```bash
$ comfortable-swipe config list
threshold = 1.0
left4 = ctrl+super+shift+Right
right3 = ctrl+super+Left
right4 = ctrl+super+shift+Left
up3 = ctrl+F12
up4 = super+d
down3 = ctrl+F12
down4 = super+d
mouse4 = button1
left3 = ctrl+super+Right
```
1. Show path to config file:
```bash
$ comfortable-swipe config path
/home/hikari9/.config/comfortable-swipe.conf
```
1. (Advanced) Show output with `--attach`
Example output of 3-finger left, 4-finger left, 3-finger right, 3-finger up: Example output of 3-finger left, 4-finger left, 3-finger right, 3-finger up:
@ -172,24 +178,60 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
... ...
``` ```
You can also pass `--bare` to attach without actually swiping. 1. Test output with `--bare` to attach without actually swiping
## Swipe Gesture Configurations ```bash
$ comfortable-swipe start --bare
SWIPE left3
SWIPE left4
SWIPE right3
SWIPE up3
...
```
1. Debug
```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
...
```
</details>
## Gesture Configurations
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`.
Edit the configuration file by running: Set a property directly with:
```
comfortable-swipe <PROPERTY> [=] <VALUE>
```
Or edit the configuration file manually:
``` ```
gedit ~/.config/comfortable-swipe.conf gedit ~/.config/comfortable-swipe.conf
``` ```
After making changes, make sure to restart the program: After editing, make sure to restart with `comfortable-swipe start`.
```
comfortable-swipe start
```
> **Warning**: For v1.1.0 below, the configuration file is located at > **Warning**: 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`
@ -198,8 +240,8 @@ comfortable-swipe start
## Configuration Reference ## Configuration Reference
| Key | Value | Defaults | | Property | Value | Examples |
| --------- | :--------------------------------------------------------------------: | ----------------------------------------------------------------- | | --------- | :--------------------------------------------------------------------: | ---------------------------------------------------------------------------------- |
| 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 |
| right3 | 3-finger swipe right | ctrl+alt+Left | | right3 | 3-finger swipe right | ctrl+alt+Left |
@ -208,9 +250,9 @@ comfortable-swipe start
| 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 | | threshold | 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 <br> (see [Mouse Gestures](#mouse-gestures-experimental)) | | | mouse3 | mouses a mouse button when 3 fingers are down | button1 / move / scroll<br> _(see [Mouse Gestures](#mouse-gestures-experimental))_ | |
| mouse4 | mouses a mouse button when 4 fingers are down | button1 <br> (see [Mouse Gestures](#mouse-gestures-experimental) | | mouse4 | mouses a mouse button when 4 fingers are down | button1 / move / scroll <br> _(see [Mouse Gestures](#mouse-gestures-experimental)_ |
### Keystrokes ### Keystrokes
@ -230,11 +272,21 @@ Taken from `man xdotool`:
Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use. Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use.
Keyboard shortcuts: - [DEFKEY - All Linux keyboard shortcuts](https://defkey.com/)
- [Unity Keyboard Shortcuts](https://cheatography.com/sapemeg/cheat-sheets/ubuntu-unity-16-04/) - [Unity Keyboard Shortcuts](https://cheatography.com/sapemeg/cheat-sheets/ubuntu-unity-16-04/)
- [GNOME Keyboard Shortcuts](https://wiki.gnome.org/Design/OS/KeyboardShortcuts) - [GNOME Keyboard Shortcuts](https://wiki.gnome.org/Design/OS/KeyboardShortcuts)
- [KDE Keyboard Shortcuts](https://community.linuxmint.com/tutorial/view/47) - [KDE Keyboard Shortcuts](https://community.linuxmint.com/tutorial/view/47)
- [PopOS Keyboard Shortcuts](https://support.system76.com/articles/pop-keyboard-shortcuts/)
## Known Issues: Pop!_OS 20.04+
Pop!_OS 20.04+ may be sensitive to capitalization (#76, #82). Make sure to capitalize every first letter:
```bash
# Pop!_OS
comfortable-swipe up3 = Super+Ctrl+Down
comfortable-swipe down3 = Super+Ctrl+Up
```
## Example Configurations ## Example Configurations
@ -243,92 +295,118 @@ This section includes some example configurations which you can use for your swi
1. Switch workspace (horizontal) 1. Switch workspace (horizontal)
```bash ```bash
comfortable-swipe config set left3 = ctrl+alt+Right # Ubuntu flavors + GNOME
comfortable-swipe config set right3 = ctrl+alt+Left comfortable-swipe left3 = ctrl+alt+Right
comfortable-swipe right3 = ctrl+alt+Left
``` ```
1. Switch workspace (vertical) 1. Switch workspace (vertical)
``` ```bash
up3 = ctrl+alt+Down # Ubuntu flavors + GNOME
down3 = ctrl+alt+Up comfortable-swipe up3 = ctrl+alt+Down
comfortable-swipe down3 = ctrl+alt+Up
``` ```
```bash ```bash
up3 = super+PgDown # GNOME alt.
down3 = super+PgUp comfortable-swipe up3 = super+PgDown
comfortable-swipe down3 = super+PgUp
```
```bash
# Pop OS
comfortable-swipe up3 = Super+Ctrl+Down
comfortable-swipe down3 = Super+Ctrl+Up
``` ```
1. Move window to workspace (horizontal) 1. Move window to workspace (horizontal)
```bash ```bash
left4 = ctrl+alt+shift+Right # Ubuntu flavors + GNOME + Kali
right4 = ctrl+alt+shift+Left comfortable-swipe left4 = ctrl+alt+shift+Right
comfortable-swipe right4 = ctrl+alt+shift+Left
```
```bash
# Elementary OS
comfortable-swipe left4 = super+alt+Right
comfortable-swipe right4 = super+alt+Left
``` ```
1. Move window to workspace (vertical) 1. Move window to workspace (vertical)
```bash ```bash
up4 = ctrl+alt+shift+Down # Ubuntu flavors + GNOME + Kali
down4 = ctrl+alt+shift+Up comfortable-swipe up4 = ctrl+alt+shift+Down
comfortable-swipe down4 = ctrl+alt+shift+Up
``` ```
```bash ```bash
up4 = super+shift+PgDown # GNOME alt.
down4 = super+shift+PgUp comfortable-swipe up4 = super+shift+PgDown
comfortable-swipe down4 = super+shift+PgUp
``` ```
1. Move window to other monitor 1. Move window to other monitor
```bash ```bash
left4 = super+shift+Right # Ubuntu flavors + GNOME
right4 = super+shift+Left comfortable-swipe left4 = super+shift+Right
comfortable-swipe right4 = super+shift+Left
``` ```
1. Toggle workspace overview 1. Toggle workspace overview
```bash ```bash
up3 = super+s # Ubuntu flavors + Elementary OS
comfortable-swipe up3 = super+s
```
```bash
# Elementary OS (all workspaces)
comfortable-swipe up4 = super+a
``` ```
1. Show desktop 1. Show desktop
```bash ```bash
down3 = super+d # Ubuntu flavors
comfortable-swipe down3 = ctrl+super+d
``` ```
```bash ```bash
down3 = ctrl+super+d # Linux Mint
comfortable-swipe down3 = super+d
``` ```
```bash ```bash
down3 = ctrl+alt+d # Kali
comfortable-swipe down3 = ctrl+alt+d
```
```bash
# KDE
comfortable-swipe down3 = ctrl+F12
``` ```
1. Snap windows to the left/right 1. Snap windows to the left/right
```bash ```bash
left3 = super+Left comfortable-swipe left3 = super+Left
right3 = super+Right comfortable-swipe right3 = super+Right
``` ```
1. Toggle maximize 1. Toggle maximize
```bash ```bash
up3 = super+Up comfortable-swipe up3 = super+Up
``` ```
1. Toggle minimize 1. Toggle minimize
```bash ```bash
down3 = super+Down comfortable-swipe down3 = super+Down
```
1. Alt+Tab switch application (experimental)
```bash
left3 = alt+Tab
right3 = alt+shift+Tab
``` ```
## Mouse Gestures (Experimental) ## Mouse Gestures (Experimental)
@ -354,46 +432,49 @@ Possible Values:
- 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)
> **Tip**: You can clear mouse gestures by setting them blank
>
> ```
> comfortable-swipe mouse3 =
> comfortable-swipe mouse4 =
> ```
Examples: Examples:
- 3/4-finger drag ✔️ swipes OK
```bash ⭕ swipes DISABLED
mouse3 = button1
``` - 3/4-finger drag ⭕
```bash
mouse4 = button1
```
- 3/4-finger natural scroll
```bash ```bash
mouse3 = scroll comfortable-swipe mouse3 = button1
comfortable-swipe mouse4 = button1
``` ```
You can also use `button2` for middle click and `button3` for right click.
- 3/4-finger natural scroll ⭕
```bash ```bash
mouse4 = scroll comfortable-swipe mouse3 = scroll
comfortable-swipe mouse4 = scroll
``` ```
- 3/4-finger reverse scroll - 3/4-finger reverse scroll
```bash ```bash
mouse3 = scroll_reverse comfortable-swipe mouse3 = scroll_reverse
comfortable-swipe mouse4 = scroll_reverse
``` ```
- Move 3/4-fingers with the cursor ✔️
```bash ```bash
mouse4 = scroll_reverse comfortable-swipe mouse3 = move
comfortable-swipe mouse4 = move
``` ```
- Move 3/4-fingers with the cursor > **Warning**: Some mouse configuration will **disable up/left/right/down behavior** to avoid gesture conflicts. The logic of this will be improved in the future.
```bash
mouse3 = move
```
```bash
mouse4 = move
```
**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
@ -436,13 +517,13 @@ If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supp
For the following reasons: For the following reasons:
1. We want prioritize "comfort" over functionality, which we deliver through performance in our near-zero-overhead implementation (that's why C++) 1. We want prioritize "comfort" over functionality, which we deliver through performance in our negligible-overhead implementation (that's why C++)
2. Running a new shell command with unpredictable process time will break our unthreaded optimizations (unlike native keystrokes) 1. There are other gesture libraries that already do this properly (eg. [libinput gestures](https://github.com/bulletmark/libinput-gestures), [Fusuma](https://github.com/iberianpig/fusuma)), we don't want to be a clone of them
3. There are other gesture libraries that already do this properly (eg. [libinput gestures](https://github.com/bulletmark/libinput-gestures), [Fusuma](https://github.com/iberianpig/fusuma)), we don't want to be a clone of them 1. Running a new shell command with unpredictable process time will break our unthreaded optimizations (unlike native keystrokes)
That's why it's not possible... That's why it's not possible... or not?
**Answer 2**: _... but actually **YES**!_ **Answer 2**: _... but actually **IT'S POSSIBLE**!_
Although we don't provide this out of the box in our config, this can definitely be Although we don't provide this out of the box in our config, this can definitely be
done with the default bash tools. done with the default bash tools.
@ -452,7 +533,9 @@ done with the default bash tools.
Running shell commands our **NOT** part of the core features of comfortable-swipe, Running shell commands our **NOT** part of the core features of comfortable-swipe,
but through the default bash tools you can _mimic_ this functionality via our program output. but through the default bash tools you can _mimic_ this functionality via our program output.
**Use Case**: _"I want to run `gnome-terminal` if I swipe up with 3 fingers."_ <details>
<summary> <b>Use Case</b>: <i>"I want to run <code>gnome-terminal</code> if I swipe up with 3 fingers."</i>
</summary>
1. Attach the program to the shell: 1. Attach the program to the shell:
@ -554,6 +637,8 @@ but through the default bash tools you can _mimic_ this functionality via our pr
Substitute `<COMMAND>` with the shell command of your choice. Substitute `<COMMAND>` with the shell command of your choice.
</details>
## Uninstall ## Uninstall
Run the following script: Run the following script:

View File

@ -1 +1 @@
v1.2.0 v1.2.5

View File

@ -115,7 +115,7 @@ function start {
debug | buffer $@ debug | buffer $@
else else
# detach buffered output # detach buffered output
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 & nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 & disown
echo "Comfortable swipe is RUNNING in the background" echo "Comfortable swipe is RUNNING in the background"
fi fi
} }
@ -173,15 +173,53 @@ function buffer {
########## ##########
function _program_running {
pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1
}
# verbosely show comfortable-swipe status # verbosely show comfortable-swipe status
function status { function status {
# TODO: show configuration status as well # show autostart status
echo "Autostart is $("$BASENAME" autostart status)" echo "Autostart is $("$BASENAME" autostart status)"
if pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1; then # show program status
if _program_running; then
echo "Program is RUNNING" echo "Program is RUNNING"
else else
echo "Program is STOPPED" echo "Program is STOPPED"
fi fi
# show configuration status
echo --------------------
echo "Configuration: $(config path)"
mouse3="$(config get mouse3)"
mouse4="$(config get mouse4)"
for key in $(config keys); do
value="$(config get "$key")"
if [[ -z "$value" ]]; then
vstatus="NOTSET"
else
vstatus="VALID"
if [[ "$key" != mouse* ]]; then
if [[ "$key" == *3 && -n "$mouse3" && "$mouse3" != move ]]; then
vstatus="DISABLED"
elif [[ "$key" == *4 && -n "$mouse4" && "$mouse4" != move ]]; then
vstatus="DISABLED"
fi
fi
if [[ "$key" == threshold ]]; then
if ! [[ "$value" =~ ^[+-]?[0-9]+\.?[0-9]*$ ]]; then
# not a float
vstatus="INVALID"
fi
fi
fi
echo "$key $vstatus" | awk '{printf "%9s is %7s", $1, $2}'
if [[ ! -z "$value" ]]; then
echo " ($value)"
else
echo
fi
done
} }
@ -291,8 +329,7 @@ function config {
local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")" local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")"
echo "$RESULT" > "$CONFIG" echo "$RESULT" > "$CONFIG"
# restart comfortable-swipe if it is running # restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then if _program_running; then
stop > /dev/null 2>&1
start > /dev/null start > /dev/null
fi fi
fi fi
@ -378,8 +415,7 @@ function config {
# show newly set value # show newly set value
echo "$KEY = $(get "$KEY")" echo "$KEY = $(get "$KEY")"
# restart comfortable-swipe if it is running # restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then if _program_running; then
stop > /dev/null 2>&1
start > /dev/null start > /dev/null
fi fi
} }
@ -451,7 +487,7 @@ function autostart {
##################################### #####################################
# toggle to opposite autostart status # toggle to opposite autostart status
function toggle { function toggle {
[[ $(status) = ON ]] && off || on [[ $(status) == ON ]] && off || on
} }
###################### ######################
@ -495,9 +531,9 @@ else
# try to invoke config set / get depending on number of arguments # try to invoke config set / get depending on number of arguments
if [[ $# -eq 1 ]]; then if [[ $# -eq 1 ]]; then
# one argument, use shorthand get # one argument, use shorthand get
"$BASENAME" config get "$1" || abort config get "$1" || abort
else else
# multiple arguments, use shorthand set # multiple arguments, use shorthand set
"$BASENAME" config set "$@" 2> /dev/null || abort config set "$@" 2> /dev/null || abort
fi fi
fi fi

View File

@ -134,7 +134,7 @@ void gesture_swipe_xdokey::update() {
gesture_swipe::update(); gesture_swipe::update();
// scale threshold to 1/10 when gesture is fresh // scale threshold to 1/10 when gesture is fresh
// acts like our static friction coefficient // acts like our static friction coefficient
float scale = get_previous_gesture() == FRESH ? 0.01f : 1.0f; const float scale = get_previous_gesture() == FRESH ? 0.01f : 1.0f;
// we are working with floating points which are not exact // we are working with floating points which are not exact
// make sure we compare with a very small value (1e-6f) // make sure we compare with a very small value (1e-6f)
// if distance goes out of threshold, perform our swipe // if distance goes out of threshold, perform our swipe

View File

@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
float threshold = 0.0f; float threshold = 0.0f;
try { try {
threshold = stof(config["threshold"]); threshold = stof(config["threshold"]);
} catch (std::invalid_argument) { } catch (...) {
} }
// create swipe handler // create swipe handler
gesture_swipe_xdokey keyswipe(commands, threshold); gesture_swipe_xdokey keyswipe(commands, threshold);
@ -112,10 +112,14 @@ int main(int argc, char *argv[]) {
// get input values // get input values
string mouse3 = config.count("mouse3") ? config["mouse3"] : config["hold3"]; string mouse3 = config.count("mouse3") ? config["mouse3"] : config["hold3"];
string mouse4 = config.count("mouse4") ? config["mouse4"] : config["hold4"]; string mouse4 = config.count("mouse4") ? config["mouse4"] : config["hold4"];
bool nomouse = mouse3.empty() || mouse4.empty(); // TODO: check if mouse invalid
// create our mouse gesture holder // create our mouse gesture holder
gesture_swipe_xdomouse mousehold(mouse3.data(), mouse4.data()); gesture_swipe_xdomouse mousehold(mouse3.data(), mouse4.data());
// start reading lines from input one by one // start reading lines from input one by one
for (string line; getline(cin, line);) { for (string line; getline(cin, line);) {
if (nomouse) {
keyswipe.run(line.data());
} else {
// optimization: if no mouse config is set, just run keyboard // optimization: if no mouse config is set, just run keyboard
if (mousehold.is_swiping() && mousehold.button == MOUSE_NONE) { if (mousehold.is_swiping() && mousehold.button == MOUSE_NONE) {
keyswipe.run(line.data()); keyswipe.run(line.data());
@ -126,6 +130,7 @@ int main(int argc, char *argv[]) {
} }
} }
} }
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

58
install
View File

@ -2,6 +2,11 @@
set -e set -e
if [[ "$USER" == root ]]; then
echo "Please run 'bash install' as non-root user" 2>&1
exit 1
fi
DIR="$(dirname "$0")" DIR="$(dirname "$0")"
VERSION="$(cat $DIR/VERSION | tr -d '[:space:]')" VERSION="$(cat $DIR/VERSION | tr -d '[:space:]')"
@ -29,7 +34,7 @@ comfortable-swipe stop > /dev/null 2>&1 || true
# shorthand to abort the installation # shorthand to abort the installation
function abort { function abort {
echo "Installation aborted" echo "Installation aborted" >&2
exit 1 exit 1
} }
@ -62,14 +67,23 @@ function install_configuration_file {
# ask user if we overwrite configuration # ask user if we overwrite configuration
echo "Old conf file found in $CONF_TARGET" >&2 echo "Old conf file found in $CONF_TARGET" >&2
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response >&2 read -r -p "Keep the old conf file? (default: yes) [Y/n] " response >&2
if ! [[ "${response,,}" =~ ^(yes|y)$ ]]; then
# If response is empty, consider it as 'yes' (default)
if [[ -z "$response" ]]; then
response="y"
fi
if [[ "${response,,}" =~ ^(no|n)$ ]]; then
# MAKE SURE they really want to overwrite # MAKE SURE they really want to overwrite
read -r -p "Conf file will be overwritten! Are you sure? [Y/n] " response >&2 read -r -p "Conf file will be overwritten! Are you sure? [Y/n] " response >&2
if [[ "${response,,}" =~ ^(yes|y)$ ]]; then if [[ -z "$response" ]]; then
response="y"
fi
if [[ "${response,,}" =~ ^(no|n)$ ]]; then
abort
else
# They agreed... replace configuration # They agreed... replace configuration
cat "$CONF_SOURCE" > "$CONF_TARGET" cat "$CONF_SOURCE" > "$CONF_TARGET"
else
abort
fi fi
fi fi
else else
@ -97,14 +111,16 @@ function install_configuration_file {
# #
function install_main_program { function install_main_program {
# copy source to target with executable permissions # copy source to target with executable permissions
TRYSUDO=
if ! touch "$TARGET" 2> /dev/null; then
TRYSUDO=sudo
fi
# install to target, with hardcoded version # install to target, with hardcoded version
$TRYSUDO sed -E "s/^VERSION=.*/VERSION=$VERSION/" "$SOURCE" > "$TARGET" if [[ -f "$TARGET" ]]; then
# allow execute permissions trysudo rm "$TARGET"
$TRYSUDO chmod +x "$TARGET" fi
trysudo cp "$SOURCE" "$TARGET"
trysudo sed -E "s/^VERSION=.*/VERSION=$VERSION/" -i "$TARGET"
# allow execute permissions with group
trysudo chmod +x "$TARGET"
# make sure non-root user is owner
trysudo chown "$USER" "$TARGET"
echo "Installed: $TARGET" echo "Installed: $TARGET"
} }
@ -118,14 +134,17 @@ function install_cpp_program {
# compile program to temporary file first # compile program to temporary file first
TMP_TARGET="$(mktemp)" TMP_TARGET="$(mktemp)"
$COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\"" $COMPILE "$COMPILE_SOURCE" -o "$TMP_TARGET" -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\"" -DCOMFORTABLE_SWIPE_CONFIG="\"$CONF_TARGET\"" -DCOMFORTABLE_SWIPE_AUTOSTART="\"$AUTOSTART_TARGET\""
# compilation ok, now try to install # compilation ok, now try to install with sudo
# eheck permissions maybe if will need sudo trysudo mkdir -p "$(dirname "$COMPILE_TARGET")"
TRYSUDO= # remove existing file for permissions to work
if ! touch "$COMPILE_TARGET" 2> /dev/null; then if [[ -f "$COMPILE_TARGET" ]]; then
TRYSUDO=sudo sudo rm "$COMPILE_TARGET"
fi fi
# move executable to target trysudo mv "$TMP_TARGET" "$COMPILE_TARGET"
$TRYSUDO mv "$TMP_TARGET" "$COMPILE_TARGET" # bugfix: add with group permissions
trysudo chmod go+x "$COMPILE_TARGET"
# make sure non-root user is owner
trysudo chown "$USER" "$COMPILE_TARGET"
echo "Installed: $COMPILE_TARGET" echo "Installed: $COMPILE_TARGET"
} }
@ -136,6 +155,7 @@ function install_cpp_program {
# /home/$USER/.config/autostart/comfortable-swipe.desktop # /home/$USER/.config/autostart/comfortable-swipe.desktop
# #
function install_autostart { function install_autostart {
mkdir -p "$(dirname "$AUTOSTART_TARGET")"
cat "$AUTOSTART_SOURCE" > "$AUTOSTART_TARGET" cat "$AUTOSTART_SOURCE" > "$AUTOSTART_TARGET"
echo "Installed: $AUTOSTART_TARGET" echo "Installed: $AUTOSTART_TARGET"
} }