Compare commits
62 Commits
v1.0-local
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc117c0ab5 | ||
|
|
4cf3bf3d8d | ||
|
|
9393a96d3f | ||
|
|
179083a152 | ||
|
|
99f659c9db | ||
|
|
7728495350 | ||
|
|
9d25f1cc9f | ||
|
|
9deaf2da2c | ||
|
|
6bd7603694 | ||
|
|
57a6e4f217 | ||
|
|
404e8febcc | ||
|
|
b2d1674ba4 | ||
|
|
548199bc38 | ||
|
|
cb018bf335 | ||
|
|
859d3f3c3c | ||
|
|
f56e0a69d3 | ||
|
|
66b2568c86 | ||
|
|
d8788782a8 | ||
|
|
217e507dce | ||
|
|
b796cb02df | ||
|
|
f2f68a97cc | ||
|
|
cd29704495 | ||
|
|
6a6bbf52e9 | ||
|
|
cb51d47a60 | ||
|
|
1ecfc79fc4 | ||
|
|
92863711b0 | ||
|
|
a7c5b6d578 | ||
|
|
8f6e231a5e | ||
|
|
dda91b7178 | ||
|
|
4852993663 | ||
|
|
810a20f1ed | ||
|
|
28f5ca2a91 | ||
|
|
89b79bc9bc | ||
|
|
7d76db6693 | ||
|
|
204a422f2d | ||
|
|
c18cb04230 | ||
|
|
b1f8a7cb0a | ||
|
|
1c9b497b56 | ||
|
|
16742495eb | ||
|
|
459fd68ba8 | ||
|
|
7923effa02 | ||
|
|
602b148fb4 | ||
|
|
68bea125e3 | ||
|
|
0b3b3238af | ||
|
|
3a0e1361c9 | ||
|
|
b5c701994b | ||
|
|
30e4a57b62 | ||
|
|
f3909f85f2 | ||
|
|
1071979b83 | ||
|
|
f40145b6fa | ||
|
|
b171fb2cdf | ||
|
|
e2e534ea2f | ||
|
|
e3453c1bbb | ||
|
|
328ae08ee1 | ||
|
|
2843b9d3ce | ||
|
|
4795a68600 | ||
|
|
8d4756f7d2 | ||
|
|
22b9869ae8 | ||
|
|
0de8777d87 | ||
|
|
91b55bad5e | ||
|
|
90246cd7d3 | ||
|
|
a394e905ba |
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# C++ generated headers
|
||||||
|
*.gch
|
||||||
|
*.o
|
||||||
|
|
||||||
|
# IDE-specific
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
42
CHANGELOG
Normal file
42
CHANGELOG
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
v1.2.0 (2020-04-20)
|
||||||
|
* Simplified source files
|
||||||
|
* Add `config get|set|list|delete` to command line
|
||||||
|
* Add specific autostart toggles
|
||||||
|
* Use clang-format and prettier for formatting
|
||||||
|
* Add `--bare` and `--attach` flags to buffer
|
||||||
|
* Remove `restart` and integrated single-instance to `start`
|
||||||
|
* Provide separate `comfortable-swipe-buffer` program
|
||||||
|
* Improve README
|
||||||
|
|
||||||
|
v1.1.0 (2020-04-18)
|
||||||
|
* Add mouse hold gestures
|
||||||
|
* Add experimental `hold3` configuration
|
||||||
|
* Add experimental `hold4` configuration
|
||||||
|
* Add linker tests
|
||||||
|
* Add `driver.cpp`
|
||||||
|
* Add `mouse_hold_gestures.cpp`
|
||||||
|
* Bugfix `comfortable-swipe stop`
|
||||||
|
* Bugfix `comfortable-swipe restart`
|
||||||
|
* Rename `index.hpp` to `all_headers.hpp`
|
||||||
|
* Rename source directory `lib` to `comfortable_swipe`
|
||||||
|
* Separate `swipe_gesture.cpp` from `keyboard_swipe_gesture.cpp`
|
||||||
|
* Update compiler scripts
|
||||||
|
* Update configurations
|
||||||
|
* Update README
|
||||||
|
* Bump to version 1.1.0
|
||||||
|
|
||||||
|
v1.0.4
|
||||||
|
* Bugfixes
|
||||||
|
|
||||||
|
v1.0.3
|
||||||
|
* Bugfixes
|
||||||
|
|
||||||
|
v1.0.2
|
||||||
|
* Change directory structure
|
||||||
|
* Bugfixes
|
||||||
|
|
||||||
|
v1.0.1
|
||||||
|
* Bugfixes
|
||||||
|
|
||||||
|
v1.0.0
|
||||||
|
* Initial version
|
||||||
694
README.md
694
README.md
@ -1,68 +1,666 @@
|
|||||||
# Comfortable Swipe (Ubuntu)
|
# Comfortable Swipe (Ubuntu)
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
|
||||||
|
[](https://github.com/Hikari9/comfortable-swipe/releases)
|
||||||
|
[](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`.
|
||||||
|
|
||||||
|
> **_New in Version 1.1.0_**: Added mouse gestures, see [#mouse-gestures-experimental](#mouse-gestures-experimental)
|
||||||
|
|
||||||
|
> **_New in Version 1.2.0_**: Autostart now switched ON by default
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Install `libinput-tools` and `libxdo-dev`
|
1. Install git and g++ ≥ 7.5
|
||||||
|
|
||||||
```bash
|
|
||||||
sudo apt-get install libinput-tools libxdo-dev
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Clone this repository
|
```bash
|
||||||
|
sudo apt install git g++
|
||||||
```bash
|
```
|
||||||
git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git
|
|
||||||
cd comfortable-swipe-ubuntu
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Install
|
1. Install libinput-tools and C libraries
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bash install
|
sudo apt install libinput-tools libinih-dev libxdo-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
4. You may delete the downloaded `comfortable-swipe-ubuntu` folder after installation.
|
1. Clone this repository
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git clone https://github.com/Hikari9/comfortable-swipe.git --depth 1
|
||||||
|
cd comfortable-swipe
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash install
|
||||||
|
```
|
||||||
|
|
||||||
|
1. You may delete the downloaded `comfortable-swipe` folder after installation.
|
||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
1. You'll need some group permissions to read touchpad input data. Run
|
1. You'll need some group permissions to read touchpad input data. Run
|
||||||
```bash
|
|
||||||
sudo gpasswd -a $USER $(ls -l /dev/input/event* | awk '{print $4}' | head --line=1)
|
|
||||||
```
|
|
||||||
2. ***Important***: After inputing your `sudo` password, log out then log back in
|
|
||||||
3. Run
|
|
||||||
```
|
|
||||||
comfortable-swipe start
|
|
||||||
```
|
|
||||||
4. _Optional_: Automatically run on startup
|
|
||||||
```
|
|
||||||
comfortable-swipe autostart
|
|
||||||
```
|
|
||||||
5. _Optional_: Change keyboard [configurations](#configurations). After making changes, run
|
|
||||||
```
|
|
||||||
comfortable-swipe restart
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configurations
|
```bash
|
||||||
Comfortable swipe makes use of keyboard shortcuts for configurations. The configuration file is located at `/usr/share/comfortable-swipe/comfortable-swipe.conf`. Make sure to run `comfortable-swipe restart` after making changes.
|
sudo gpasswd -a "$USER" "$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1)"
|
||||||
|
```
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
1. **_Important_**: After inputing your `sudo` password, log out then log back in
|
||||||
--------- | ----------- | -------------- | -----
|
|
||||||
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point | 0.0
|
1. Start the Program
|
||||||
left3 | 3-finger swipe left | ctrl+shift+Right | switch 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
|
comfortable-swipe start
|
||||||
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
|
|
||||||
up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace
|
You will see this output:
|
||||||
down3 | 3-finger swipe down | ctrl+shift+Down | switch to above workspace
|
|
||||||
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
```
|
||||||
|
$ comfortable-swipe start
|
||||||
|
Comfortable swipe is RUNNING in the background
|
||||||
|
```
|
||||||
|
|
||||||
|
1. (Optional) Toggle autostart
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe autostart on
|
||||||
|
```
|
||||||
|
|
||||||
|
1. (Optional) Stop the Program
|
||||||
|
|
||||||
|
```
|
||||||
|
comfortable-swipe stop
|
||||||
|
```
|
||||||
|
|
||||||
|
1. (Optional) See program status
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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 get <PROPERTY>
|
||||||
|
comfortable-swipe config set <PROPERTY> [=] <VALUE>
|
||||||
|
comfortable-swipe config path
|
||||||
|
comfortable-swipe config keys
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Help and Version
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe --version
|
||||||
|
comfortable-swipe --help
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Autostart commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe autostart on
|
||||||
|
comfortable-swipe autostart off
|
||||||
|
comfortable-swipe autostart toggle
|
||||||
|
comfortable-swipe autostart status
|
||||||
|
comfortable-swipe autostart path
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Show output with `--attach`
|
||||||
|
|
||||||
|
Example output of 3-finger left, 4-finger left, 3-finger right, 3-finger up:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ comfortable-swipe start --attach
|
||||||
|
SWIPE left3
|
||||||
|
SWIPE left4
|
||||||
|
SWIPE right3
|
||||||
|
SWIPE up3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Test output with `--bare` to attach without actually swiping
|
||||||
|
|
||||||
|
```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`.
|
||||||
|
Comfortable swipe makes use of **keyboard shortcuts** to perform swipes, through `xdotool`.
|
||||||
|
|
||||||
|
Set a property directly with:
|
||||||
|
|
||||||
|
```
|
||||||
|
comfortable-swipe <PROPERTY> [=] <VALUE>
|
||||||
|
```
|
||||||
|
|
||||||
|
Or edit the configuration file manually:
|
||||||
|
|
||||||
|
```
|
||||||
|
gedit ~/.config/comfortable-swipe.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
After editing, make sure to restart with `comfortable-swipe start`.
|
||||||
|
|
||||||
|
> **Warning**: For v1.1.0 below, the configuration file is located at
|
||||||
|
> `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`
|
||||||
|
|
||||||
|
> **Note**: You can locate the absolute path to your configuration by running: `comfortable-swipe config path`
|
||||||
|
|
||||||
|
## Configuration Reference
|
||||||
|
|
||||||
|
| Property | Value | Examples |
|
||||||
|
| --------- | :--------------------------------------------------------------------: | ---------------------------------------------------------------------------------- |
|
||||||
|
| left3 | 3-finger swipe left | ctrl+alt+Right |
|
||||||
|
| left4 | 4-finger swipe left | ctrl+alt+shift+Right |
|
||||||
|
| right3 | 3-finger swipe right | ctrl+alt+Left |
|
||||||
|
| right4 | 4-finger swipe right | ctrl+alt+shift+Left |
|
||||||
|
| up3 | 3-finger swipe up | ctrl+alt+Down |
|
||||||
|
| 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 | 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 / move / scroll <br> _(see [Mouse Gestures](#mouse-gestures-experimental)_ |
|
||||||
|
|
||||||
|
### Keystrokes
|
||||||
|
|
||||||
|
Taken from `man xdotool`:
|
||||||
|
|
||||||
|
> Type a given keystroke. Examples being "alt+r", "Control_L+J",
|
||||||
|
> "ctrl+alt+n", "BackSpace".
|
||||||
|
>
|
||||||
|
> Generally, any valid X Keysym string will work. Multiple keys are
|
||||||
|
> separated by '+'. Aliases exist for "alt", "ctrl", "shift",
|
||||||
|
> "super", and "meta" which all map to Foo_L, such as Alt_L and
|
||||||
|
> Control_L, etc.
|
||||||
|
>
|
||||||
|
> In cases where your keyboard doesn't actually have the key you want
|
||||||
|
> to type, xdotool will automatically find an unused keycode and use
|
||||||
|
> that to type the key.
|
||||||
|
|
||||||
|
Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use.
|
||||||
|
|
||||||
|
- [DEFKEY - All Linux keyboard shortcuts](https://defkey.com/)
|
||||||
|
- [Unity Keyboard Shortcuts](https://cheatography.com/sapemeg/cheat-sheets/ubuntu-unity-16-04/)
|
||||||
|
- [GNOME Keyboard Shortcuts](https://wiki.gnome.org/Design/OS/KeyboardShortcuts)
|
||||||
|
- [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
|
||||||
|
|
||||||
|
This section includes some example configurations which you can use for your swipe experience.
|
||||||
|
|
||||||
|
1. Switch workspace (horizontal)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + GNOME
|
||||||
|
comfortable-swipe left3 = ctrl+alt+Right
|
||||||
|
comfortable-swipe right3 = ctrl+alt+Left
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Switch workspace (vertical)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + GNOME
|
||||||
|
comfortable-swipe up3 = ctrl+alt+Down
|
||||||
|
comfortable-swipe down3 = ctrl+alt+Up
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GNOME alt.
|
||||||
|
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)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + GNOME + Kali
|
||||||
|
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)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + GNOME + Kali
|
||||||
|
comfortable-swipe up4 = ctrl+alt+shift+Down
|
||||||
|
comfortable-swipe down4 = ctrl+alt+shift+Up
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GNOME alt.
|
||||||
|
comfortable-swipe up4 = super+shift+PgDown
|
||||||
|
comfortable-swipe down4 = super+shift+PgUp
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Move window to other monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + GNOME
|
||||||
|
comfortable-swipe left4 = super+shift+Right
|
||||||
|
comfortable-swipe right4 = super+shift+Left
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle workspace overview
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors + Elementary OS
|
||||||
|
comfortable-swipe up3 = super+s
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Elementary OS (all workspaces)
|
||||||
|
comfortable-swipe up4 = super+a
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Show desktop
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu flavors
|
||||||
|
comfortable-swipe down3 = ctrl+super+d
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Linux Mint
|
||||||
|
comfortable-swipe down3 = super+d
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Kali
|
||||||
|
comfortable-swipe down3 = ctrl+alt+d
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# KDE
|
||||||
|
comfortable-swipe down3 = ctrl+F12
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Snap windows to the left/right
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe left3 = super+Left
|
||||||
|
comfortable-swipe right3 = super+Right
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle maximize
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe up3 = super+Up
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle minimize
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe down3 = super+Down
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mouse Gestures (Experimental)
|
||||||
|
|
||||||
|
You can also play around with mouse gestures during swipe.
|
||||||
|
This enables certain mouse behaviour to trigger along with a 3/4-finger swipe.
|
||||||
|
|
||||||
|
Keys:
|
||||||
|
|
||||||
|
- mouse3 - for 3-finger mouse gestures
|
||||||
|
- mouse4 - for 4-finger mosue gestures
|
||||||
|
- hold3 (deprecated) - old equivalent of mouse3
|
||||||
|
- hold4 (deprecated) - old equivalent of mouse4
|
||||||
|
|
||||||
|
Possible Values:
|
||||||
|
|
||||||
|
- 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)
|
||||||
|
|
||||||
|
> **Tip**: You can clear mouse gestures by setting them blank
|
||||||
|
>
|
||||||
|
> ```
|
||||||
|
> comfortable-swipe mouse3 =
|
||||||
|
> comfortable-swipe mouse4 =
|
||||||
|
> ```
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
✔️ swipes OK
|
||||||
|
⭕ swipes DISABLED
|
||||||
|
|
||||||
|
- 3/4-finger drag ⭕
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
comfortable-swipe mouse3 = scroll
|
||||||
|
comfortable-swipe mouse4 = scroll
|
||||||
|
```
|
||||||
|
|
||||||
|
- 3/4-finger reverse scroll ⭕
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe mouse3 = scroll_reverse
|
||||||
|
comfortable-swipe mouse4 = scroll_reverse
|
||||||
|
```
|
||||||
|
|
||||||
|
- Move 3/4-fingers with the cursor ✔️
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe mouse3 = move
|
||||||
|
comfortable-swipe mouse4 = move
|
||||||
|
```
|
||||||
|
|
||||||
|
> **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.
|
||||||
|
|
||||||
|
## Debugging
|
||||||
|
|
||||||
|
You can check your touchpad driver by running
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe debug
|
||||||
|
```
|
||||||
|
|
||||||
|
This is an alias of `libinput debug-events`. This logs all gestures you make on your touchpad, along with other input-based events that can be captured by libinput.
|
||||||
|
|
||||||
|
A working swipe gesture will show the following:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ comfortable-swipe debug
|
||||||
|
...
|
||||||
|
-event9 DEVICE_ADDED TouchPad seat0 default group7 cap:pg size 70x50mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on
|
||||||
|
...
|
||||||
|
event9 GESTURE_SWIPE_BEGIN +2.03s 3
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.03s 3 -9.95/ 2.64 (-26.90/ 7.12 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.03s 3 -10.44/ 3.19 (-28.22/ 8.62 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.04s 3 -9.71/ 2.64 (-26.25/ 7.12 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.05s 3 -8.98/ 2.64 (-24.28/ 7.12 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.06s 3 -7.40/ 2.36 (-20.01/ 6.37 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.06s 3 -6.31/ 2.50 (-17.06/ 6.75 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.07s 3 -5.34/ 1.80 (-14.44/ 4.87 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.08s 3 -4.61/ 2.08 (-12.47/ 5.62 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.09s 3 -4.49/ 1.53 (-12.14/ 4.12 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.09s 3 -4.01/ 1.25 (-10.83/ 3.37 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_UPDATE +2.10s 3 -4.13/ 0.42 (-11.15/ 1.12 unaccelerated)
|
||||||
|
event9 GESTURE_SWIPE_END +2.11s 3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supports multi-touch swipe gestures.
|
||||||
|
|
||||||
|
## FAQ: Can I run a _shell command_ instead of a keystroke?
|
||||||
|
|
||||||
|
**Answer 1**: _Unfortunately **NO**..._
|
||||||
|
|
||||||
|
For the following reasons:
|
||||||
|
|
||||||
|
1. We want prioritize "comfort" over functionality, which we deliver through performance in our negligible-overhead implementation (that's why C++)
|
||||||
|
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
|
||||||
|
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... or not?
|
||||||
|
|
||||||
|
**Answer 2**: _... but actually **IT'S POSSIBLE**!_
|
||||||
|
|
||||||
|
Although we don't provide this out of the box in our config, this can definitely be
|
||||||
|
done with the default bash tools.
|
||||||
|
|
||||||
|
## Hack: Shell command on 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.
|
||||||
|
|
||||||
|
<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:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe start --attach
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify it outputs when you swipe left, left, up, right, up with 3 fingers:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ comfortable-swipe start --attach
|
||||||
|
SWIPE left3
|
||||||
|
SWIPE left3
|
||||||
|
SWIPE up3
|
||||||
|
SWIPE right3
|
||||||
|
SWIPE up3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Filter out the wanted gesture with `grep`.
|
||||||
|
|
||||||
|
In our case, we want 3-finger swipe up which is "SWIPE up3":
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ comfortable-swipe start --attach | grep --line-buffered "SWIPE up3"
|
||||||
|
SWIPE up3
|
||||||
|
SWIPE up3
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note**: The flag `--line-buffered` ensures the output prints line-by-line.
|
||||||
|
|
||||||
|
1. Now we can execute our shell command with `xargs`.
|
||||||
|
|
||||||
|
So if we want "SWIPE up3" to open the terminal,
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe start --attach | grep "SWIPE up3" --line-buffered | xargs -I@ gnome-terminal
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note**: The flag `-I@` in xargs substitutes the line "SWIPE xxx" to the charatcter "@", which you can use for your program.
|
||||||
|
|
||||||
|
1. _Bonus_: Add to autostart
|
||||||
|
|
||||||
|
Open our autostart file:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
gedit "$(comfortable-swipe autostart path)"
|
||||||
|
```
|
||||||
|
|
||||||
|
Tweak the `Exec` section:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Exec=comfortable-swipe start
|
||||||
|
Name=Comfortable Swipe
|
||||||
|
Comment=Comfortable 3/4-finger touchpad gestures
|
||||||
|
Hidden=false
|
||||||
|
NoDisplay=false
|
||||||
|
X-GNOME-Autostart-enabled=true
|
||||||
|
```
|
||||||
|
|
||||||
|
To:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Exec=comfortable-swipe start --attach | grep "SWIPE up3" --line-buffered | xargs -I@ gnome-terminal
|
||||||
|
Name=Comfortable Swipe
|
||||||
|
Comment=Comfortable 3/4-finger touchpad gestures
|
||||||
|
Hidden=false
|
||||||
|
NoDisplay=false
|
||||||
|
X-GNOME-Autostart-enabled=true
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Log out and log back in.
|
||||||
|
You should now be able to run your custom shell commands on startup.
|
||||||
|
|
||||||
|
1. _Bonus_: Use `--bare` instead of `--attach` to NOT run keystrokes while swiping
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe start --bare | grep "SWIPE up3" --line-buffered | xargs -I@ gnome-terminal
|
||||||
|
```
|
||||||
|
|
||||||
|
1. _Bonus_: You can pipe multiple gestures with `tee`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
comfortable-swipe start --attach | \
|
||||||
|
tee >(grep "SWIPE left3" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE left4" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE right3" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE right4" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE up3" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE up4" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE down3" --line-buffered | xargs -I@ <COMMAND>) | \
|
||||||
|
tee >(grep "SWIPE down4" --line-buffered | xargs -I@ <COMMAND>)
|
||||||
|
```
|
||||||
|
|
||||||
|
Substitute `<COMMAND>` with the shell command of your choice.
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
## Uninstall
|
## Uninstall
|
||||||
Download the `uninstall` script then run `bash uninstall`
|
|
||||||
|
Run the following script:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wget -qO - https://raw.githubusercontent.com/Hikari9/comfortable-swipe/master/uninstall | bash
|
||||||
|
```
|
||||||
|
|
||||||
## 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*`
|
||||||
|
4. `xinput list | grep touchpad -i`
|
||||||
|
5. `lsmod | grep hid`
|
||||||
|
6. `comfortable-swipe status`
|
||||||
|
7. `comfortable-swipe start` (if you can run it)
|
||||||
|
8. `comfortable-swipe debug` (try swiping if you can see `GESTURE_SWIPE_XXX`)
|
||||||
|
9. `cat $(comfortable-swipe config)`
|
||||||
|
|||||||
539
comfortable-swipe
Executable file
539
comfortable-swipe
Executable file
@ -0,0 +1,539 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Comfortable Swipe
|
||||||
|
|
||||||
|
# turn on errors per line
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
#########
|
||||||
|
# USAGE #
|
||||||
|
#########
|
||||||
|
|
||||||
|
function usage {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $BASENAME [--help|--version] [start|stop|config|autostart|buffer|debug|status] [<args>]
|
||||||
|
|
||||||
|
Configuration:
|
||||||
|
|
||||||
|
$BASENAME <PROPERTY> gets configuration property
|
||||||
|
$BASENAME <PROPERTY> [=] <VALUE> sets configuration to a value
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
# show help
|
||||||
|
function help {
|
||||||
|
usage
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Global Options:
|
||||||
|
|
||||||
|
-h, --help show this help text
|
||||||
|
-v, --version print the program version
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
start [--attach|--bare]
|
||||||
|
starts 3/4-finger gesture service in a detached process
|
||||||
|
--attach attach process to console
|
||||||
|
--bare attach with bare configurations
|
||||||
|
|
||||||
|
stop
|
||||||
|
stops 3/4-finger gesture service
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
config [get|set|delete|list|properties|path] [...]
|
||||||
|
shows the location of the config file
|
||||||
|
|
||||||
|
debug
|
||||||
|
logs raw output from input events taken from libinput
|
||||||
|
|
||||||
|
status
|
||||||
|
checks status of program and autostart
|
||||||
|
|
||||||
|
Report bugs to https://github.com/Hikari9/comfortable-swipe/issues/new
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
####################
|
||||||
|
# COMMAND OPTIONS #
|
||||||
|
####################
|
||||||
|
|
||||||
|
|
||||||
|
for i in "$@"; do
|
||||||
|
case $i in
|
||||||
|
-h | --help) # eagerly show help
|
||||||
|
help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-v | --version) # eagerly print version
|
||||||
|
echo "comfortable-swipe $VERSION"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--attach | --bare) # for start
|
||||||
|
if [[ "$1" != start ]]; then
|
||||||
|
if [[ "$1" != buffer ]]; then
|
||||||
|
echo "Unknown option: $i" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
OPTION_ATTACH="true"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ "$i" == -* ]]; then
|
||||||
|
echo "Unknown option: $i" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
#########
|
||||||
|
# START #
|
||||||
|
#########
|
||||||
|
|
||||||
|
|
||||||
|
# start comfortable-swipe
|
||||||
|
# internally pipes debug text to the buffer
|
||||||
|
function start {
|
||||||
|
stop > /dev/null 2>&1
|
||||||
|
if [[ "$OPTION_ATTACH" == "true" ]]; then
|
||||||
|
# attach the buffered output
|
||||||
|
debug | buffer $@
|
||||||
|
else
|
||||||
|
# detach buffered output
|
||||||
|
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 & disown
|
||||||
|
echo "Comfortable swipe is RUNNING in the background"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
########
|
||||||
|
# STOP #
|
||||||
|
########
|
||||||
|
|
||||||
|
|
||||||
|
# stop running comfortable-swipe commands (except self)
|
||||||
|
function stop {
|
||||||
|
function stop_prop {
|
||||||
|
pgrep -f "${1:?}" | fgrep -v $$ | xargs -I{} kill -- "{}"
|
||||||
|
}
|
||||||
|
stop_prop "$BASENAME"
|
||||||
|
stop_prop "$(which comfortable-swipe)"
|
||||||
|
stop_prop "$(which comfortable-swipe-buffer)"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#########
|
||||||
|
# DEBUG #
|
||||||
|
#########
|
||||||
|
|
||||||
|
|
||||||
|
# show debug text
|
||||||
|
# internally just calls libinput debug-events
|
||||||
|
function debug {
|
||||||
|
if command -v libinput-debug-events > /dev/null 2>&1; then
|
||||||
|
# compat for old Ubuntu
|
||||||
|
local COMMAND="libinput-debug-events"
|
||||||
|
else
|
||||||
|
local COMMAND="libinput debug-events"
|
||||||
|
fi
|
||||||
|
stdbuf -oL -e0 $COMMAND 2> >(fgrep -v 'double tracking')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# BUFFER #
|
||||||
|
##########
|
||||||
|
|
||||||
|
|
||||||
|
# parse input from a buffer
|
||||||
|
# internally calls comfortable-swipe-main.cpp, which is
|
||||||
|
# installed as: /usr/local/bin/ comfortable-swipe-buffer
|
||||||
|
function buffer {
|
||||||
|
exec comfortable-swipe-buffer "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# STATUS #
|
||||||
|
##########
|
||||||
|
|
||||||
|
|
||||||
|
function _program_running {
|
||||||
|
pgrep -f "$BASENAME" | fgrep -v $$ > /dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# verbosely show comfortable-swipe status
|
||||||
|
function status {
|
||||||
|
# show autostart status
|
||||||
|
echo "Autostart is $("$BASENAME" autostart status)"
|
||||||
|
# show program status
|
||||||
|
if _program_running; then
|
||||||
|
echo "Program is RUNNING"
|
||||||
|
else
|
||||||
|
echo "Program is STOPPED"
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##########
|
||||||
|
# CONFIG #
|
||||||
|
##########
|
||||||
|
|
||||||
|
|
||||||
|
# get location of configuration file
|
||||||
|
function config {
|
||||||
|
local CONFIG="$HOME/.config/comfortable-swipe.conf"
|
||||||
|
|
||||||
|
############
|
||||||
|
# show usage
|
||||||
|
function usage {
|
||||||
|
echo "Usage: $BASENAME config [get|set|delete|list|keys|edit|path] ..."
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# show path to config
|
||||||
|
function path {
|
||||||
|
echo "$CONFIG"
|
||||||
|
}
|
||||||
|
|
||||||
|
##############################################
|
||||||
|
# list config, show only last among duplicates
|
||||||
|
function list {
|
||||||
|
# dispatch subcommands
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
# no options; just show path
|
||||||
|
tac "$CONFIG" |\
|
||||||
|
sed -E "s/[#;].*//g" |\
|
||||||
|
egrep '\s+' |\
|
||||||
|
tr -d ' ' |\
|
||||||
|
egrep "^($KEYS|$DEPRECATED)=" |\
|
||||||
|
awk '!a[$1]++' |\
|
||||||
|
tac |\
|
||||||
|
sed 's/=/ = /g'
|
||||||
|
else
|
||||||
|
# filter list to match arguments as pattern
|
||||||
|
local pattern="$1"
|
||||||
|
for arg in "${@:2}"; do
|
||||||
|
pattern="$pattern|$arg"
|
||||||
|
done
|
||||||
|
list | egrep "($pattern)[^=]* ="
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
############################################
|
||||||
|
# get a list of all valid keys, one per line
|
||||||
|
function keys {
|
||||||
|
echo "$KEYS" | sed 's/|/\n/g'
|
||||||
|
}
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# Get a specific key in the config
|
||||||
|
function get {
|
||||||
|
function usage {
|
||||||
|
echo "Usage: $BASENAME config get <PROPERTY>"
|
||||||
|
echo -n "Props: "
|
||||||
|
echo "$KEYS" | sed 's/|/, /g'
|
||||||
|
}
|
||||||
|
# no next argument: show list
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
list
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
local KEY="$1"
|
||||||
|
# check if key is valid
|
||||||
|
if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then
|
||||||
|
# echo "'$KEY' is an invalid property" >&2
|
||||||
|
# echo >&2
|
||||||
|
usage >&2
|
||||||
|
echo >&2
|
||||||
|
echo "If you want to list down configurations, you can run:" >&2
|
||||||
|
echo >&2
|
||||||
|
echo " $BASENAME config list" >&2
|
||||||
|
echo >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# get key from config file
|
||||||
|
list | fgrep -m1 "$KEY =" | sed -E "s/^$KEY = //"
|
||||||
|
}
|
||||||
|
|
||||||
|
############################
|
||||||
|
# delete a key in the config
|
||||||
|
function delete {
|
||||||
|
# helper function to print usage
|
||||||
|
function usage {
|
||||||
|
echo "Usage: $BASENAME config delete [<PROPERTY>...]"
|
||||||
|
}
|
||||||
|
# no next argument: show help
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
echo "Property name is required!" >&2
|
||||||
|
# no key; show usage
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
local DELETE="$(list "$@")"
|
||||||
|
# check if there is something to delete
|
||||||
|
if [[ -z "$DELETE" ]]; then
|
||||||
|
echo "No config entry to delete" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Deleted:"
|
||||||
|
echo "$DELETE"
|
||||||
|
local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")"
|
||||||
|
echo "$RESULT" > "$CONFIG"
|
||||||
|
# restart comfortable-swipe if it is running
|
||||||
|
if _program_running; then
|
||||||
|
start > /dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
##################################
|
||||||
|
# set a specific key in the config
|
||||||
|
function set {
|
||||||
|
# helper function to print usage
|
||||||
|
function usage {
|
||||||
|
echo "Usage: $BASENAME config set <PROPERTY> [=] <VALUE>"
|
||||||
|
echo -n "Valid properties: "
|
||||||
|
echo "$KEYS" | sed 's/|/, /g'
|
||||||
|
echo
|
||||||
|
echo "Example:"
|
||||||
|
echo
|
||||||
|
echo " $BASENAME config set left3 = ctrl+super+Right"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
# no next argument: show help
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
echo "Property name is required!" >&2
|
||||||
|
echo >&2
|
||||||
|
# no key; show usage
|
||||||
|
usage >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# parse key and value option
|
||||||
|
local KEYVALUE="${@:1}"
|
||||||
|
local KEY=
|
||||||
|
local VALUE=
|
||||||
|
case "$KEYVALUE" in
|
||||||
|
*=*)
|
||||||
|
# key has equal sign, we split it
|
||||||
|
KEY="${KEYVALUE%%=*}"
|
||||||
|
VALUE="${KEYVALUE#*=}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# default: just get from next arguments combined
|
||||||
|
if [[ $# -eq 1 ]]; then
|
||||||
|
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
|
||||||
|
echo >&2
|
||||||
|
echo " $BASENAME config set $@ \"\"" >&2
|
||||||
|
echo >&2
|
||||||
|
echo "Or delete explicitly:" >&2
|
||||||
|
echo >&2
|
||||||
|
echo " $BASENAME config delete $1"
|
||||||
|
echo >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
KEY="$1"
|
||||||
|
VALUE="${@:2}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# trim leading and trailing spaces from key and value
|
||||||
|
KEY="$(echo "$KEY" | awk '{$1=$1};1')"
|
||||||
|
VALUE="$(echo "$VALUE" | awk '{$1=$1};1')"
|
||||||
|
# check if key is valid
|
||||||
|
if ! [[ "$KEY" =~ ^($KEYS|$DEPRECATED)$ ]]; then
|
||||||
|
echo "'$KEY' is an invalid property name" >&2
|
||||||
|
echo >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# if the key is present in the config, perform a replace
|
||||||
|
# replace the last value from the config with the given key
|
||||||
|
if list | grep -P "^\Q$KEY =" > /dev/null 2>&1; then
|
||||||
|
# apply sed to keep our formatting
|
||||||
|
# \\1 - keep any kind of indentation
|
||||||
|
# \\2 - keep any comments after the value (with the whitespace instact)
|
||||||
|
local RESULT="$(tac "$CONFIG" |\
|
||||||
|
sed -E "s/^(\\s*)$KEY\\s*=\\s*(\?!(\\s*[#;]))*(.*)\$/\\1$KEY = $VALUE\\2/1" |\
|
||||||
|
tac)"
|
||||||
|
# make sure we separate piping from outputing
|
||||||
|
echo "$RESULT" > "$CONFIG"
|
||||||
|
else
|
||||||
|
# otherwise, key is not present so we simply append
|
||||||
|
echo "$KEY = $VALUE" >> "$CONFIG"
|
||||||
|
fi
|
||||||
|
# show newly set value
|
||||||
|
echo "$KEY = $(get "$KEY")"
|
||||||
|
# restart comfortable-swipe if it is running
|
||||||
|
if _program_running; then
|
||||||
|
start > /dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
######################
|
||||||
|
# dispatch subcommands
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
# no options; just show usage
|
||||||
|
usage
|
||||||
|
echo "Try:"
|
||||||
|
echo
|
||||||
|
echo " $BASENAME config list"
|
||||||
|
echo
|
||||||
|
elif declare -f "$1" >/dev/null 2>&1; then
|
||||||
|
# invoke subcommand function, passing arguments through
|
||||||
|
# TODO: unset all nonlocal functions
|
||||||
|
"$@" # same as "$1" "$2" "$3" ... for full argument list
|
||||||
|
else
|
||||||
|
echo "Error: function $1 not recognized" >&2
|
||||||
|
echo "$USAGE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#############
|
||||||
|
# AUTOSTART #
|
||||||
|
#############
|
||||||
|
|
||||||
|
# enable or disable autostart
|
||||||
|
function autostart {
|
||||||
|
# path to autostart files
|
||||||
|
local AUTOSTART="$HOME/.config/autostart/comfortable-swipe.desktop"
|
||||||
|
local ENABLED="X-GNOME-Autostart-enabled"
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# show autostart file path
|
||||||
|
function path {
|
||||||
|
echo "$AUTOSTART"
|
||||||
|
}
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
# echo autostart status: ON, OFF, MISSING, INVALID
|
||||||
|
function status {
|
||||||
|
if [[ ! -f "$AUTOSTART" ]]; then
|
||||||
|
echo "MISSING"
|
||||||
|
elif fgrep "$ENABLED=true" < "$AUTOSTART" > /dev/null; then
|
||||||
|
echo "ON"
|
||||||
|
elif fgrep "$ENABLED=false" < "$AUTOSTART" > /dev/null; then
|
||||||
|
echo "OFF"
|
||||||
|
else
|
||||||
|
echo "INVALID"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
##################
|
||||||
|
# enable autostart
|
||||||
|
function on {
|
||||||
|
sed -i "s/$ENABLED=false/$ENABLED=true/" "$AUTOSTART"
|
||||||
|
echo "Autostart switched on"
|
||||||
|
}
|
||||||
|
|
||||||
|
###################
|
||||||
|
# disable autostart
|
||||||
|
function off {
|
||||||
|
sed -i "s/$ENABLED=true/$ENABLED=false/" "$AUTOSTART"
|
||||||
|
echo "Autostart switched off"
|
||||||
|
}
|
||||||
|
|
||||||
|
#####################################
|
||||||
|
# toggle to opposite autostart status
|
||||||
|
function toggle {
|
||||||
|
[[ $(status) == ON ]] && off || on
|
||||||
|
}
|
||||||
|
|
||||||
|
######################
|
||||||
|
# dispatch subcommands
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
# default behavior is to toggle
|
||||||
|
toggle
|
||||||
|
elif declare -f "$1" >/dev/null 2>&1; then
|
||||||
|
# invoke subcommand function, passing arguments through
|
||||||
|
# TODO: unset all nonlocal functions
|
||||||
|
"$@" # same as "$1" "$2" "$3" ... for full argument list
|
||||||
|
else
|
||||||
|
echo "Function $1 not recognized" >&2
|
||||||
|
echo "Usage: $BASENAME autostart [on|off|toggle|status|path]" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
############
|
||||||
|
# DISPATCH #
|
||||||
|
############
|
||||||
|
|
||||||
|
|
||||||
|
# dispatch subcommands
|
||||||
|
if [[ $# -eq 0 ]]; then
|
||||||
|
# no options; just show help
|
||||||
|
help
|
||||||
|
elif declare -f "$1" >/dev/null 2>&1; then
|
||||||
|
# invoke subcommand function, passing arguments through
|
||||||
|
# TODO: unset all nonlocal functions
|
||||||
|
"$@" # same as "$1" "$2" "$3" ... for full argument list
|
||||||
|
else
|
||||||
|
function abort {
|
||||||
|
# echo "Error: $1 not recognized" >&2
|
||||||
|
# echo >&2
|
||||||
|
usage >&2
|
||||||
|
echo -n "Valid props: " >&2
|
||||||
|
echo "$KEYS" | sed 's/|/, /g' >&2
|
||||||
|
}
|
||||||
|
# try to invoke config set / get depending on number of arguments
|
||||||
|
if [[ $# -eq 1 ]]; then
|
||||||
|
# one argument, use shorthand get
|
||||||
|
config get "$1" || abort
|
||||||
|
else
|
||||||
|
# multiple arguments, use shorthand set
|
||||||
|
config set "$@" 2> /dev/null || abort
|
||||||
|
fi
|
||||||
|
fi
|
||||||
55
comfortable-swipe-defines.cpp
Normal file
55
comfortable-swipe-defines.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef __comfortable_swipe_defines__
|
||||||
|
#define __comfortable_swipe_defines__
|
||||||
|
// all global #define statements go here
|
||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* COMFORTABLE_SWIPE_CONFIG
|
||||||
|
*
|
||||||
|
* This definition points to the location of the configuration file.
|
||||||
|
* A warning will be issued to the compiler if you do not define this at compile
|
||||||
|
* time.
|
||||||
|
*/
|
||||||
|
#ifndef COMFORTABLE_SWIPE_CONFIG
|
||||||
|
#pragma message "Please define COMFORTABLE_SWIPE_CONFIG during compilation!"
|
||||||
|
// just point to config from source directory
|
||||||
|
#define COMFORTABLE_SWIPE_CONFIG "/dev/null"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_CONFIG */
|
||||||
|
/**
|
||||||
|
* COMFORTABLE_SWIPE_AUTOSTART
|
||||||
|
*
|
||||||
|
* This definition points to the location of the autostart (.desktop) file.
|
||||||
|
* A warning will be issued to the compiler if you do not define this at compile
|
||||||
|
* time.
|
||||||
|
*/
|
||||||
|
#ifndef COMFORTABLE_SWIPE_AUTOSTART
|
||||||
|
#pragma message "Please define COMFORTABLE_SWIPE_AUTOSTART during compilation!"
|
||||||
|
// just point to autostart from source directory
|
||||||
|
#define COMFORTABLE_SWIPE_AUTOSTART "/dev/null"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_AUTOSTART */
|
||||||
|
/**
|
||||||
|
* COMFORTABLE_SWIPE_VERSION
|
||||||
|
*
|
||||||
|
* This is an optional definition for the version string of comfortable-swipe.
|
||||||
|
*/
|
||||||
|
#ifndef COMFORTABLE_SWIPE_VERSION
|
||||||
|
#pragma message "Please define COMFORTABLE_SWIPE_VERSION during compilation!"
|
||||||
|
#define COMFORTABLE_SWIPE_VERSION "v(UNKNOWN)"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_VERSION */
|
||||||
|
|
||||||
|
#endif /* __comfortable_swipe_defines__ */
|
||||||
197
comfortable-swipe-gesture-swipe-xdokey.cpp
Normal file
197
comfortable-swipe-gesture-swipe-xdokey.cpp
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
#ifndef __comfortable_swipe_gesture_swipe_xdokey__
|
||||||
|
#define __comfortable_swipe_gesture_swipe_xdokey__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <array> // std::array
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <xdo.h> // xdo_send_keysequence_window
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "comfortable-swipe-gesture-swipe.cpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe {
|
||||||
|
/**
|
||||||
|
* Gesture Swipe keyboard-swipe gestures class with xdo.
|
||||||
|
*
|
||||||
|
* Performs a swipe in one of the four cardinal directions:
|
||||||
|
* left, right, up, down. Applicable for 3 or 4 fingers.
|
||||||
|
*
|
||||||
|
* When constructing, please mind the order in the
|
||||||
|
* `gesture_swipe_xdokey::command_name[]` static array.
|
||||||
|
*/
|
||||||
|
class gesture_swipe_xdokey : public gesture_swipe {
|
||||||
|
public:
|
||||||
|
// stores the 8 command strings for xdo to execute
|
||||||
|
std::array<std::string, 8> commands;
|
||||||
|
// constructor
|
||||||
|
gesture_swipe_xdokey(const decltype(commands) &commands, float threshold = 0);
|
||||||
|
// destructor
|
||||||
|
virtual ~gesture_swipe_xdokey();
|
||||||
|
// hooks that we override
|
||||||
|
virtual void begin() override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
// override this when keyboard gesture is to be performed
|
||||||
|
virtual void do_keyboard_gesture(int mask);
|
||||||
|
// public accessors
|
||||||
|
virtual int get_previous_gesture() const { return this->previous_gesture; }
|
||||||
|
virtual int get_current_mask() const { return this->current_mask; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// stores square of threshold so we can compute faster
|
||||||
|
float threshold_squared;
|
||||||
|
// stores previous gesture so we don't repeat action
|
||||||
|
int previous_gesture;
|
||||||
|
int current_mask;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// static enums we will use for gesture matching
|
||||||
|
static const int FRESH = -1;
|
||||||
|
static const int MSK_THREE_FINGERS = 0;
|
||||||
|
static const int MSK_FOUR_FINGERS = 1;
|
||||||
|
static const int MSK_NEGATIVE = 0;
|
||||||
|
static const int MSK_POSITIVE = 2;
|
||||||
|
static const int MSK_HORIZONTAL = 0;
|
||||||
|
static const int MSK_VERTICAL = 4;
|
||||||
|
// mappings to our command string names
|
||||||
|
static const std::string command_name[];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Our mapped directional command names. These will be
|
||||||
|
* printed to the console during execution:
|
||||||
|
*
|
||||||
|
* SWIPE <command_name>
|
||||||
|
*
|
||||||
|
* Refer to the order of this array for the "commands"
|
||||||
|
* paramter in the constructor.
|
||||||
|
*/
|
||||||
|
decltype(
|
||||||
|
gesture_swipe_xdokey::command_name) gesture_swipe_xdokey::command_name = {
|
||||||
|
// the order of variables is based on bitmasking
|
||||||
|
// <VERTICAL?> | <POSITIVE?> | <FOUR FINGERS?>
|
||||||
|
"left3", // 000
|
||||||
|
"left4", // 001
|
||||||
|
"right3", // 010
|
||||||
|
"right4", // 011
|
||||||
|
"up3", // 100
|
||||||
|
"up4", // 101
|
||||||
|
"down3", // 110
|
||||||
|
"down4" // 111
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Constructs a new keyboard-based swipe gesture, given configurations
|
||||||
|
* for certain swipe events. Here, we construct our definition based on
|
||||||
|
* the four directions (left, up, right, down) for 3-finger and 4-finger
|
||||||
|
* swipes. Note that the direction is based on the Australian natural
|
||||||
|
* scrolling direction (ie. left3 is natural movement of 3 fingers left).
|
||||||
|
*/
|
||||||
|
gesture_swipe_xdokey::gesture_swipe_xdokey(
|
||||||
|
const decltype(gesture_swipe_xdokey::commands) &commands, float threshold)
|
||||||
|
: gesture_swipe(), commands(commands),
|
||||||
|
threshold_squared(threshold * threshold),
|
||||||
|
previous_gesture(gesture_swipe_xdokey::FRESH),
|
||||||
|
current_mask(gesture_swipe_xdokey::FRESH) {}
|
||||||
|
/**
|
||||||
|
* Destructs this keyboard swipe gesture.
|
||||||
|
*/
|
||||||
|
gesture_swipe_xdokey::~gesture_swipe_xdokey() {}
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdokey::begin() {
|
||||||
|
// call superclass method
|
||||||
|
gesture_swipe::begin();
|
||||||
|
// assign gesture to FRESH
|
||||||
|
current_mask = FRESH;
|
||||||
|
previous_gesture = FRESH;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdokey::update() {
|
||||||
|
// call superclass method
|
||||||
|
gesture_swipe::update();
|
||||||
|
// scale threshold to 1/10 when gesture is fresh
|
||||||
|
// acts like our static friction coefficient
|
||||||
|
const float scale = get_previous_gesture() == FRESH ? 0.01f : 1.0f;
|
||||||
|
// we are working with floating points which are not exact
|
||||||
|
// make sure we compare with a very small value (1e-6f)
|
||||||
|
// if distance goes out of threshold, perform our swipe
|
||||||
|
if (x * x + y * y > threshold_squared * scale + 1e-6f) {
|
||||||
|
// we parse our mask based on the values obtained from the regex
|
||||||
|
int mask = 0;
|
||||||
|
if (fingers == 3)
|
||||||
|
mask |= MSK_THREE_FINGERS;
|
||||||
|
else if (fingers == 4)
|
||||||
|
mask |= MSK_FOUR_FINGERS;
|
||||||
|
const float absx = x >= 0 ? x : -x;
|
||||||
|
const float absy = y >= 0 ? y : -y;
|
||||||
|
if (absx > absy) {
|
||||||
|
// gesture is horizontal
|
||||||
|
mask |= MSK_HORIZONTAL;
|
||||||
|
if (x < 0)
|
||||||
|
mask |= MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= MSK_POSITIVE;
|
||||||
|
} else /* std::abs(x) <= std::abs(y) */
|
||||||
|
{
|
||||||
|
// gesture is vertical
|
||||||
|
mask |= MSK_VERTICAL;
|
||||||
|
if (y < 0)
|
||||||
|
mask |= MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
// update our mask
|
||||||
|
current_mask = mask;
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if (previous_gesture == FRESH ||
|
||||||
|
previous_gesture == (mask ^ MSK_POSITIVE)) {
|
||||||
|
// do keyboard gesture
|
||||||
|
do_keyboard_gesture(mask);
|
||||||
|
// reset our location variables
|
||||||
|
x = y = 0;
|
||||||
|
previous_gesture = mask;
|
||||||
|
}
|
||||||
|
} else { // not in threshold, set mask to fresh
|
||||||
|
current_mask = FRESH;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Perform our maske command to xdo.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdokey::do_keyboard_gesture(int mask) {
|
||||||
|
// perform our keyboard command with xdo_send_keysequence
|
||||||
|
xdo_send_keysequence_window(xdo, CURRENTWINDOW, commands[mask].data(), 0);
|
||||||
|
std::cout << "SWIPE " << command_name[mask] << std::endl;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdokey::end() {
|
||||||
|
// just call superclass method
|
||||||
|
gesture_swipe::end();
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe
|
||||||
|
#endif /* __comfortable_swipe_gesture_swipe_xdokey__ */
|
||||||
202
comfortable-swipe-gesture-swipe-xdomouse.cpp
Normal file
202
comfortable-swipe-gesture-swipe-xdomouse.cpp
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
#ifndef __comfortable_swipe_gesture_swipe_xdomouse__
|
||||||
|
#define __comfortable_swipe_gesture_swipe_xdomouse__
|
||||||
|
/**
|
||||||
|
* File: comfortable-swipe-gesture-swipe-xdomouse.cpp
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <cstdio> // std::sscanf
|
||||||
|
#include <cstring> // strncmp
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <xdo.h> // xdo_mouse_down
|
||||||
|
// xdo_mouse_up
|
||||||
|
// xdo_move_mouse_relative
|
||||||
|
// CURRENTWINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "comfortable-swipe-gesture-swipe.cpp"
|
||||||
|
|
||||||
|
namespace comfortable_swipe {
|
||||||
|
// enumerations for mouse hold gesture types
|
||||||
|
enum {
|
||||||
|
MOUSE_NONE = -1,
|
||||||
|
MOUSE_MOVE = 0,
|
||||||
|
MOUSE_LEFT_CLICK = 1,
|
||||||
|
MOUSE_MIDDLE_CLICK = 2,
|
||||||
|
MOUSE_RIGHT_CLICK = 3,
|
||||||
|
MOUSE_WHEEL_UP = 4,
|
||||||
|
MOUSE_WHEEL_DOWN = 5,
|
||||||
|
MOUSE_SCROLL = 6,
|
||||||
|
MOUSE_SCROLL_REVERSE = 7
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Gesture Swipe mouse gestures class with xdo.
|
||||||
|
*
|
||||||
|
* If type is MOUSE_*_CLICK, we apply:
|
||||||
|
* - xdo_mouse_down on begin()
|
||||||
|
* - xdo_mouse_up on end()
|
||||||
|
*
|
||||||
|
* If type is MOUSE_MOVE, we apply:
|
||||||
|
* - xdo_mouse_move_relative on update().
|
||||||
|
*
|
||||||
|
* If type is MOUSE_WHEEL* or MOUSE_SCROLL*, we apply:
|
||||||
|
* - xdo_mouse_down on update()
|
||||||
|
* - xdo_mouse_up on update()
|
||||||
|
*/
|
||||||
|
class gesture_swipe_xdomouse : public gesture_swipe {
|
||||||
|
public:
|
||||||
|
// the button number being clicked
|
||||||
|
int button;
|
||||||
|
// constructor
|
||||||
|
gesture_swipe_xdomouse(const char *mouse3, // 3 finger mouse gesture
|
||||||
|
const char *mouse4 // 4 finger mouse gesture
|
||||||
|
);
|
||||||
|
// destructor
|
||||||
|
virtual ~gesture_swipe_xdomouse();
|
||||||
|
// override begin and end for mousedown
|
||||||
|
virtual void begin() override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
// provide our own mouse dispatch functions
|
||||||
|
virtual void do_mousedown(int button, int fingers);
|
||||||
|
virtual void do_mouseup(int button, int fingers);
|
||||||
|
// utility method to parse mouse input given config characters
|
||||||
|
static int parse_mouse_button(const char *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// command holders
|
||||||
|
const char *mouse3;
|
||||||
|
const char *mouse4;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Constructs a new mouse gesture, given "mouse3" and "mouse4" configurations.
|
||||||
|
*/
|
||||||
|
gesture_swipe_xdomouse::gesture_swipe_xdomouse(const char *mouse3,
|
||||||
|
const char *mouse4)
|
||||||
|
: gesture_swipe(), button(MOUSE_NONE), mouse3(mouse3), mouse4(mouse4) {}
|
||||||
|
/**
|
||||||
|
* Destructs this mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
gesture_swipe_xdomouse::~gesture_swipe_xdomouse() {}
|
||||||
|
/**
|
||||||
|
* Utility method to parse mouse number from input.
|
||||||
|
* Returns MOUSE_NONE on failure.
|
||||||
|
*/
|
||||||
|
int gesture_swipe_xdomouse::parse_mouse_button(const char *input) {
|
||||||
|
// just move without holding button down
|
||||||
|
if (std::strcmp(input, "move") == 0)
|
||||||
|
return MOUSE_MOVE;
|
||||||
|
if (std::strcmp(input, "scroll") == 0)
|
||||||
|
return MOUSE_SCROLL;
|
||||||
|
if (std::strcmp(input, "scroll_reverse") == 0)
|
||||||
|
return MOUSE_SCROLL_REVERSE;
|
||||||
|
// get button number
|
||||||
|
int button;
|
||||||
|
if (std::sscanf(input, "button%d", &button) == 1) {
|
||||||
|
if (1 <= button && button <= 6) {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MOUSE_NONE;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Run mousedown command on a mouse button input.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdomouse::do_mousedown(int button, int fingers) {
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK) {
|
||||||
|
// send mouse down on associated button
|
||||||
|
xdo_mouse_down(xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Run mouseup command on a mouse button output.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdomouse::do_mouseup(int button, int fingers) {
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK) {
|
||||||
|
// send mouse up on associated button
|
||||||
|
xdo_mouse_up(xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on begin of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdomouse::begin() {
|
||||||
|
// call superclass method
|
||||||
|
gesture_swipe::begin();
|
||||||
|
// map fingers to gesture command
|
||||||
|
auto command = fingers == 3 ? mouse3 : (fingers == 4 ? mouse4 : NULL);
|
||||||
|
if (command != NULL) {
|
||||||
|
// get button int from the command
|
||||||
|
button = parse_mouse_button(command);
|
||||||
|
// perform mousedown on the button and print to console
|
||||||
|
if (button != MOUSE_NONE) {
|
||||||
|
do_mousedown(button, fingers);
|
||||||
|
std::printf("MOUSE DOWN mouse%d %s\n", this->fingers, command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on end of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdomouse::update() {
|
||||||
|
// call superclass method
|
||||||
|
gesture_swipe::update();
|
||||||
|
if (button != MOUSE_NONE) {
|
||||||
|
// if MOUSE_MOVE or MOUSE_CLICK*
|
||||||
|
if (0 <= button && button <= 3) {
|
||||||
|
// drag mouse with pointer during update
|
||||||
|
xdo_move_mouse_relative(xdo, udx, udy);
|
||||||
|
} else if (button == MOUSE_SCROLL || button == MOUSE_SCROLL_REVERSE) {
|
||||||
|
// perform naive scroll depending on vertical direction
|
||||||
|
int wheel = MOUSE_WHEEL_DOWN;
|
||||||
|
if ((udy > 0) == (button == MOUSE_SCROLL))
|
||||||
|
wheel = MOUSE_WHEEL_UP;
|
||||||
|
// click wheel on update (note: this is not precise)
|
||||||
|
xdo_mouse_down(xdo, CURRENTWINDOW, wheel);
|
||||||
|
xdo_mouse_up(xdo, CURRENTWINDOW, wheel);
|
||||||
|
} else if (button == MOUSE_WHEEL_UP || button == MOUSE_WHEEL_DOWN) {
|
||||||
|
// click wheel button on 4 or 5
|
||||||
|
xdo_mouse_down(xdo, CURRENTWINDOW, button);
|
||||||
|
xdo_mouse_up(xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void gesture_swipe_xdomouse::end() {
|
||||||
|
// optimization: only perform mouseup when flag is set
|
||||||
|
if (button != MOUSE_NONE) {
|
||||||
|
// map fingers to gesture command
|
||||||
|
// perform mouseup on the button and print to console
|
||||||
|
do_mouseup(button, fingers);
|
||||||
|
std::printf("MOUSE UP mouse%d %s\n", fingers,
|
||||||
|
fingers == 3 ? mouse3 : mouse4);
|
||||||
|
}
|
||||||
|
// reset button
|
||||||
|
button = MOUSE_NONE;
|
||||||
|
// call superclass method
|
||||||
|
gesture_swipe::end();
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe
|
||||||
|
|
||||||
|
#endif /* __comfortable_swipe_gesture_swipe_xdomouse__ */
|
||||||
229
comfortable-swipe-gesture-swipe.cpp
Normal file
229
comfortable-swipe-gesture-swipe.cpp
Normal file
@ -0,0 +1,229 @@
|
|||||||
|
#ifndef __comfortable_swipe_gesture_swipe__
|
||||||
|
#define __comfortable_swipe_gesture_swipe__
|
||||||
|
/**
|
||||||
|
* File: comfortable-swipe-gesture-swipe.cpp
|
||||||
|
*
|
||||||
|
* This is the base class of all comfortable swipe gestures.
|
||||||
|
*
|
||||||
|
* The class `comfortable_swipe::gesture_swipe` handles dispatching
|
||||||
|
* of swipe gestures. The method `gesture_swipe::run(const char*)`
|
||||||
|
* parses a line from libinput debug-events and dispatches a begin(),
|
||||||
|
* update(), or end() function based on a compiled regex pattern.
|
||||||
|
*
|
||||||
|
* We statically compile our swipe gesture regex patterns here.
|
||||||
|
* This is for parsing `libinput debug-events` console output:
|
||||||
|
*
|
||||||
|
* GESTURE_SWIPE_BEGIN - libinput's begin wipe command
|
||||||
|
* GESTURE_SWIPE_UPDATE - libinput's update swipe command
|
||||||
|
* GESTURE_SWIPE_END - libinput's end swipe command
|
||||||
|
*
|
||||||
|
* We dispatch our events based on the regex patterns above, and
|
||||||
|
* extract important information, such as number of fingers, in
|
||||||
|
* an efficient way with Regular Expressions (regex).
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <regex> // std::regex, std::regex_match, std::cmatch
|
||||||
|
#include <string> // std::stoi, std::stof
|
||||||
|
extern "C" {
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
namespace comfortable_swipe {
|
||||||
|
/**
|
||||||
|
* Handles swipe gesture input from libinput debug-events.
|
||||||
|
* Dispatches keyboard commands on swipe using libxdo.
|
||||||
|
*/
|
||||||
|
class gesture_swipe {
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
gesture_swipe();
|
||||||
|
// destructor
|
||||||
|
virtual ~gesture_swipe();
|
||||||
|
// fields for xdo
|
||||||
|
int fingers;
|
||||||
|
// normal values (for touchpad mapping)
|
||||||
|
float x, y, dx, dy;
|
||||||
|
// unaccelerated values (for screen mapping)
|
||||||
|
float ux, uy, udx, udy;
|
||||||
|
// hooks that we can override (mark as virtual)
|
||||||
|
virtual void begin();
|
||||||
|
virtual void update();
|
||||||
|
virtual void end();
|
||||||
|
virtual bool run(const char *);
|
||||||
|
// public check if currently swiping
|
||||||
|
virtual bool is_swiping() const { return this->flag_swiping; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// xdo container
|
||||||
|
xdo_t *xdo;
|
||||||
|
// location of mouse
|
||||||
|
int screen_num, ix, iy;
|
||||||
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
|
bool flag_swiping;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// defined in: comfortable-swipe-gesture-swipe.regex.cpp
|
||||||
|
static const std::regex GESTURE_SWIPE_BEGIN;
|
||||||
|
static const std::regex GESTURE_SWIPE_UPDATE;
|
||||||
|
static const std::regex GESTURE_SWIPE_END;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Constructs a new fresh swipe gesture container.
|
||||||
|
*/
|
||||||
|
gesture_swipe::gesture_swipe() : xdo(xdo_new(NULL)), flag_swiping(false) {
|
||||||
|
// improve responsiveness of first gesture by pre-empting xdotool
|
||||||
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Destructs this swipe gesture.
|
||||||
|
*/
|
||||||
|
gesture_swipe::~gesture_swipe() { xdo_free(this->xdo); }
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void gesture_swipe::begin() {
|
||||||
|
// save current screen location for gestured mouse movement
|
||||||
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
||||||
|
this->x = 0;
|
||||||
|
this->y = 0;
|
||||||
|
this->ux = 0;
|
||||||
|
this->uy = 0;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void gesture_swipe::update() {
|
||||||
|
this->x += this->dx;
|
||||||
|
this->y += this->dy;
|
||||||
|
this->ux += this->udx;
|
||||||
|
this->uy += this->udy;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void gesture_swipe::end() {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Dispatches begin/update/end depending on the regex pattern provided by this
|
||||||
|
* class. Returns true if a gesture begin/update/end was parsed.
|
||||||
|
*
|
||||||
|
* @param line the line from libinput debug-events to parse
|
||||||
|
* @return true if begin/update/end was dispatched
|
||||||
|
*/
|
||||||
|
bool gesture_swipe::run(const char *line) {
|
||||||
|
// prepare holder for regex matches
|
||||||
|
static std::cmatch matches;
|
||||||
|
if (!this->flag_swiping) {
|
||||||
|
// not swiping, check if swipe will begin
|
||||||
|
if (std::regex_match(line, matches, GESTURE_SWIPE_BEGIN) != 0) {
|
||||||
|
// assign necessary variables for swipe begin
|
||||||
|
this->flag_swiping = true;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
// dispatch begin
|
||||||
|
this->begin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// currently swiping
|
||||||
|
if (std::regex_match(line, matches, GESTURE_SWIPE_UPDATE) != 0) {
|
||||||
|
// assign necessary variables for swipe update
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->dx = std::stof(matches[2]);
|
||||||
|
this->dy = std::stof(matches[3]);
|
||||||
|
this->udx = std::stof(matches[4]);
|
||||||
|
this->udy = std::stof(matches[5]);
|
||||||
|
// dispatch update
|
||||||
|
this->update();
|
||||||
|
return true;
|
||||||
|
} else if (std::regex_match(line, matches, GESTURE_SWIPE_END) != 0) {
|
||||||
|
// assign necessary variables for swipe end
|
||||||
|
this->flag_swiping = false;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
// dispatch end
|
||||||
|
this->end();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for start of swipe.
|
||||||
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_SWIPE_BEGIN +34.33s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const std::regex
|
||||||
|
gesture_swipe::GESTURE_SWIPE_BEGIN("^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_BEGIN" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
);
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for the end of swipe.
|
||||||
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_SWIPE_END +35.03s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const std::regex
|
||||||
|
gesture_swipe::GESTURE_SWIPE_END("^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_END" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
);
|
||||||
|
// matches signed decimal numbers (eg. "6.02" "-1.1")
|
||||||
|
#define _NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
||||||
|
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
||||||
|
#define _NUMBER_DIVISION "\\s*(" _NUMBER_REGEX ")/\\s*(" _NUMBER_REGEX ")"
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for during a swipe.
|
||||||
|
* Extracts number of fingers used and the speed (normal and accelerated) of the
|
||||||
|
* swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_SWIPE_UPDATE \
|
||||||
|
* +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)
|
||||||
|
* ^ ^ ^ ^ ^
|
||||||
|
* fingers dx dy udx udy
|
||||||
|
*/
|
||||||
|
const std::regex gesture_swipe::GESTURE_SWIPE_UPDATE(
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_UPDATE" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s+" _NUMBER_DIVISION // speed (dx/dy)
|
||||||
|
"\\s+\\(" _NUMBER_DIVISION
|
||||||
|
"\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
||||||
|
"\\s*$" // end of string
|
||||||
|
);
|
||||||
|
// clean up temporary macros
|
||||||
|
#undef _NUMBER_DIVISION
|
||||||
|
#undef _NUMBER_REGEX
|
||||||
|
} // namespace comfortable_swipe
|
||||||
|
#endif /* __comfortable_swipe_gesture_swipe__ */
|
||||||
137
comfortable-swipe-main.cpp
Normal file
137
comfortable-swipe-main.cpp
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
#ifndef __comfortable_swipe_main__
|
||||||
|
#define __comfortable_swipe_main__
|
||||||
|
/**
|
||||||
|
* The main driver program for `comfortable-swipe-buffer`
|
||||||
|
*
|
||||||
|
* This C++ program parses the output from libinput debug-events
|
||||||
|
* into a buffer and dispatches C++ libxdo commands upon swipe.
|
||||||
|
*
|
||||||
|
* Possible paths of the executable:
|
||||||
|
*
|
||||||
|
* /usr/bin/comfortable-swipe-buffer
|
||||||
|
* /usr/local/bin/comfortable-swipe-buffer
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "comfortable-swipe-defines.cpp"
|
||||||
|
#include "comfortable-swipe-gesture-swipe-xdokey.cpp"
|
||||||
|
#include "comfortable-swipe-gesture-swipe-xdomouse.cpp"
|
||||||
|
#include "comfortable-swipe-gesture-swipe.cpp"
|
||||||
|
#include <iostream> // std::ios, std::cin, std::getline
|
||||||
|
#include <map> // std::map
|
||||||
|
#include <set> // std::set
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <ini.h> // ini_parse
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers keys and values from the config file to a map.
|
||||||
|
*/
|
||||||
|
int parse_config(void *config, const char section[], const char name[],
|
||||||
|
const char value[]) {
|
||||||
|
auto &configmap = *(std::map<std::string, std::string> *)config;
|
||||||
|
configmap[name] = value;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main driver program.
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
using namespace std;
|
||||||
|
using namespace comfortable_swipe;
|
||||||
|
// unsync stdio for faster IO
|
||||||
|
ios::sync_with_stdio(false);
|
||||||
|
cin.tie(0);
|
||||||
|
cout.tie(0);
|
||||||
|
// parse configuration file
|
||||||
|
map<string, string> config;
|
||||||
|
if (ini_parse(COMFORTABLE_SWIPE_CONFIG, parse_config, &config) < 0) {
|
||||||
|
cerr << "error: config " << COMFORTABLE_SWIPE_CONFIG << endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
// clear config and just use "threshold" if --bare
|
||||||
|
if (set<string>(argv + 1, argv + argc).count("--bare")) {
|
||||||
|
if (config.count("threshold")) {
|
||||||
|
auto threshold = config["threshold"];
|
||||||
|
config.clear();
|
||||||
|
config["threshold"] = threshold;
|
||||||
|
} else {
|
||||||
|
config.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// initialize keyboard swipe gesture handler
|
||||||
|
// commands are: [left|up|right|down][3|4]
|
||||||
|
// we will fetch our commands from the config in correct order
|
||||||
|
// Examples:
|
||||||
|
// left3=ctrl+alt+Right shift to right workspace
|
||||||
|
// right3=ctrl+alt+Left shift to left workspace
|
||||||
|
// up3=super+Up maximize
|
||||||
|
// down3=super+Down minimize
|
||||||
|
decltype(gesture_swipe_xdokey::commands) commands;
|
||||||
|
for (size_t i = 0; i < commands.size(); ++i)
|
||||||
|
commands[i] = config[gesture_swipe_xdokey::command_name[i]];
|
||||||
|
// correctly parse threshold as float
|
||||||
|
float threshold = 0.0f;
|
||||||
|
try {
|
||||||
|
threshold = stof(config["threshold"]);
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
// create swipe handler
|
||||||
|
gesture_swipe_xdokey keyswipe(commands, threshold);
|
||||||
|
// initialize mouse hold gesture handler
|
||||||
|
// for now, this supports 3-finger and 4-finger hold
|
||||||
|
// Examples:
|
||||||
|
// mouse3=move move mouse on 3 fingers
|
||||||
|
// mouse3=button1 hold button 1 on 3 fingers
|
||||||
|
// mouse4=button3 hold button 3 (right click) on 3 fingers
|
||||||
|
// warn user that hold3 is deprecated
|
||||||
|
if (config.count("hold3"))
|
||||||
|
std::cerr << "WARNING: hold3 is deprecated. Use mouse3 instead."
|
||||||
|
<< std::endl;
|
||||||
|
if (config.count("hold4"))
|
||||||
|
std::cerr << "WARNING: hold4 is deprecated. Use mouse4 instead."
|
||||||
|
<< std::endl;
|
||||||
|
// get input values
|
||||||
|
string mouse3 = config.count("mouse3") ? config["mouse3"] : config["hold3"];
|
||||||
|
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
|
||||||
|
gesture_swipe_xdomouse mousehold(mouse3.data(), mouse4.data());
|
||||||
|
// start reading lines from input one by one
|
||||||
|
for (string line; getline(cin, line);) {
|
||||||
|
if (nomouse) {
|
||||||
|
keyswipe.run(line.data());
|
||||||
|
} else {
|
||||||
|
// optimization: if no mouse config is set, just run keyboard
|
||||||
|
if (mousehold.is_swiping() && mousehold.button == MOUSE_NONE) {
|
||||||
|
keyswipe.run(line.data());
|
||||||
|
} else if (mousehold.run(line.data())) {
|
||||||
|
// only allow keyswipe gestures on mouse move
|
||||||
|
if (mousehold.button == MOUSE_NONE || mousehold.button == MOUSE_MOVE) {
|
||||||
|
keyswipe.run(line.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
12
compile
Executable file
12
compile
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# usage: ./compile *.cpp
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR="$(dirname $0)"
|
||||||
|
VERSION="$(cat "$DIR/VERSION" | tr -d '[:space:]')"
|
||||||
|
|
||||||
|
CXX='g++'
|
||||||
|
CXX_FLAGS='-std=c++14 -O2 -Wall -lxdo -linih -lxdo -linih'
|
||||||
|
|
||||||
|
g++ "$@" ${CXX_FLAGS} -DCOMFORTABLE_SWIPE_VERSION="\"$VERSION\""
|
||||||
42
config/comfortable-swipe.conf
Normal file
42
config/comfortable-swipe.conf
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Comfortable Swipe
|
||||||
|
#
|
||||||
|
# Feel free to edit this configuration file if you have different
|
||||||
|
# keyboard shortcuts that you would like to use. Comments starting
|
||||||
|
# with a pound (#) or semi-colon (;) are ignored.
|
||||||
|
#
|
||||||
|
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for
|
||||||
|
# a list of keycodes you can use.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Tweak threshold depending on the sensitivity of your touchpad.
|
||||||
|
# Make this higher to lessen sensitivity.
|
||||||
|
# (note: values have no limit, can be as large as 1000.0)
|
||||||
|
threshold = 0.0
|
||||||
|
|
||||||
|
# Uncomment below to enable mouse gestures (3 fingers)
|
||||||
|
; mouse3 = button1 # drag left click
|
||||||
|
; mouse3 = button2 # drag middle click
|
||||||
|
; mouse3 = button3 # drag right click
|
||||||
|
; mouse3 = button4 # drag wheel up
|
||||||
|
; mouse3 = button5 # drag wheel down
|
||||||
|
; mouse3 = move # just move mouse along with the cursor
|
||||||
|
; mouse3 = scroll # natural scroll (experimental)
|
||||||
|
; mouse3 = scroll_reverse # reverse scroll (experimental)
|
||||||
|
|
||||||
|
# Uncomment below to enable mouse gestures (4 fingers)
|
||||||
|
; mouse4 = button1 # drag left click
|
||||||
|
; mouse4 = button2 # drag middle click
|
||||||
|
; mouse4 = button3 # drag right click
|
||||||
|
; mouse4 = button4 # drag wheel up
|
||||||
|
; mouse4 = button5 # drag wheel down
|
||||||
|
; mouse4 = move # just move mouse along with the cursor
|
||||||
|
; mouse4 = scroll # natural scroll (experimental)
|
||||||
|
; mouse4 = scroll_reverse # reverse scroll (experimental)
|
||||||
8
config/comfortable-swipe.desktop
Normal file
8
config/comfortable-swipe.desktop
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Exec=comfortable-swipe start
|
||||||
|
Name=Comfortable Swipe
|
||||||
|
Comment=Comfortable 3/4-finger touchpad gestures
|
||||||
|
Hidden=false
|
||||||
|
NoDisplay=false
|
||||||
|
X-GNOME-Autostart-enabled=true
|
||||||
231
install
231
install
@ -1,56 +1,201 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# prefer running as root
|
|
||||||
DIR=$(dirname $0)
|
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
|
||||||
CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf
|
|
||||||
DCONF_PATH=$DIR/src/defaults.conf
|
|
||||||
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
|
||||||
|
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
set -e
|
||||||
# stop any running comfortable-swipe if it exists
|
|
||||||
$PROGRAM stop
|
if [[ "$USER" == root ]]; then
|
||||||
# remove existing comfortable-swipe
|
echo "Please run 'bash install' as non-root user" 2>&1
|
||||||
rm $(which comfortable-swipe)
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#copy config file
|
DIR="$(dirname "$0")"
|
||||||
abort () {
|
VERSION="$(cat $DIR/VERSION | tr -d '[:space:]')"
|
||||||
exec echo "Installation aborted"
|
|
||||||
|
# target executable
|
||||||
|
SOURCE="$DIR/comfortable-swipe"
|
||||||
|
TARGET="/usr/local/bin/comfortable-swipe"
|
||||||
|
|
||||||
|
# compile targets
|
||||||
|
COMPILE="$DIR/compile"
|
||||||
|
COMPILE_SOURCE="$DIR/comfortable-swipe-main.cpp"
|
||||||
|
COMPILE_TARGET="/usr/local/bin/comfortable-swipe-buffer"
|
||||||
|
|
||||||
|
# configurations
|
||||||
|
CONF_SOURCE="$DIR/config/comfortable-swipe.conf"
|
||||||
|
CONF_TARGET="$HOME/.config/comfortable-swipe.conf"
|
||||||
|
OLD_CONF_TARGET="/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
||||||
|
|
||||||
|
# autostart
|
||||||
|
AUTOSTART_SOURCE="$DIR/config/comfortable-swipe.desktop"
|
||||||
|
AUTOSTART_TARGET="$HOME/.config/autostart/comfortable-swipe.desktop"
|
||||||
|
|
||||||
|
# stop any running comfortable-swipe if it exists
|
||||||
|
comfortable-swipe stop > /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
|
||||||
|
# shorthand to abort the installation
|
||||||
|
function abort {
|
||||||
|
echo "Installation aborted" >&2
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
mkdir -p $(dirname $CONF_PATH) || abort
|
|
||||||
if [ ! -f $CONF_PATH ]; then
|
# shorthand to try a command with sudo if it fails
|
||||||
if [ ! -f $OLD_CONF_PATH ]; then
|
function trysudo {
|
||||||
# old config file not found, create from scratch
|
$@ 2> /dev/null || sudo $@
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
}
|
||||||
else
|
|
||||||
# old config file found, move to the new path
|
# uninstall existing program
|
||||||
cat $OLD_CONF_PATH > $CONF_PATH || abort
|
function uninstall_existing {
|
||||||
echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH"
|
local PROGRAM="${1:?missing program name}"
|
||||||
|
# remove existing comfortable-swipe
|
||||||
|
if [[ -x "$(command -v "$PROGRAM")" ]]; then
|
||||||
|
echo -n "Removing previous $(which "$PROGRAM") ... "
|
||||||
|
trysudo rm -f "$(which "$PROGRAM")"
|
||||||
|
echo "ok"
|
||||||
fi
|
fi
|
||||||
else
|
}
|
||||||
# config file found, ask user if overwrite
|
|
||||||
echo "Old conf file found in $CONF_PATH"
|
|
||||||
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
## CONFIGURATION FILE LOADING
|
||||||
response=${response,,} # tolower
|
# This section handles installation of configuration file.
|
||||||
if [[ "$response" =~ ^(no|n)$ ]]; then
|
# We determine first if any old configuration files exists.
|
||||||
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
# make sure config directory exists
|
||||||
response=${response,,}
|
function install_configuration_file {
|
||||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
mkdir -p "$(dirname "$CONF_TARGET")"
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
|
||||||
|
# check if configuration already exists
|
||||||
|
if [[ -f "$CONF_TARGET" ]]; then
|
||||||
|
# ask user if we overwrite configuration
|
||||||
|
echo "Old conf file found in $CONF_TARGET" >&2
|
||||||
|
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response >&2
|
||||||
|
|
||||||
|
# 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
|
||||||
|
read -r -p "Conf file will be overwritten! Are you sure? [Y/n] " response >&2
|
||||||
|
if [[ -z "$response" ]]; then
|
||||||
|
response="y"
|
||||||
|
fi
|
||||||
|
if [[ "${response,,}" =~ ^(no|n)$ ]]; then
|
||||||
|
abort
|
||||||
|
else
|
||||||
|
# They agreed... replace configuration
|
||||||
|
cat "$CONF_SOURCE" > "$CONF_TARGET"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# target does not exist yet
|
||||||
|
# try copying from older configurations
|
||||||
|
if [[ -f "$OLD_CONF_TARGET" ]]; then
|
||||||
|
# move configuration from an older version (< v1.2)
|
||||||
|
echo "Moving configuration from $OLD_CONF_TARGET to $CONF_TARGET ..."
|
||||||
|
mv "$OLD_CONF_TARGET" "$CONF_TARGET"
|
||||||
|
# clean up old directory if possible
|
||||||
|
rmdir "$(dirname "$OLD_CONF_TARGET")" > /dev/null 2>&1 || true
|
||||||
else
|
else
|
||||||
abort
|
# fresh installation! just copy default configuration
|
||||||
|
cat "$CONF_SOURCE" > "$CONF_TARGET"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Installed: $CONF_TARGET"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
## Installation of main program
|
||||||
|
#
|
||||||
|
# /usr/local/bin/comfortable-swipe
|
||||||
|
#
|
||||||
|
function install_main_program {
|
||||||
|
# copy source to target with executable permissions
|
||||||
|
# install to target, with hardcoded version
|
||||||
|
if [[ -f "$TARGET" ]]; then
|
||||||
|
trysudo rm "$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"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Compilation and installation of C++ buffer program:
|
||||||
|
#
|
||||||
|
# /usr/local/bin/comfortable-swipe-buffer
|
||||||
|
#
|
||||||
|
function install_cpp_program {
|
||||||
|
# compile program to temporary file first
|
||||||
|
TMP_TARGET="$(mktemp)"
|
||||||
|
$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 with sudo
|
||||||
|
trysudo mkdir -p "$(dirname "$COMPILE_TARGET")"
|
||||||
|
# remove existing file for permissions to work
|
||||||
|
if [[ -f "$COMPILE_TARGET" ]]; then
|
||||||
|
sudo rm "$COMPILE_TARGET"
|
||||||
|
fi
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Installation of Autostart Desktop file
|
||||||
|
#
|
||||||
|
# /home/$USER/.config/autostart/comfortable-swipe.desktop
|
||||||
|
#
|
||||||
|
function install_autostart {
|
||||||
|
mkdir -p "$(dirname "$AUTOSTART_TARGET")"
|
||||||
|
cat "$AUTOSTART_SOURCE" > "$AUTOSTART_TARGET"
|
||||||
|
echo "Installed: $AUTOSTART_TARGET"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# install configuration files first but defer output later
|
||||||
|
# this is to ensure that the prompt runs first in the script
|
||||||
|
INSTALL_CONF_OUTPUT="$(install_configuration_file)"
|
||||||
|
|
||||||
|
# uninstall existing commands
|
||||||
|
uninstall_existing comfortable-swipe
|
||||||
|
uninstall_existing comfortable-swipe-buffer
|
||||||
|
|
||||||
|
# install new binaries
|
||||||
|
echo "Installing binaries ..."
|
||||||
|
install_cpp_program
|
||||||
|
install_main_program
|
||||||
|
echo "$INSTALL_CONF_OUTPUT"
|
||||||
|
install_autostart
|
||||||
|
|
||||||
|
# add permissions to input group (defer)
|
||||||
|
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
||||||
|
|
||||||
|
# make sure comfortable-swipe is in path
|
||||||
|
if ! command -v comfortable-swipe > /dev/null 2>&1; then
|
||||||
|
cat <<EOF >&2
|
||||||
|
WARNING: $(dirname "$TARGET") is not in PATH!
|
||||||
|
Make sure to add the following in your ~/.profile:
|
||||||
|
|
||||||
|
export PATH="$PATH:$(dirname "$TARGET")"
|
||||||
|
|
||||||
|
EOF
|
||||||
fi
|
fi
|
||||||
echo "Installing..."
|
|
||||||
# mkdir -p ~/.local/bin
|
|
||||||
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM || exec echo "Installation aborted"
|
|
||||||
|
|
||||||
GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
cat <<EOF
|
||||||
|
|
||||||
# toggle autostart twice to refresh any changes
|
Successfully installed comfortable-swipe $VERSION
|
||||||
$PROGRAM autostart > /dev/null || abort
|
Autostart switched $("$TARGET" autostart status)
|
||||||
$PROGRAM autostart > /dev/null || abort
|
|
||||||
|
|
||||||
echo "Successfully installed comfortable-swipe."
|
EOF
|
||||||
echo "Configuration file is located at $CONF_PATH"
|
|
||||||
|
# start the program
|
||||||
|
"$TARGET" start
|
||||||
|
|||||||
@ -1,417 +0,0 @@
|
|||||||
/*
|
|
||||||
Comfortable Swipe
|
|
||||||
by Rico Tiongson
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <map>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <cassert>
|
|
||||||
#include <cmath>
|
|
||||||
#include <regex>
|
|
||||||
#include <chrono>
|
|
||||||
#include <ctime>
|
|
||||||
#include <unistd.h>
|
|
||||||
#define cstr const string&
|
|
||||||
#define PROGRAM "/usr/local/bin/comfortable-swipe"
|
|
||||||
#define CONFIG "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
// sudo apt install libxdo-dev
|
|
||||||
#include <xdo.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MASKS FOR GESTURES */
|
|
||||||
|
|
||||||
#define MSK_THREE_FINGERS 0
|
|
||||||
#define MSK_FOUR_FINGERS 1
|
|
||||||
#define MSK_NEGATIVE 0
|
|
||||||
#define MSK_POSITIVE 2
|
|
||||||
#define MSK_HORIZONTAL 0
|
|
||||||
#define MSK_VERTICAL 4
|
|
||||||
|
|
||||||
/* GESTURE MNEMONYMS */
|
|
||||||
#define FRESH -1
|
|
||||||
#define OPPOSITE (mask ^ MSK_POSITIVE)
|
|
||||||
|
|
||||||
/* FORWARD DECLARATIONS */
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
string join(cstr, string[], int);
|
|
||||||
string build_gesture_begin();
|
|
||||||
string build_gesture_update();
|
|
||||||
string build_gesture_end();
|
|
||||||
map<string, string> read_config_file(const char*);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace service {
|
|
||||||
void buffer();
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
void restart();
|
|
||||||
void autostart();
|
|
||||||
void help();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MAIN DRIVER FUNCTION */
|
|
||||||
|
|
||||||
int main(int argc, char** args) {
|
|
||||||
if (argc > 1) {
|
|
||||||
string arg = args[1];
|
|
||||||
// select based on argument
|
|
||||||
if (arg == "start") service::start();
|
|
||||||
else if (arg == "stop") service::stop();
|
|
||||||
else if (arg == "restart") service::restart();
|
|
||||||
else if (arg == "buffer") service::buffer();
|
|
||||||
else if (arg == "autostart") service::autostart();
|
|
||||||
else service::help();
|
|
||||||
} else {
|
|
||||||
service::help();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct swipe_gesture {
|
|
||||||
string device, stamp, fingers;
|
|
||||||
string dx, dy, udx, udy;
|
|
||||||
xdo_t* xdo;
|
|
||||||
virtual void on_update() = 0;
|
|
||||||
virtual void on_begin() = 0;
|
|
||||||
virtual void on_end() = 0;
|
|
||||||
swipe_gesture(): xdo(xdo_new(NULL)) {}
|
|
||||||
~swipe_gesture() {xdo_free(xdo);}
|
|
||||||
};
|
|
||||||
|
|
||||||
const char* const command_map[] = {
|
|
||||||
"left 3",
|
|
||||||
"left 4",
|
|
||||||
"right 3",
|
|
||||||
"right 4",
|
|
||||||
"up 3",
|
|
||||||
"up 4",
|
|
||||||
"down 3",
|
|
||||||
"down 4"
|
|
||||||
};
|
|
||||||
|
|
||||||
struct swipe_gesture_impl : swipe_gesture {
|
|
||||||
int screen_num, ix, iy;
|
|
||||||
float x, y, threshold;
|
|
||||||
int previous_gesture;
|
|
||||||
const char** commands;
|
|
||||||
swipe_gesture_impl(
|
|
||||||
const float threshold,
|
|
||||||
const char* left3 /* 000 */,
|
|
||||||
const char* left4 /* 001 */,
|
|
||||||
const char* right3 /* 010 */,
|
|
||||||
const char* right4 /* 011 */,
|
|
||||||
const char* up3 /* 100 */,
|
|
||||||
const char* up4 /* 101 */,
|
|
||||||
const char* down3 /* 110 */,
|
|
||||||
const char* down4 /* 111 */
|
|
||||||
): swipe_gesture(), threshold(threshold) {
|
|
||||||
commands = new const char*[8];
|
|
||||||
commands[0] = left3;
|
|
||||||
commands[1] = left4;
|
|
||||||
commands[2] = right3;
|
|
||||||
commands[3] = right4;
|
|
||||||
commands[4] = up3;
|
|
||||||
commands[5] = up4;
|
|
||||||
commands[6] = down3;
|
|
||||||
commands[7] = down4;
|
|
||||||
}
|
|
||||||
~swipe_gesture_impl() {
|
|
||||||
delete[] commands;
|
|
||||||
}
|
|
||||||
void key(const char* cmd) const {
|
|
||||||
xdo_send_keysequence_window(xdo, CURRENTWINDOW, cmd, 0);
|
|
||||||
}
|
|
||||||
void on_begin() override {
|
|
||||||
xdo_get_mouse_location(xdo, &ix, &iy, &screen_num);
|
|
||||||
previous_gesture = FRESH;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
void on_update() override {
|
|
||||||
x += stof(dx);
|
|
||||||
y += stof(dy);
|
|
||||||
// scale threshold to 1/10 when gesture is not fresh
|
|
||||||
float scale = previous_gesture == FRESH ?
|
|
||||||
1.0f :
|
|
||||||
0.1f;
|
|
||||||
if (x*x + y*y > threshold*threshold*(scale*scale)) {
|
|
||||||
int mask = 0;
|
|
||||||
if (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
|
||||||
if (fingers == "4") mask |= MSK_FOUR_FINGERS;
|
|
||||||
if (abs(x) > abs(y)) {
|
|
||||||
mask |= MSK_HORIZONTAL;
|
|
||||||
if (x < 0) mask |= MSK_NEGATIVE;
|
|
||||||
else mask |= MSK_POSITIVE;
|
|
||||||
} else {
|
|
||||||
mask |= MSK_VERTICAL;
|
|
||||||
if (y < 0) mask |= MSK_NEGATIVE;
|
|
||||||
else mask |= MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
// send command on fresh OR opposite gesture
|
|
||||||
if (previous_gesture == FRESH or previous_gesture == OPPOSITE) {
|
|
||||||
x = y = 0;
|
|
||||||
previous_gesture = mask;
|
|
||||||
cout << "SWIPE " << command_map[mask] << endl;
|
|
||||||
key(commands[mask]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void on_end() override {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// path services
|
|
||||||
namespace service {
|
|
||||||
// get the full path of the .conf file
|
|
||||||
string conf_filename() {
|
|
||||||
return CONFIG;
|
|
||||||
}
|
|
||||||
// get the full path of the .desktop file associated
|
|
||||||
// with the autostart feature
|
|
||||||
string autostart_filename() {
|
|
||||||
static string *filename = NULL;
|
|
||||||
if (filename == NULL) {
|
|
||||||
const char* xdg_config = getenv("XDG_CONFIG_HOME");
|
|
||||||
string config(
|
|
||||||
xdg_config == NULL
|
|
||||||
? string(getenv("HOME")) + "/.config"
|
|
||||||
: xdg_config
|
|
||||||
);
|
|
||||||
filename = new string(config
|
|
||||||
+ "/autostart/comfortable-swipe.desktop");
|
|
||||||
}
|
|
||||||
return *filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace service {
|
|
||||||
// parses output from libinput-debug-events
|
|
||||||
void buffer() {
|
|
||||||
// check first if $user
|
|
||||||
ios::sync_with_stdio(false);
|
|
||||||
cin.tie(0); cout.tie(0);
|
|
||||||
const regex gesture_begin(util::build_gesture_begin());
|
|
||||||
const regex gesture_update(util::build_gesture_update());
|
|
||||||
const regex gesture_end(util::build_gesture_end());
|
|
||||||
string sentence;
|
|
||||||
// read config file
|
|
||||||
auto config = util::read_config_file(conf_filename().data());
|
|
||||||
// initialize gesture handler
|
|
||||||
swipe_gesture_impl swipe(
|
|
||||||
config.count("threshold") ? stof(config["threshold"]) : 0.0,
|
|
||||||
config["left3"].c_str(),
|
|
||||||
config["left4"].c_str(),
|
|
||||||
config["right3"].c_str(),
|
|
||||||
config["right4"].c_str(),
|
|
||||||
config["up3"].c_str(),
|
|
||||||
config["up4"].c_str(),
|
|
||||||
config["down3"].c_str(),
|
|
||||||
config["down4"].c_str()
|
|
||||||
);
|
|
||||||
while (getline(cin, sentence)) {
|
|
||||||
auto data = sentence.data();
|
|
||||||
cmatch matches;
|
|
||||||
if (regex_match(data, matches, gesture_begin)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.on_begin();
|
|
||||||
}
|
|
||||||
else if (regex_match(data, matches, gesture_end)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.on_end();
|
|
||||||
}
|
|
||||||
else if (regex_match(data, matches, gesture_update)) {
|
|
||||||
swipe.device = matches[1];
|
|
||||||
swipe.stamp = matches[2];
|
|
||||||
swipe.fingers = matches[3];
|
|
||||||
swipe.dx = matches[4];
|
|
||||||
swipe.dy = matches[5];
|
|
||||||
swipe.udx = matches[6];
|
|
||||||
swipe.udy = matches[7];
|
|
||||||
swipe.on_update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// starts service
|
|
||||||
void start() {
|
|
||||||
int x = system("stdbuf -oL -eL libinput-debug-events | " PROGRAM " buffer");
|
|
||||||
}
|
|
||||||
// stops service
|
|
||||||
void stop() {
|
|
||||||
// kill all comfortable-swipe, except self
|
|
||||||
char* buffer = new char[20];
|
|
||||||
FILE* pipe = popen("pgrep -f comfortable-swipe", "r");
|
|
||||||
if (!pipe) throw std::runtime_error("stop command failed");
|
|
||||||
string kill = "kill";
|
|
||||||
while (!feof(pipe)) {
|
|
||||||
if (fgets(buffer, 20, pipe) != NULL) {
|
|
||||||
int pid = atoi(buffer);
|
|
||||||
if (pid != getpid()) {
|
|
||||||
kill += " " + to_string(pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int result = system(kill.data());
|
|
||||||
delete[] buffer;
|
|
||||||
pclose(pipe);
|
|
||||||
}
|
|
||||||
// stops then starts service
|
|
||||||
void restart() {
|
|
||||||
service::stop();
|
|
||||||
service::start();
|
|
||||||
}
|
|
||||||
// toggle automatically start application on startup
|
|
||||||
void autostart() {
|
|
||||||
string path = autostart_filename();
|
|
||||||
if (ifstream(path.data()).good()) {
|
|
||||||
// file found, delete it
|
|
||||||
if (remove(path.data()) != 0)
|
|
||||||
cerr << "Error: failed to switch off autostart. "
|
|
||||||
<< "Maybe the autostart file is in use?"
|
|
||||||
<< endl;
|
|
||||||
else
|
|
||||||
cout << "Autostart switched off" << endl;
|
|
||||||
} else {
|
|
||||||
// file not found, create it
|
|
||||||
int result = system(("mkdir -p $(dirname " + path + ")").data());
|
|
||||||
ofstream fout(path.data());
|
|
||||||
if (result != 0 || !fout.good())
|
|
||||||
cerr << "Error: failed to switch on autostart. "
|
|
||||||
<< "Are you sure you have the permissions?"
|
|
||||||
<< endl;
|
|
||||||
else {
|
|
||||||
fout <<
|
|
||||||
"[Desktop Entry]\n"
|
|
||||||
"Type=Application\n"
|
|
||||||
"Exec=bash -c \"" PROGRAM " start\"\n"
|
|
||||||
"Hidden=false\n"
|
|
||||||
"NoDisplay=false\n"
|
|
||||||
"X-GNOME-Autostart-enabled=true\n"
|
|
||||||
"Name=Comfortable Swipe\n"
|
|
||||||
"Comment=3 or 4 touchpad gestures\n";
|
|
||||||
cout << "Autostart switched on" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// shows help
|
|
||||||
void help() {
|
|
||||||
puts("comfortable-swipe [start|stop|restart|autostart|buffer|help]");
|
|
||||||
puts("");
|
|
||||||
puts("start - starts 3/4-finger gesture service");
|
|
||||||
puts("stop - stops 3/4-finger gesture service");
|
|
||||||
puts("restart - stops then starts 3/4-finger gesture service");
|
|
||||||
puts("autostart - automatically run on startup (toggleable)");
|
|
||||||
puts("buffer - parses output of libinput-debug-events");
|
|
||||||
puts("help - shows the help dialog");
|
|
||||||
puts("");
|
|
||||||
puts((("Configuration file can be found in ") + conf_filename()).data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* UTILITY FUNCTIONS */
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
string number_regex() {
|
|
||||||
return "-?\\d+(?:\\.\\d+)";
|
|
||||||
}
|
|
||||||
|
|
||||||
string join(cstr delim, string arr[], int n) {
|
|
||||||
string ans = arr[0];
|
|
||||||
for (int i = 1; i < n; ++i) {
|
|
||||||
ans += delim;
|
|
||||||
ans += arr[i];
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_begin() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_BEGIN\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
|
||||||
return join("\\s+", arr, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_update() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_UPDATE\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string num_1 = "\\s*(" + number_regex() + ")\\s*";
|
|
||||||
string num_2 = num_1;
|
|
||||||
string num_div = num_1 + "/" + num_2;
|
|
||||||
string num_accel = "\\s*\\(\\s*" + num_div + "\\s*unaccelerated\\s*\\)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers, num_div, num_accel};
|
|
||||||
return join("\\s+", arr, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
string build_gesture_end() {
|
|
||||||
string device = "\\s*(\\S+)\\s*";
|
|
||||||
string gesture = "\\s*GESTURE_SWIPE_END\\s*";
|
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
|
||||||
return join("\\s+", arr, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
map<string, string> read_config_file(const char* filename) {
|
|
||||||
map<string, string> conf;
|
|
||||||
ifstream fin(filename);
|
|
||||||
if (!fin.is_open()) {
|
|
||||||
cerr << "file \"" << filename << "\" does not exist!" << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
string line, key, token, buffer, value;
|
|
||||||
int line_number = 0;
|
|
||||||
while (getline(fin, line)) {
|
|
||||||
++line_number;
|
|
||||||
istringstream is(line);
|
|
||||||
buffer.clear();
|
|
||||||
while (is >> token) {
|
|
||||||
if (token[0] == '#')
|
|
||||||
break;
|
|
||||||
buffer += token;
|
|
||||||
}
|
|
||||||
if (buffer.empty())
|
|
||||||
continue;
|
|
||||||
auto id = buffer.find('=');
|
|
||||||
if (id == string::npos) {
|
|
||||||
cerr << "error in conf file: " << filename << endl;
|
|
||||||
cerr << "equal sign expected in line " << line_number << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
key = buffer.substr(0, id);
|
|
||||||
value = buffer.substr(id + 1);
|
|
||||||
conf[key] = value;
|
|
||||||
}
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
# Comfortable Swipe converts touchpad swipe gestures to keyboard commands. You
|
|
||||||
# may edit this configuration file if you have different keyboard shortcuts
|
|
||||||
# that you would like to use. You can ignore a gesture by commenting out with
|
|
||||||
# a pound(#) symbol.
|
|
||||||
#
|
|
||||||
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a list of
|
|
||||||
# keycodes you can use.
|
|
||||||
|
|
||||||
#################
|
|
||||||
# MISCELLANEOUS #
|
|
||||||
#################
|
|
||||||
|
|
||||||
# Threshold
|
|
||||||
# Tweak this value depending on the sensitivity of your mousepad to perform
|
|
||||||
# gestures. A higher value means less sensitive.
|
|
||||||
# Default: threshold = 0.0
|
|
||||||
threshold = 0.0
|
|
||||||
|
|
||||||
#############################
|
|
||||||
# THREE / FOUR FINGER SWIPE #
|
|
||||||
#############################
|
|
||||||
|
|
||||||
# 3-finger swipe left
|
|
||||||
# The default shortcut is switching to the right workspace.
|
|
||||||
# Default: left3 = ctrl+alt+Right
|
|
||||||
left3 = ctrl+alt+Right
|
|
||||||
|
|
||||||
# 4-finger swipe left
|
|
||||||
# The default shortcut is moving current window to the right workspace.
|
|
||||||
# Default: left4=ctrl+alt+shift+Right
|
|
||||||
left4 = ctrl+alt+shift+Right
|
|
||||||
|
|
||||||
# 3-finger swipe right
|
|
||||||
# The default shortcut is switching to the left workspace.
|
|
||||||
# Default: right3 = ctrl+alt+Left
|
|
||||||
right3 = ctrl+alt+Left
|
|
||||||
|
|
||||||
# 4-finger swipe right
|
|
||||||
# The default shortcut is moving current window to the left workspace.
|
|
||||||
# Default: right4=ctrl+alt+shift+Left
|
|
||||||
right4 = ctrl+alt+shift+Left
|
|
||||||
|
|
||||||
# 3-finger swipe up
|
|
||||||
# The default shortcut is switching to the workspace below.
|
|
||||||
# Default: up3 = ctrl+alt+Down
|
|
||||||
up3 = ctrl+alt+Down
|
|
||||||
|
|
||||||
# 4-finger swipe up
|
|
||||||
# The default shortcut is moving current window to the bottom workspace.
|
|
||||||
# Default: ctrl+alt+shift+Down
|
|
||||||
up4 = ctrl+alt+shift+Down
|
|
||||||
|
|
||||||
# 3-finger swipe down
|
|
||||||
# The default shortcut is switching to the workspace above.
|
|
||||||
# Default: down3 = ctrl+alt+Up
|
|
||||||
down3 = ctrl+alt+Up
|
|
||||||
|
|
||||||
# 4-finger swipe down
|
|
||||||
# The default shortcut is moving current window to the above workspace.
|
|
||||||
# Default: ctrl+alt+shift+Up
|
|
||||||
down4 = ctrl+alt+shift+Up
|
|
||||||
28
tests/run_tests
Executable file
28
tests/run_tests
Executable file
@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DIR="$(dirname "$0")"
|
||||||
|
COMPILER="$(dirname "$DIR")/compile"
|
||||||
|
|
||||||
|
# just call abort on error
|
||||||
|
TEMPOUT="$(mktemp)"
|
||||||
|
abort () {
|
||||||
|
rm "$tempout"
|
||||||
|
echo "Test aborted"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# run all shell files in this directory
|
||||||
|
for SH in "$DIR/test_"*.sh; do
|
||||||
|
"$SH" || abort
|
||||||
|
done
|
||||||
|
|
||||||
|
# run all cpp files in this directory
|
||||||
|
for CPP in "$DIR/test_"*.cpp; do
|
||||||
|
# compile the test
|
||||||
|
"$COMPILER" "$CPP" -o "$TEMPOUT" || abort
|
||||||
|
# run the test
|
||||||
|
chmod +x "$TEMPOUT"
|
||||||
|
"$TEMPOUT"
|
||||||
|
done
|
||||||
88
tests/test_regex.cpp
Normal file
88
tests/test_regex.cpp
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#include "../comfortable-swipe-gesture-swipe.cpp"
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
#include <regex>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
void gesture_begin_should_match_regex();
|
||||||
|
void gesture_update_should_match_regex();
|
||||||
|
void gesture_end_should_match_regex();
|
||||||
|
} // namespace test
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::cout << "(1) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_begin_should_match_regex();
|
||||||
|
|
||||||
|
std::cout << "(2) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_update_should_match_regex();
|
||||||
|
|
||||||
|
std::cout << "(3) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
|
test::gesture_end_should_match_regex();
|
||||||
|
std::cout << "ALL TEST PASSED" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace test {
|
||||||
|
void gesture_begin_test(const std::regex &matcher, const char *data,
|
||||||
|
const char *expected_fingers) {
|
||||||
|
std::cout << " testing against \"" << data << "\"...";
|
||||||
|
std::cmatch matches;
|
||||||
|
int result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string)matches[1] == expected_fingers);
|
||||||
|
std::cout << "PASSED" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_begin_should_match_regex() {
|
||||||
|
std::regex matcher = comfortable_swipe::gesture_swipe::GESTURE_SWIPE_BEGIN;
|
||||||
|
test::gesture_begin_test(matcher, " event15 GESTURE_SWIPE_BEGIN +34.33s 3\n",
|
||||||
|
"3");
|
||||||
|
test::gesture_begin_test(matcher, "-event4 GESTURE_SWIPE_BEGIN +3.12s 4\n",
|
||||||
|
"4");
|
||||||
|
test::gesture_begin_test(matcher, "-event7 GESTURE_SWIPE_BEGIN +4.72s 3\n",
|
||||||
|
"3");
|
||||||
|
test::gesture_begin_test(matcher, " event9 GESTURE_SWIPE_BEGIN +45.80s 4\n",
|
||||||
|
"4");
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_update_should_match_regex() {
|
||||||
|
const char *data = " event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 "
|
||||||
|
"(-0.33/13.50 unaccelerated)\n";
|
||||||
|
std::regex matcher = comfortable_swipe::gesture_swipe::GESTURE_SWIPE_UPDATE;
|
||||||
|
std::cmatch matches;
|
||||||
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string)matches[1] == "3");
|
||||||
|
assert((std::string)matches[2] == "-0.12");
|
||||||
|
assert((std::string)matches[3] == "4.99");
|
||||||
|
assert((std::string)matches[4] == "-0.33");
|
||||||
|
assert((std::string)matches[5] == "13.50");
|
||||||
|
}
|
||||||
|
|
||||||
|
void gesture_end_should_match_regex() {
|
||||||
|
const char *data = " event15 GESTURE_SWIPE_END +35.03s 3\n";
|
||||||
|
std::regex matcher = comfortable_swipe::gesture_swipe::GESTURE_SWIPE_END;
|
||||||
|
std::cmatch matches;
|
||||||
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
|
assert(result != 0);
|
||||||
|
assert((std::string)matches[1] == "3");
|
||||||
|
}
|
||||||
|
} // namespace test
|
||||||
103
tests/test_swipe.sh
Executable file
103
tests/test_swipe.sh
Executable file
@ -0,0 +1,103 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
DIR="$(dirname "$0")"
|
||||||
|
ROOT="$(dirname "$DIR")"
|
||||||
|
COMPILER="$ROOT/compile"
|
||||||
|
|
||||||
|
# just call abort on error
|
||||||
|
TEMPOUT="$(mktemp)"
|
||||||
|
abort () {
|
||||||
|
echo "Test aborted"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# try to compile main test
|
||||||
|
# use empty configuration /dev/null
|
||||||
|
EMPTY_CONFIG="$(mktemp)"
|
||||||
|
echo "threshold = 0.0" >> "$EMPTY_CONFIG"
|
||||||
|
"$COMPILER" "$ROOT/comfortable-swipe-main.cpp" -o "$TEMPOUT" \
|
||||||
|
-DCOMFORTABLE_SWIPE_AUTOSTART="\"$ROOT/comfortable-swipe.desktop\"" \
|
||||||
|
-DCOMFORTABLE_SWIPE_CONFIG="\"$EMPTY_CONFIG\"" \
|
||||||
|
|| abort
|
||||||
|
chmod +x "$TEMPOUT"
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
|
# try to run start, then wait for the user to swipe
|
||||||
|
echo "Simulating swipe..."
|
||||||
|
|
||||||
|
# get output result
|
||||||
|
OUTPUT="$(mktemp)"
|
||||||
|
"$TEMPOUT" <<EOF > "$OUTPUT"
|
||||||
|
event7 GESTURE_SWIPE_BEGIN +1.72s 3
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.72s 3 -12.26/-0.42 (-33.14/-1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.73s 3 -14.08/ 0.00 (-38.06/ 0.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.74s 3 -15.78/-0.42 (-42.65/-1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.75s 3 -16.63/-0.14 (-44.95/-0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.75s 3 -16.63/-0.42 (-44.95/-1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.76s 3 -16.39/ 0.14 (-44.29/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.77s 3 -15.66/ 0.28 (-42.32/ 0.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.78s 3 -13.96/ 0.55 (-37.73/ 1.50 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.78s 3 -12.38/ 0.28 (-33.46/ 0.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.79s 3 -10.56/ 0.55 (-28.54/ 1.50 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.80s 3 -8.86/ 0.69 (-23.95/ 1.87 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.81s 3 -6.92/ 1.53 (-18.70/ 4.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.81s 3 -5.10/ 1.53 (-13.78/ 4.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.82s 3 -4.13/ 1.39 (-11.15/ 3.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.83s 3 -3.40/ 0.97 (-9.19/ 2.62 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.84s 3 -2.43/ 0.97 (-6.56/ 2.62 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.84s 3 -1.82/ 0.69 (-4.92/ 1.87 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.85s 3 -0.97/ 0.69 (-2.62/ 1.87 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.86s 3 -0.36/ 0.69 (-0.98/ 1.87 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.87s 3 -0.24/ 0.42 (-0.66/ 1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.88s 3 0.23/ 0.26 ( 0.66/ 0.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.88s 3 0.99/ 0.13 ( 2.95/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.89s 3 2.31/ 0.42 ( 6.23/ 1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.90s 3 3.88/ 0.97 (10.50/ 2.62 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.91s 3 7.65/ 0.55 (20.67/ 1.50 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.91s 3 12.26/ 0.55 (33.14/ 1.50 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.92s 3 17.36/-0.42 (46.92/-1.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.93s 3 21.73/-1.25 (58.73/-3.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.94s 3 24.64/-2.64 (66.60/-7.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.94s 3 26.95/-3.75 (72.83/-10.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.95s 3 27.80/-4.72 (75.13/-12.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.96s 3 27.07/-4.86 (73.16/-13.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.97s 3 25.49/-5.27 (68.90/-14.25 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.97s 3 23.06/-4.72 (62.34/-12.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.98s 3 20.15/-4.16 (54.46/-11.25 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +1.99s 3 17.24/-3.33 (46.59/-9.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.00s 3 13.84/-2.64 (37.40/-7.12 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.00s 3 10.80/-1.80 (29.20/-4.87 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.01s 3 7.77/-0.83 (21.00/-2.25 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.02s 3 5.46/ 0.14 (14.76/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.03s 3 3.03/ 0.28 ( 8.20/ 0.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.04s 3 1.82/ 0.00 ( 4.92/ 0.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.04s 3 0.61/-0.28 ( 1.64/-0.75 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.05s 3 0.24/-0.14 ( 0.66/-0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.06s 3 -0.22/ 0.13 (-0.66/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.07s 3 0.00/ 0.06 ( 0.00/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.09s 3 -0.05/ 0.06 (-0.33/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.10s 3 -0.05/ 0.00 (-0.33/ 0.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.10s 3 -0.05/ 0.05 (-0.33/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.11s 3 -0.05/ 0.06 (-0.33/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.12s 3 0.05/ 0.00 ( 0.33/ 0.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.13s 3 -0.11/ 0.00 (-0.66/ 0.00 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.13s 3 0.00/ 0.07 ( 0.00/ 0.37 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_UPDATE +2.14s 3 -2.41/-0.50 (-7.22/-1.50 unaccelerated)
|
||||||
|
event7 GESTURE_SWIPE_END +2.19s 3
|
||||||
|
EOF
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT="SWIPE left3 SWIPE right3"
|
||||||
|
ACTUAL_OUTPUT="$(cat "$OUTPUT" | xargs)"
|
||||||
|
echo "My output: $ACTUAL_OUTPUT"
|
||||||
|
echo "Expected: $EXPECTED_OUTPUT"
|
||||||
|
|
||||||
|
if [[ "$ACTUAL_OUTPUT" == "$EXPECTED_OUTPUT" ]]; then
|
||||||
|
echo "PASSED"
|
||||||
|
else
|
||||||
|
echo "Did not match expected output:" >&2
|
||||||
|
echo "$EXPECTED_OUTPUT" >&2
|
||||||
|
abort
|
||||||
|
fi
|
||||||
42
uninstall
42
uninstall
@ -1,7 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
echo "Uninstalling..."
|
|
||||||
rm ${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop 2> /dev/null
|
set -e
|
||||||
comfortable-swipe stop 2> /dev/null
|
|
||||||
rm $HOME/.local/bin/comfortable-swipe 2> /dev/null # compat
|
function trysudo {
|
||||||
rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
$@ 2> /dev/null || sudo $@
|
||||||
echo "Successfully uninstalled comfortable-swipe"
|
}
|
||||||
|
|
||||||
|
function uninstall {
|
||||||
|
TARGET="${1?missing uninstall parameter}"
|
||||||
|
if [[ -f "$TARGET" ]]; then
|
||||||
|
trysudo rm -f "$TARGET"
|
||||||
|
echo "Removed: $TARGET"
|
||||||
|
elif [[ ! -z "$TARGET" ]]; then
|
||||||
|
echo "Not found: $TARGET"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# stop program first if it is still running
|
||||||
|
comfortable-swipe stop 2> /dev/null || true
|
||||||
|
|
||||||
|
# uninstall binaries
|
||||||
|
uninstall "$(which comfortable-swipe || echo /usr/share/bin/comfortable-swipe)"
|
||||||
|
uninstall "$(which comfortable-swipe-buffer || echo /usr/share/bin/comfortable-swipe-buffer)"
|
||||||
|
|
||||||
|
# uninstall desktop file
|
||||||
|
uninstall "$HOME/.config/autostart/comfortable-swipe.desktop"
|
||||||
|
|
||||||
|
# tell user we are keeping configuration file
|
||||||
|
CONF_TARGET="$HOME/.config/comfortable-swipe.conf"
|
||||||
|
if [ -f "$CONF_TARGET" ]; then
|
||||||
|
echo "Keeping your configuration file: $CONF_TARGET"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
Successfully uninstalled comfortable-swipe
|
||||||
|
EOF
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user