Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2f68a97cc | ||
|
|
cd29704495 | ||
|
|
6a6bbf52e9 | ||
|
|
cb51d47a60 | ||
|
|
1ecfc79fc4 | ||
|
|
92863711b0 | ||
|
|
a7c5b6d578 | ||
|
|
8f6e231a5e | ||
|
|
dda91b7178 | ||
|
|
4852993663 | ||
|
|
810a20f1ed |
No files matched your search
-120
@@ -4,123 +4,3 @@
|
|||||||
# IDE-specific
|
# IDE-specific
|
||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# PYTHON
|
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
!/lib
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
pip-wheel-metadata/
|
|
||||||
share/python-wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# PyInstaller
|
|
||||||
# Usually these files are written by a python script from a template
|
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
||||||
*.manifest
|
|
||||||
*.spec
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.nox/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
db.sqlite3
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# IPython
|
|
||||||
profile_default/
|
|
||||||
ipython_config.py
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
.python-version
|
|
||||||
|
|
||||||
# celery beat schedule file
|
|
||||||
celerybeat-schedule
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Environments
|
|
||||||
.env
|
|
||||||
.venv
|
|
||||||
env/
|
|
||||||
venv/
|
|
||||||
ENV/
|
|
||||||
env.bak/
|
|
||||||
venv.bak/
|
|
||||||
|
|
||||||
# Spyder project settings
|
|
||||||
.spyderproject
|
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
|
||||||
/site
|
|
||||||
|
|
||||||
# mypy
|
|
||||||
.mypy_cache/
|
|
||||||
.dmypy.json
|
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
dist: xenial
|
|
||||||
language: python
|
|
||||||
sudo: required
|
|
||||||
python:
|
|
||||||
- 2.7
|
|
||||||
- 3.5
|
|
||||||
- 3.6
|
|
||||||
- 3.7
|
|
||||||
- 3.8-dev
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
update: true
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- libxdo-dev
|
|
||||||
- libinput-tools
|
|
||||||
- g++-7
|
|
||||||
env:
|
|
||||||
CC: gcc-7
|
|
||||||
CXX: g++-7
|
|
||||||
install:
|
|
||||||
- pip install .
|
|
||||||
script:
|
|
||||||
- python setup.py test
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
@@ -1 +0,0 @@
|
|||||||
include comfortable_swipe/res/comfortable-swipe.desktop
|
|
||||||
@@ -1,117 +1,274 @@
|
|||||||
# Comfortable Swipe (Debian/Ubuntu)
|
# Comfortable Swipe (Ubuntu)
|
||||||
|
|
||||||
[](https://github.com/Hikari9/comfortable-swipe/releases)
|
[](https://github.com/Hikari9/comfortable-swipe/releases)
|
||||||
[](https://github.com/Hikari9/comfortable-swipe/commits/master)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
[](https://github.com/Hikari9/comfortable-swipe/commits/develop)
|
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
|
||||||
|
|
||||||
Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures. Tested in Ubuntu 14.04 LTS and beyond, for Unity, GNOME, and KDE desktop environments.
|
> **_New in Version 1.1.0!_** Added mouse gestures, see [#mouse-gestures-experimental](#mouse-gestures-experimental)
|
||||||
|
|
||||||
> **Note**: May work for other Linux distros that support `libinput` and `libxdo` (untested).
|
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`.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Update and install essential tools and libraries
|
1. Install git, libinput, and g++
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt update && sudo apt install git g++-7 python3-pip libinput-tools libxdo-dev
|
sudo apt-get install git libinput-tools libxdo-dev g++
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Install `comfortable-swipe` for your user
|
2. Clone this repository
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip3 install --user git+https://github.com/Hikari9/comfortable-swipe
|
git clone https://github.com/Hikari9/comfortable-swipe.git --depth 1
|
||||||
|
cd comfortable-swipe
|
||||||
```
|
```
|
||||||
|
|
||||||
3. You can check status with `comfortable-swipe status`
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$> comfortable-swipe status
|
git clone https://github.com/Hikari9/comfortable-swipe.git --depth 1
|
||||||
usr/local/share/comfortable-swipe/comfortable-swipe.conf
|
cd comfortable-swipe
|
||||||
threshold = 0.0
|
|
||||||
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
|
|
||||||
autostart is ON
|
|
||||||
comfortable-swipe program is STOPPED
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. You can list down all commands with `comfortable-swipe` or `comfortable-swipe help`
|
3. Install
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$> comfortable-swipe
|
bash install
|
||||||
comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]
|
|
||||||
|
|
||||||
start - starts 3/4-finger gesture service
|
|
||||||
stop - stops 3/4-finger gesture service
|
|
||||||
restart - stops then starts 3/4-finger gesture service
|
|
||||||
autostart - automatically run on startup (toggleable)
|
|
||||||
buffer - parses output of libinput debug-events
|
|
||||||
help - shows the help dialog
|
|
||||||
config - locates the config file
|
|
||||||
debug - logs raw output from input events taken from libinput
|
|
||||||
status - checks status of program and autostart
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4. 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
|
```bash
|
||||||
sudo gpasswd -a $USER $(ls -l /dev/input/event* | awk '{print $4}' | head --line=1)
|
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
|
2. **_Important_**: After inputing your `sudo` password, log out then log back in
|
||||||
3. By default, comfortable-swipe should be running. Otherwise, run:
|
3. Run
|
||||||
```bash
|
```
|
||||||
comfortable-swipe start
|
comfortable-swipe start
|
||||||
```
|
```
|
||||||
You can see if gestures work correctly if you see `SWIPE xxx` in the output:
|
4. _Optional_: Automatically run on startup
|
||||||
|
```
|
||||||
```bash
|
comfortable-swipe autostart
|
||||||
$> comfortable-swipe start
|
```
|
||||||
SWIPE left3
|
5. Check the status of your application by running
|
||||||
SWIPE right3
|
```
|
||||||
...
|
comfortable-swipe status
|
||||||
```
|
```
|
||||||
|
|
||||||
## How to Upgrade
|
## Swipe Configurations
|
||||||
|
|
||||||
```bash
|
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running:
|
||||||
pip3 install -U --user git+https://github.com/Hikari9/comfortable-swipe
|
|
||||||
|
```
|
||||||
|
gedit $(comfortable-swipe config)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Uninstall
|
| Property | Description | Default Value | Default Behavior |
|
||||||
|
| --------- | :------------------------------------------: | -------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| left3 | 3-finger swipe left | ctrl+alt+Right | switch to right workspace |
|
||||||
|
| left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace |
|
||||||
|
| right3 | 3-finger swipe right | ctrl+alt+Left | switch to left workspace |
|
||||||
|
| right4 | 4-finger swipe right | ctrl+alt+shift+Left | move window to left workspace |
|
||||||
|
| up3 | 3-finger swipe up | ctrl+alt+Down | switch to bottom workspace |
|
||||||
|
| up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace |
|
||||||
|
| down3 | 3-finger swipe down | ctrl+alt+Up | switch to above workspace |
|
||||||
|
| down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace |
|
||||||
|
| threshold | mouse pixels to activate swipe | 0.0 | tweak this if you're having troubles with touchpad sensitivity (higher = less sensitive, values can be as large as 1000.0) |
|
||||||
|
| hold3 | holds a mouse button when 3 fingers are down | (none) | See [Mouse Gestures (Experimental)](#mouse-gestures-experimental) |
|
||||||
|
| hold4 | holds a mouse button when 4 fingers are down | (none) | See [Mouse Gestures (Experimental)](#mouse-gestures-experimental) |
|
||||||
|
|
||||||
```bash
|
After making changes, make sure to restart the program:
|
||||||
# Uncomment below to COMPLETELY remove configurations (not recommended)
|
|
||||||
# rm $(comfortable-swipe config)
|
|
||||||
|
|
||||||
pip3 uninstall comfortable-swipe
|
```
|
||||||
|
comfortable-swipe restart
|
||||||
```
|
```
|
||||||
|
|
||||||
## Other Commands
|
Taken from `man xdotool`:
|
||||||
|
|
||||||
1. `comfortable-swipe config` - outputs location of configuration file
|
> 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.
|
||||||
|
|
||||||
|
**Keyboard Shortcuts**:
|
||||||
|
|
||||||
|
- Unity: https://cheatography.com/sapemeg/cheat-sheets/ubuntu-unity-16-04/
|
||||||
|
- GNOME: https://wiki.gnome.org/Design/OS/KeyboardShortcuts
|
||||||
|
- KDE: https://community.linuxmint.com/tutorial/view/47
|
||||||
|
|
||||||
|
## Swipe Gesture Templates
|
||||||
|
|
||||||
|
1. Switching workspaces
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$> comfortable-swipe config
|
# Unity, KDE
|
||||||
/usr/local/share/comfortable-swipe/comfortable-swipe.conf
|
left3 = ctrl+alt+Right
|
||||||
|
right3 = ctrl+alt+Left
|
||||||
|
up3 = ctrl+alt+Down
|
||||||
|
down3 = ctrl+alt+Up
|
||||||
```
|
```
|
||||||
|
|
||||||
2. `comfortable-swipe autostart` - Toggles autostart
|
|
||||||
```bash
|
```bash
|
||||||
$> comfortable-swipe autostart
|
# GNOME
|
||||||
Autostart switched off
|
up3 = super+PgDown
|
||||||
|
down3 = super+PgUp
|
||||||
```
|
```
|
||||||
|
|
||||||
3. `comfortable-swipe debug` - Debugs input (this is an unbuffered alias of `libinput debug-events`)
|
1. Move window to workspace
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$> comfortable-swipe debug
|
# Unity, KDE
|
||||||
|
left4 = ctrl+alt+shift+Right
|
||||||
|
right4 = ctrl+alt+shift+Left
|
||||||
|
up4 = ctrl+alt+shift+Down
|
||||||
|
down4 = ctrl+alt+shift+Up
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GNOME
|
||||||
|
up4 = super+shift+PgDown
|
||||||
|
down4 = super+shift+PgUp
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Move window to other monitor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GNOME
|
||||||
|
left4 = super+shift+Right
|
||||||
|
right4 = super+shift+Left
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle workspace overview
|
||||||
|
|
||||||
|
```bash
|
||||||
|
up3 = super+s
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Show desktop ([setup manually](https://www.itsupportguides.com/knowledge-base/ubuntu/ubuntu-how-to-make-windows-d-show-desktop/))
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Ubuntu
|
||||||
|
down3 = ctrl+super+d
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# GNOME
|
||||||
|
down3 = super+d
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# KDE
|
||||||
|
down3 = ctrl+alt+d
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Snap windows to the left/right
|
||||||
|
|
||||||
|
```bash
|
||||||
|
left3 = super+Left
|
||||||
|
right3 = super+Right
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle maximize
|
||||||
|
|
||||||
|
```bash
|
||||||
|
up3 = super+Up
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Toggle minimize
|
||||||
|
|
||||||
|
```bash
|
||||||
|
down3 = super+Down
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Alt+Tab switch application (experimental)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
left3 = alt+Tab
|
||||||
|
right3 = alt+shift+Tab
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mouse Gestures (Experimental)
|
||||||
|
|
||||||
|
We have included simple mouse gestures on swipe by setting `hold3` and `hold4`.
|
||||||
|
|
||||||
|
**Possible Values**:
|
||||||
|
|
||||||
|
- `move` - just move the mouse cursor (no mousedown)
|
||||||
|
- `button1` - hold left click on finger swipe
|
||||||
|
- `button2` - hold middle click on finger swipe
|
||||||
|
- `button3` - hold right click on finger swipe
|
||||||
|
- `button4` - wheel up on finger swipe (experimental)
|
||||||
|
- `button5` - wheel down on finger swipe (experimental)
|
||||||
|
- `scroll` - naive 3/4 finger natural scroll (no acceleration, very experimental)
|
||||||
|
- `scroll_reverse` - naive 3/4 finger reverse scroll (no acceleration, very experimental)
|
||||||
|
|
||||||
|
Any value not mentioned above disables the mouse-hold.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
1. 3-finger drag
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold3 = button1
|
||||||
|
```
|
||||||
|
|
||||||
|
1. 4-finger drag (with middle click)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold4 = button2
|
||||||
|
```
|
||||||
|
|
||||||
|
1. 3-finger natural scroll
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold3 = scroll
|
||||||
|
```
|
||||||
|
|
||||||
|
1. 4-finger reverse scroll
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold4 = scroll_reverse
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Just move the cursor
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold3 = move
|
||||||
|
hold4 = move
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Any other command will disable the mouse hold
|
||||||
|
|
||||||
|
```bash
|
||||||
|
hold3 = disabled
|
||||||
|
hold4 = nothing
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note**: Applying any mouse-hold configuration will disable up/left/right/down behavior to avoid gesture conflicts. The logic of this will be improved in the future.
|
||||||
|
|
||||||
|
## 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 DEVICE_ADDED TouchPad seat0 default group7 cap:pg size 70x50mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on
|
||||||
...
|
...
|
||||||
@@ -133,47 +290,24 @@ pip3 uninstall comfortable-swipe
|
|||||||
|
|
||||||
If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supports multi-touch swipe gestures.
|
If you can see `GESTURE_SWIPE_XXX` in your output, that means your touchpad supports multi-touch swipe gestures.
|
||||||
|
|
||||||
## Configurations
|
## Uninstall
|
||||||
|
|
||||||
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
|
Download the `uninstall` script then run `bash uninstall`
|
||||||
|
|
||||||
```bash
|
|
||||||
gedit $(comfortable-swipe config)
|
|
||||||
```
|
|
||||||
|
|
||||||
Make sure to restart after making changes:
|
|
||||||
```bash
|
|
||||||
comfortable-swipe restart
|
|
||||||
```
|
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
|
||||||
--------- | ----------- | -------------- | -----
|
|
||||||
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point (Note: Sky is the limit! Can be as large as 1000.0) | 0.0
|
|
||||||
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
|
|
||||||
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
|
|
||||||
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
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
## 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)`
|
||||||
Whitespace-only changes.
@@ -1,28 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from comfortable_swipe.autostart import toggle_status
|
|
||||||
from comfortable_swipe.constants import CONFIG
|
|
||||||
from comfortable_swipe.status import print_status
|
|
||||||
|
|
||||||
from comfortable_swipe.cpp import service as cpp_service
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) <= 1:
|
|
||||||
cpp_service.help()
|
|
||||||
else:
|
|
||||||
dict(
|
|
||||||
start=cpp_service.start,
|
|
||||||
stop=cpp_service.stop,
|
|
||||||
restart=cpp_service.restart,
|
|
||||||
buffer=cpp_service.buffer,
|
|
||||||
help=cpp_service.help,
|
|
||||||
debug=cpp_service.debug,
|
|
||||||
status=print_status,
|
|
||||||
autostart=lambda: print('Autostart switched', toggle_status()),
|
|
||||||
config=lambda: print(CONFIG),
|
|
||||||
)[sys.argv[1]]()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Add header files will be imported here.
|
||||||
|
* You can import this as a shorthand:
|
||||||
|
*
|
||||||
|
* #include "../all_headers.hpp"
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__all_headers_hpp__
|
||||||
|
#define __COMFORTABLE_SWIPE__all_headers_hpp__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// global defines
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__PROGRAM__
|
||||||
|
#define __COMFORTABLE_SWIPE__PROGRAM__ "/usr/local/bin/comfortable-swipe"
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__PROGRAM__ */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__CONFIG__
|
||||||
|
#define __COMFORTABLE_SWIPE__CONFIG__ \
|
||||||
|
"/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */
|
||||||
|
|
||||||
|
#ifndef COMFORTABLE_SWIPE_VERSION
|
||||||
|
#warning COMFORTABLE_SWIPE_VERSION is not defined
|
||||||
|
#define COMFORTABLE_SWIPE_VERSION "v(UNKNOWN)"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_VERSION */
|
||||||
|
|
||||||
|
#include <map> // std::map
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
namespace comfortable_swipe {
|
||||||
|
// driver method
|
||||||
|
int driver();
|
||||||
|
// this is found in the util/ folder
|
||||||
|
namespace util {
|
||||||
|
const char *autostart_filename();
|
||||||
|
constexpr const char *conf_filename();
|
||||||
|
std::map<std::string, std::string> read_config_file(const char *);
|
||||||
|
} // namespace util
|
||||||
|
// this is found in the service/ folder
|
||||||
|
namespace service {
|
||||||
|
void autostart();
|
||||||
|
void buffer();
|
||||||
|
void config();
|
||||||
|
void debug();
|
||||||
|
void help();
|
||||||
|
void restart();
|
||||||
|
void start();
|
||||||
|
void status();
|
||||||
|
void stop();
|
||||||
|
} // namespace service
|
||||||
|
} // namespace comfortable_swipe
|
||||||
|
}
|
||||||
|
|
||||||
|
// add headers for classes here so it can be imported during include
|
||||||
|
#include "gesture/keyboard_swipe_gesture.h"
|
||||||
|
#include "gesture/mouse_hold_gesture.h"
|
||||||
|
#include "gesture/swipe_gesture.h"
|
||||||
|
#include "gesture/xdo_gesture.h"
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__all_headers_hpp__ */
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from comfortable_swipe.constants import NAME, RES, exe
|
|
||||||
|
|
||||||
|
|
||||||
# status enums
|
|
||||||
OFF = 'off'
|
|
||||||
ON = 'on'
|
|
||||||
|
|
||||||
|
|
||||||
# the target path to the autostart desktop file
|
|
||||||
def target_path():
|
|
||||||
return os.path.join(
|
|
||||||
os.getenv(
|
|
||||||
'XDG_CONFIG_HOME',
|
|
||||||
os.path.join(os.getenv('HOME'), '.config')
|
|
||||||
),
|
|
||||||
'autostart',
|
|
||||||
'{}.desktop'.format(NAME)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# path to the autostart template file to be copied
|
|
||||||
def template_path():
|
|
||||||
return os.path.join(RES, '{}.desktop'.format(NAME))
|
|
||||||
|
|
||||||
|
|
||||||
# parsed contents of the template file
|
|
||||||
def template(raw=False):
|
|
||||||
with open(template_path(), 'r') as file:
|
|
||||||
contents = file.read()
|
|
||||||
if raw:
|
|
||||||
return contents
|
|
||||||
return contents.replace('Exec=' + NAME, 'Exec={} {}'.format(sys.executable, exe()))
|
|
||||||
|
|
||||||
|
|
||||||
# gets the current autostart status
|
|
||||||
def get_status():
|
|
||||||
return ON if os.path.exists(target_path()) else OFF
|
|
||||||
|
|
||||||
|
|
||||||
# sets the autostart status
|
|
||||||
def set_status(status=ON):
|
|
||||||
if status == ON:
|
|
||||||
# make sure dir exists
|
|
||||||
path = target_path()
|
|
||||||
path_dir = os.path.dirname(path)
|
|
||||||
if not os.path.exists(path_dir):
|
|
||||||
os.makedirs(path_dir)
|
|
||||||
with open(target_path(), 'w') as file:
|
|
||||||
file.write(template())
|
|
||||||
elif status == OFF:
|
|
||||||
if os.path.exists(target_path()):
|
|
||||||
os.remove(target_path())
|
|
||||||
else:
|
|
||||||
raise ValueError('invalid status for autostart')
|
|
||||||
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
# toggles autostart status
|
|
||||||
def toggle_status():
|
|
||||||
return set_status(OFF if get_status() == ON else ON)
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from distutils.spawn import find_executable
|
|
||||||
|
|
||||||
|
|
||||||
NAME = 'comfortable-swipe'
|
|
||||||
DESCRIPTION = 'Comfortable 3-finger and 4-finger swipe gestures'
|
|
||||||
BIN = os.path.dirname(sys.executable)
|
|
||||||
DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
PYTHON_NAME = os.path.basename(DIR)
|
|
||||||
RES = os.path.join(DIR, 'res')
|
|
||||||
CONFIG = os.path.join(sys.prefix, 'local', 'share', NAME, '{}.conf'.format(NAME))
|
|
||||||
DEFAULT_CONFIG = os.path.join(RES, 'defaults.conf')
|
|
||||||
|
|
||||||
def exe():
|
|
||||||
return find_executable(NAME)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
# This is a placeholder module that will contain the C++ libraries.
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__driver__
|
||||||
|
#define __COMFORTABLE_SWIPE__driver__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "all_headers.hpp"
|
||||||
|
#include <cstdio> // fgets_unlocked, stdin
|
||||||
|
#include <iostream> // std::ios, std::cout, std::cin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main driver program.
|
||||||
|
*/
|
||||||
|
namespace comfortable_swipe {
|
||||||
|
int driver() {
|
||||||
|
// unsync for faster IO
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(0);
|
||||||
|
std::cout.tie(0);
|
||||||
|
std::cout.flush();
|
||||||
|
|
||||||
|
// read config file
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(
|
||||||
|
comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// initialize mouse hold gesture handler
|
||||||
|
// for now, this supports 3-finger and 4-finger hold
|
||||||
|
// Examples:
|
||||||
|
// hold3=move move mouse on 3 fingers
|
||||||
|
// hold3=button1 hold button 1 on 3 fingers
|
||||||
|
// hold4=button3 hold button 3 (right click) on 3 fingers
|
||||||
|
// hold3=ignore <do nothing>
|
||||||
|
comfortable_swipe::gesture::mouse_hold_gesture mouse_hold(
|
||||||
|
config["hold3"].c_str(), config["hold4"].c_str());
|
||||||
|
|
||||||
|
// initialize keyboard swipe gesture handler
|
||||||
|
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe(
|
||||||
|
config.count("threshold") ? std::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());
|
||||||
|
|
||||||
|
// prepare data containers
|
||||||
|
std::array<char, 256> line;
|
||||||
|
|
||||||
|
// start reading lines from input one by one
|
||||||
|
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL) {
|
||||||
|
// prioritize mouse hold gesture first
|
||||||
|
mouse_hold.parse_line(line.data());
|
||||||
|
|
||||||
|
// if mouse hold fails, try keyboard hold
|
||||||
|
if (!mouse_hold.is_mousedown()) {
|
||||||
|
// attempt to parse keyboard gestures
|
||||||
|
keyboard_swipe.parse_line(line.data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__driver__ */
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "keyboard_swipe_gesture.h"
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture {
|
||||||
|
|
||||||
|
/* STATICS DEFINITIONS */
|
||||||
|
const int keyboard_swipe_gesture::MSK_THREE_FINGERS = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
|
const int keyboard_swipe_gesture::MSK_NEGATIVE = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_POSITIVE = 2;
|
||||||
|
const int keyboard_swipe_gesture::MSK_HORIZONTAL = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_VERTICAL = 4;
|
||||||
|
const int keyboard_swipe_gesture::FRESH = -1;
|
||||||
|
const char *const keyboard_swipe_gesture::command_map[8] = {
|
||||||
|
"left3", "left4", "right3", "right4", "up3", "up4", "down3", "down4"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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).
|
||||||
|
*/
|
||||||
|
keyboard_swipe_gesture::keyboard_swipe_gesture(
|
||||||
|
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 */
|
||||||
|
)
|
||||||
|
: // construct superclass
|
||||||
|
comfortable_swipe::gesture::swipe_gesture(),
|
||||||
|
// compute square of threshold because we will use squared distances
|
||||||
|
threshold_squared(threshold * threshold),
|
||||||
|
// register our commands
|
||||||
|
commands(new const char *[8] {
|
||||||
|
left3, left4, right3, right4, up3, up4, down3, down4
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this keyboard swipe gesture.
|
||||||
|
*/
|
||||||
|
keyboard_swipe_gesture::~keyboard_swipe_gesture() { delete[] commands; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::begin() {
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::begin();
|
||||||
|
|
||||||
|
// assign previous gesture to FRESH
|
||||||
|
this->previous_gesture = keyboard_swipe_gesture::FRESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::update() {
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::update();
|
||||||
|
|
||||||
|
// scale threshold to 1/10 when gesture is not fresh
|
||||||
|
float scale = this->previous_gesture == keyboard_swipe_gesture::FRESH
|
||||||
|
? 1.00f
|
||||||
|
: 0.01f; // square root of 1/10
|
||||||
|
|
||||||
|
// we are working with floating points which are not exact
|
||||||
|
// make sure we compare with a very small value (epsilon)
|
||||||
|
static const float EPSILON = 1e-6f;
|
||||||
|
const float distance_squared = this->x * this->x + this->y * this->y;
|
||||||
|
const float beyond_threshold = this->threshold_squared * scale;
|
||||||
|
|
||||||
|
// apply if strictly beyond threshold
|
||||||
|
if (distance_squared > beyond_threshold + EPSILON) {
|
||||||
|
// we parse our mask based on the values obtained from the regex
|
||||||
|
int mask = 0;
|
||||||
|
|
||||||
|
if (this->fingers == 3)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_THREE_FINGERS;
|
||||||
|
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_FOUR_FINGERS;
|
||||||
|
|
||||||
|
const float absx = x >= 0 ? x : -x;
|
||||||
|
const float absy = y >= 0 ? y : -y;
|
||||||
|
|
||||||
|
if (absx > absy) {
|
||||||
|
// gesture is horizontal
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_HORIZONTAL;
|
||||||
|
if (x < 0)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_POSITIVE;
|
||||||
|
} else /* std::abs(x) <= std::abs(y) */
|
||||||
|
{
|
||||||
|
// gesture is vertical
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_VERTICAL;
|
||||||
|
if (y < 0)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if (this->previous_gesture == keyboard_swipe_gesture::FRESH ||
|
||||||
|
this->previous_gesture ==
|
||||||
|
(mask ^ keyboard_swipe_gesture::MSK_POSITIVE)) {
|
||||||
|
this->do_keyboard_gesture(mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the update given a mask.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::do_keyboard_gesture(int mask) {
|
||||||
|
// perform our keyboard command with xdo_send_keysequence
|
||||||
|
const char *command = keyboard_swipe_gesture::commands[mask];
|
||||||
|
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, command, 0);
|
||||||
|
|
||||||
|
// reset our location variables
|
||||||
|
this->x = this->y = 0;
|
||||||
|
this->previous_gesture = mask;
|
||||||
|
|
||||||
|
// log our command name in stdout
|
||||||
|
const char *command_name = keyboard_swipe_gesture::command_map[mask];
|
||||||
|
std::cout << "SWIPE " << command_name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::end() {
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace comfortable_swipe::gesture
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__ */
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "swipe_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class keyboard_swipe_gesture : public swipe_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
keyboard_swipe_gesture(
|
||||||
|
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 */
|
||||||
|
);
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
virtual ~keyboard_swipe_gesture();
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// stores all command strings for xdo to execute
|
||||||
|
const char ** commands;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// static enums we will use for gesture matching
|
||||||
|
static const int FRESH;
|
||||||
|
static const int MSK_THREE_FINGERS;
|
||||||
|
static const int MSK_FOUR_FINGERS;
|
||||||
|
static const int MSK_NEGATIVE;
|
||||||
|
static const int MSK_POSITIVE;
|
||||||
|
static const int MSK_HORIZONTAL;
|
||||||
|
static const int MSK_VERTICAL;
|
||||||
|
static const char * const command_map[8];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__ */
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "mouse_hold_gesture.h"
|
||||||
|
#include <cstdio> // std::sscanf
|
||||||
|
#include <cstring> // strncmp
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture {
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
|
||||||
|
*/
|
||||||
|
mouse_hold_gesture::mouse_hold_gesture(const char *hold3, const char *hold4)
|
||||||
|
: comfortable_swipe::gesture::swipe_gesture(), button(MOUSE_NONE),
|
||||||
|
hold3(hold3), hold4(hold4), flag_mousedown(false) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
mouse_hold_gesture::~mouse_hold_gesture() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run mousedown command on hold input.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::do_mousedown(const char *mouseinput) {
|
||||||
|
const int button = this->button = this->parse_mouse_button(mouseinput);
|
||||||
|
if (button != MOUSE_NONE) {
|
||||||
|
// eg. MOUSE DOWN hold3 mouse1
|
||||||
|
std::printf("MOUSE DOWN hold%d %s\n", this->fingers, mouseinput);
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK) {
|
||||||
|
// send mouse down on associated button
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
this->flag_mousedown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run mouseup command on hold output.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::do_mouseup(const char *mouseinput) {
|
||||||
|
const int button = this->button = this->parse_mouse_button(mouseinput);
|
||||||
|
if (button != MOUSE_NONE) {
|
||||||
|
std::printf("MOUSE UP hold%d %s\n", this->fingers, mouseinput);
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK) {
|
||||||
|
// send mouse up on associated button
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
this->flag_mousedown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to parse mouse number from input.
|
||||||
|
* Returns -1 on failure.
|
||||||
|
*/
|
||||||
|
int mouse_hold_gesture::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::begin() {
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::begin();
|
||||||
|
// dispatch mouse down event
|
||||||
|
if (this->fingers == 3) {
|
||||||
|
this->do_mousedown(this->hold3);
|
||||||
|
} else if (this->fingers == 4) {
|
||||||
|
this->do_mousedown(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::update() {
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::update();
|
||||||
|
if (this->is_mousedown()) {
|
||||||
|
if (0 <= this->button && this->button <= 3) {
|
||||||
|
// drag mouse with pointer during update
|
||||||
|
xdo_move_mouse_relative(this->xdo, this->udx, this->udy);
|
||||||
|
} else if (this->button == MOUSE_SCROLL ||
|
||||||
|
this->button == MOUSE_SCROLL_REVERSE) {
|
||||||
|
// perform naive scroll depending on vertical direction
|
||||||
|
int wheel = MOUSE_WHEEL_DOWN;
|
||||||
|
if ((this->udy > 0) == (this->button == MOUSE_SCROLL))
|
||||||
|
wheel = MOUSE_WHEEL_UP;
|
||||||
|
|
||||||
|
// click wheel on update (note: this is not precise)
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, wheel);
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, wheel);
|
||||||
|
} else if (this->button == MOUSE_WHEEL_UP ||
|
||||||
|
this->button == MOUSE_WHEEL_DOWN) {
|
||||||
|
// click wheel button on 4 or 5
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, this->button);
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, this->button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::end() {
|
||||||
|
if (this->is_mousedown()) {
|
||||||
|
if (this->fingers == 3) {
|
||||||
|
this->do_mouseup(this->hold3);
|
||||||
|
} else if (this->fingers == 4) {
|
||||||
|
this->do_mouseup(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to check if mouse is current held.
|
||||||
|
*/
|
||||||
|
bool mouse_hold_gesture::is_mousedown() const { return this->flag_mousedown; }
|
||||||
|
} // namespace comfortable_swipe::gesture
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__ */
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "swipe_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class mouse_hold_gesture : public swipe_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
mouse_hold_gesture(
|
||||||
|
const char* hold3, // 3 finger mouse down
|
||||||
|
const char* hold4 // 4 finger mouse down
|
||||||
|
);
|
||||||
|
|
||||||
|
// the button being clicked
|
||||||
|
int button;
|
||||||
|
|
||||||
|
virtual ~mouse_hold_gesture();
|
||||||
|
|
||||||
|
// override begin and end for mousedown
|
||||||
|
virtual void begin() override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
|
||||||
|
// provide our own mouse functions
|
||||||
|
virtual void do_mousedown(const char*);
|
||||||
|
virtual void do_mouseup(const char*);
|
||||||
|
virtual bool is_mousedown() const;
|
||||||
|
|
||||||
|
// utility method to parse mouse input given config characters
|
||||||
|
static int parse_mouse_button(const char*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// command holders
|
||||||
|
const char * hold3;
|
||||||
|
const char * hold4;
|
||||||
|
|
||||||
|
// flag we can use to check if mouse is down
|
||||||
|
bool flag_mousedown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__ */
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "swipe_gesture.h"
|
||||||
|
#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::gesture {
|
||||||
|
/**
|
||||||
|
* Constructs a new fresh swipe gesture container.
|
||||||
|
*/
|
||||||
|
swipe_gesture::swipe_gesture()
|
||||||
|
: // construct our superclass
|
||||||
|
comfortable_swipe::gesture::xdo_gesture(), 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.
|
||||||
|
*/
|
||||||
|
swipe_gesture::~swipe_gesture() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void swipe_gesture::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 swipe_gesture::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 swipe_gesture::end() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches begin/update/end depending on the regex pattern provided by this
|
||||||
|
* class.
|
||||||
|
*
|
||||||
|
* @param line the line from libinput debug-events to parse
|
||||||
|
* @return true if begin/update/end was dispatched
|
||||||
|
*/
|
||||||
|
bool swipe_gesture::parse_line(const char *line) {
|
||||||
|
|
||||||
|
// prepare regex matchers statically (will only load at most once)
|
||||||
|
static const std::regex gesture_swipe_begin(
|
||||||
|
swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN),
|
||||||
|
gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN),
|
||||||
|
gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
|
|
||||||
|
// prepare holder for regex matches
|
||||||
|
static std::cmatch matches;
|
||||||
|
|
||||||
|
if (this->flag_swiping) {
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// not swiping, check if swipe will begin
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_begin) != 0 ||
|
||||||
|
std::regex_match(line, matches, gesture_swipe_update) != 0) {
|
||||||
|
// assign necessary variables for swipe begin
|
||||||
|
this->flag_swiping = true;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
// dispatch begin
|
||||||
|
this->begin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::gesture
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "xdo_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class swipe_gesture : public xdo_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
swipe_gesture();
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
virtual ~swipe_gesture();
|
||||||
|
|
||||||
|
// 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 parse_line(const char *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// location of mouse
|
||||||
|
int screen_num, ix, iy;
|
||||||
|
|
||||||
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
|
bool flag_swiping;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// regex patterns
|
||||||
|
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_END_REGEX_PATTERN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_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 "swipe_gesture.h"
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture {
|
||||||
|
/**
|
||||||
|
* 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 char *swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN =
|
||||||
|
"^" // 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 char *swipe_gesture::GESTURE_END_REGEX_PATTERN =
|
||||||
|
"^" // 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 CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
||||||
|
|
||||||
|
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
||||||
|
#define CF_NUMBER_DIVISION "\\s*(" CF_NUMBER_REGEX ")/\\s*(" CF_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 char *swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_SWIPE_UPDATE" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
||||||
|
"\\s+\\(" CF_NUMBER_DIVISION
|
||||||
|
"\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// delete macros
|
||||||
|
#undef CF_NUMBER_DIVISION
|
||||||
|
#undef CF_NUMBER_EXTRACT
|
||||||
|
#undef CF_NUMBER_REGEX
|
||||||
|
} // namespace comfortable_swipe::gesture
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ */
|
||||||
@@ -19,32 +19,22 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#include <xdo.h> // xdo, xdo_new
|
#include <xdo.h> // xdo, xdo_new
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "xdo_gesture.h"
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
namespace comfortable_swipe
|
namespace comfortable_swipe::gesture {
|
||||||
{
|
|
||||||
namespace gesture
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new gesture handler with xdo.
|
* Constructs a new gesture handler with xdo.
|
||||||
*/
|
*/
|
||||||
xdo_gesture::xdo_gesture():
|
xdo_gesture::xdo_gesture() : xdo(xdo_new(NULL)) {}
|
||||||
xdo(xdo_new(NULL))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new swipe gesture with xdo.
|
* Constructs a new swipe gesture with xdo.
|
||||||
*/
|
*/
|
||||||
xdo_gesture::~xdo_gesture()
|
xdo_gesture::~xdo_gesture() { xdo_free(this->xdo); }
|
||||||
{
|
} // namespace comfortable_swipe::gesture
|
||||||
xdo_free(this->xdo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__xdo_gesture__ */
|
#endif /* __COMFORTABLE_SWIPE__xdo_gesture__ */
|
||||||
@@ -39,13 +39,7 @@ namespace comfortable_swipe
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
xdo_gesture();
|
xdo_gesture();
|
||||||
~xdo_gesture();
|
virtual ~xdo_gesture();
|
||||||
|
|
||||||
// hooks
|
|
||||||
virtual void begin() = 0;
|
|
||||||
virtual void update() = 0;
|
|
||||||
virtual void end() = 0;
|
|
||||||
virtual bool parse_line(const char *) = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__
|
||||||
|
#define __COMFORTABLE_SWIPE__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "all_headers.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all cpp files below to be ready for export.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "driver.cpp"
|
||||||
|
#include "gesture/keyboard_swipe_gesture.cpp"
|
||||||
|
#include "gesture/mouse_hold_gesture.cpp"
|
||||||
|
#include "gesture/swipe_gesture.cpp"
|
||||||
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
|
#include "gesture/xdo_gesture.cpp"
|
||||||
|
#include "service/autostart.cpp"
|
||||||
|
#include "service/buffer.cpp"
|
||||||
|
#include "service/config.cpp"
|
||||||
|
#include "service/debug.cpp"
|
||||||
|
#include "service/help.cpp"
|
||||||
|
#include "service/restart.cpp"
|
||||||
|
#include "service/start.cpp"
|
||||||
|
#include "service/status.cpp"
|
||||||
|
#include "service/stop.cpp"
|
||||||
|
#include "util/autostart_filename.cpp"
|
||||||
|
#include "util/conf_filename.cpp"
|
||||||
|
#include "util/read_config_file.cpp"
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__ */
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
[Desktop Entry]
|
|
||||||
Type=Application
|
|
||||||
Exec=comfortable-swipe start
|
|
||||||
Hidden=false
|
|
||||||
NoDisplay=false
|
|
||||||
X-GNOME-Autostart-enabled=true
|
|
||||||
Name=Comfortable Swipe
|
|
||||||
Comment=3 or 4 finger swipe gestures
|
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_autostart__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_autostart__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../all_headers.hpp"
|
||||||
|
#include <cstdio> // std::remove
|
||||||
|
#include <cstdlib> // std::system
|
||||||
|
#include <fstream> // std::ifstream, std::ofstream
|
||||||
|
#include <iostream> // std::cerr, std::cout, std::endl
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Toggles automatic startup of comfortable swipe.
|
||||||
|
*/
|
||||||
|
void autostart() {
|
||||||
|
using comfortable_swipe::util::autostart_filename;
|
||||||
|
|
||||||
|
const std::string &path = autostart_filename();
|
||||||
|
if (std::ifstream(path.data()).good()) {
|
||||||
|
// file found, delete it
|
||||||
|
if (std::remove(path.data()) != 0)
|
||||||
|
std::cerr << "Error: failed to switch off autostart. "
|
||||||
|
<< "Maybe the autostart file is in use?" << std::endl;
|
||||||
|
else
|
||||||
|
std::cout << "Autostart switched off" << std::endl;
|
||||||
|
} else {
|
||||||
|
// file not found, create it
|
||||||
|
int result = std::system(("mkdir -p $(dirname " + path + ")").data());
|
||||||
|
std::ofstream fout(path.data());
|
||||||
|
if (result != 0 || !fout.good())
|
||||||
|
std::cerr << "Error: failed to switch on autostart. "
|
||||||
|
<< "Are you sure you have the permissions?" << std::endl;
|
||||||
|
else {
|
||||||
|
fout << "[Desktop Entry]\n"
|
||||||
|
"Type=Application\n"
|
||||||
|
"Exec=bash -c \"" __COMFORTABLE_SWIPE__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";
|
||||||
|
std::cout << "Autostart switched on" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_autostart__ */
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_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 "../all_headers.hpp"
|
||||||
|
#include <cstdlib> // std::exit
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
*/
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
void buffer() { std::exit(comfortable_swipe::driver()); }
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_config__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_config__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
#include <cstdio> // std::puts
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Prints where the config file of comfortable swipe is located.
|
||||||
|
*
|
||||||
|
* Usage: nano $(comfortable-swipe config)
|
||||||
|
*/
|
||||||
|
void config() { std::puts(comfortable_swipe::util::conf_filename()); }
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_config__ */
|
||||||
@@ -21,18 +21,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <cstdlib> // std::system
|
#include <cstdlib> // std::system
|
||||||
|
|
||||||
namespace comfortable_swipe
|
namespace comfortable_swipe::service {
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Debugs output from `libinput debug-events`.
|
* Debugs output from `libinput debug-events`.
|
||||||
*/
|
*/
|
||||||
void debug()
|
void debug() {
|
||||||
{
|
(void)std::system("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep "
|
||||||
(void) std::system("bash -c \"stdbuf -oL -e0 libinput debug-events 2> >(grep -v 'double tracking')\"");
|
"-v 'double tracking')\"");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_debug__ */
|
#endif /* __COMFORTABLE_SWIPE__service_debug__ */
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_help__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_help__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../all_headers.hpp"
|
||||||
|
#include <cstdio> // std::puts, std::printf
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Shows the help window.
|
||||||
|
*/
|
||||||
|
void help() {
|
||||||
|
using comfortable_swipe::util::conf_filename;
|
||||||
|
std::puts("comfortable-swipe " COMFORTABLE_SWIPE_VERSION
|
||||||
|
" [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
||||||
|
std::puts("");
|
||||||
|
std::puts("start - starts 3/4-finger gesture service");
|
||||||
|
std::puts("stop - stops 3/4-finger gesture service");
|
||||||
|
std::puts("restart - stops then starts 3/4-finger gesture service");
|
||||||
|
std::puts("autostart - automatically run on startup (toggleable)");
|
||||||
|
std::puts("buffer - parses output of libinput debug-events");
|
||||||
|
std::puts("help - shows the help dialog");
|
||||||
|
std::puts("config - locates the config file "
|
||||||
|
"[/usr/share/comfortable-swipe/comfortable-swipe.conf]");
|
||||||
|
std::puts(
|
||||||
|
"debug - logs raw output from input events taken from libinput");
|
||||||
|
std::puts("status - checks status of program and autostart");
|
||||||
|
std::puts("");
|
||||||
|
std::printf("Configuration file can be found in %s\n", conf_filename());
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_help__ */
|
||||||
@@ -19,21 +19,22 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../service/_index.hpp"
|
#include "../all_headers.hpp"
|
||||||
|
#include <cstdio> // freopen, stdout
|
||||||
|
|
||||||
namespace comfortable_swipe
|
namespace comfortable_swipe::service {
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Restarts the comfortable-swipe service.
|
* Restarts the comfortable-swipe service.
|
||||||
*/
|
*/
|
||||||
void restart()
|
void restart() {
|
||||||
{
|
// dont show stdout on stop
|
||||||
|
freopen("/dev/null", "a", stdout);
|
||||||
comfortable_swipe::service::stop();
|
comfortable_swipe::service::stop();
|
||||||
|
|
||||||
|
// show back on start
|
||||||
|
freopen("/dev/tty", "a", stdout);
|
||||||
comfortable_swipe::service::start();
|
comfortable_swipe::service::start();
|
||||||
}
|
}
|
||||||
}
|
} // namespace comfortable_swipe::service
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_start__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_start__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 "../all_headers.hpp"
|
||||||
|
#include <cstdlib> // std::system
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
|
||||||
|
* for the technical implementation.
|
||||||
|
*/
|
||||||
|
void start() {
|
||||||
|
(void)std::system(__COMFORTABLE_SWIPE__PROGRAM__
|
||||||
|
" debug | " __COMFORTABLE_SWIPE__PROGRAM__ " buffer");
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_start__ */
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_status__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_status__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
#include <array> // std::array
|
||||||
|
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||||
|
#include <cstdlib> // std::atoi
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
|
#include <regex> // std::cmatch, std::regex, std::regex_match
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Prints the status of comfortable-swipe.
|
||||||
|
*/
|
||||||
|
void status() {
|
||||||
|
// check if comfortable-swipe is running
|
||||||
|
bool running = false;
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(
|
||||||
|
popen("pgrep -f comfortable-swipe", "r"), pclose);
|
||||||
|
if (pipe && !std::feof(pipe.get()) &&
|
||||||
|
std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL) {
|
||||||
|
int pid = std::atoi(buffer.data());
|
||||||
|
if (pid != getpid())
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if autostart is on
|
||||||
|
auto autostart_f = comfortable_swipe::util::autostart_filename();
|
||||||
|
bool autostart_on = access(autostart_f, F_OK) != -1;
|
||||||
|
|
||||||
|
std::puts(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// check status of configuration file
|
||||||
|
try {
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(
|
||||||
|
comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// formatting
|
||||||
|
const char *FORMAT_NO_ARGS = " %9s is %9s\n";
|
||||||
|
const char *FORMAT_ARGS = " %9s is %9s (%s)\n";
|
||||||
|
|
||||||
|
// print threshold
|
||||||
|
if (config.count("threshold") > 0) {
|
||||||
|
auto &threshold = config["threshold"];
|
||||||
|
|
||||||
|
// check if regex pattern matches threshold
|
||||||
|
std::cmatch matches;
|
||||||
|
bool ok = (std::regex_match(threshold.data(), matches,
|
||||||
|
std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
|
||||||
|
|
||||||
|
// print status of threshold
|
||||||
|
std::printf(FORMAT_ARGS, "threshold", ok ? "VALID" : "INVALID",
|
||||||
|
threshold.data());
|
||||||
|
} else
|
||||||
|
std::printf(FORMAT_NO_ARGS, "threshold", "NOTSET");
|
||||||
|
|
||||||
|
// print mouse hold commands
|
||||||
|
const char *mouse_hold_commands[] = {"hold3", "hold4"};
|
||||||
|
bool has_mouse_hold[] = {false, false};
|
||||||
|
int index = 0;
|
||||||
|
for (const auto *command : mouse_hold_commands) {
|
||||||
|
if (config.count(command) > 0) {
|
||||||
|
// check if command is valid
|
||||||
|
const auto &input = config[command];
|
||||||
|
int button =
|
||||||
|
comfortable_swipe::gesture::mouse_hold_gesture::parse_mouse_button(
|
||||||
|
input.c_str());
|
||||||
|
if (button != comfortable_swipe::gesture::MOUSE_NONE) {
|
||||||
|
std::printf(FORMAT_ARGS, command, "VALID", input.c_str());
|
||||||
|
has_mouse_hold[index] = button;
|
||||||
|
} else {
|
||||||
|
std::printf(FORMAT_ARGS, command, "INVALID", input.c_str());
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
std::printf(FORMAT_NO_ARGS, command, "NOTSET");
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print swipe commands
|
||||||
|
for (auto &command :
|
||||||
|
comfortable_swipe::gesture::keyboard_swipe_gesture::command_map) {
|
||||||
|
if (config.count(command) > 0) {
|
||||||
|
int fingers = int(command[strlen(command) - 1] - '0');
|
||||||
|
if (has_mouse_hold[fingers - 3]) {
|
||||||
|
// command is disabled because mouse hold exists
|
||||||
|
std::printf(FORMAT_ARGS, command, "DISABLED", config[command].data());
|
||||||
|
} else {
|
||||||
|
// check if it's disabled by checking button
|
||||||
|
std::printf(FORMAT_ARGS, command, "VALID", config[command].data());
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
std::printf(FORMAT_NO_ARGS, command, "NOTSET");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (const std::runtime_error &e) {
|
||||||
|
std::printf("config error: %s\n", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// print status
|
||||||
|
std::printf("\nautostart is %s\n", autostart_on ? "ON" : "OFF");
|
||||||
|
std::printf("comfortable-swipe program is %s\n",
|
||||||
|
running ? "RUNNING" : "STOPPED");
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_stop__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_stop__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <cstdio> // std::FILE, std::feof, std::fgets
|
||||||
|
#include <cstdlib> // std::atoi, std::system
|
||||||
|
#include <memory> // std::unique_ptr
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
#include <string> // std::string, std::to_string
|
||||||
|
#include <unistd.h> // popen, pclose, getpid
|
||||||
|
|
||||||
|
namespace comfortable_swipe::service {
|
||||||
|
/**
|
||||||
|
* Stops all comfortable-swipe instances.
|
||||||
|
*/
|
||||||
|
void stop() {
|
||||||
|
|
||||||
|
// read all service names from process (pgrep)
|
||||||
|
std::array<char, 128> buffer;
|
||||||
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(
|
||||||
|
popen("pgrep -f \"$(which comfortable-swipe)\"", "r"), pclose);
|
||||||
|
|
||||||
|
// make sure pipe exists
|
||||||
|
if (!pipe)
|
||||||
|
throw std::runtime_error("stop command failed");
|
||||||
|
|
||||||
|
// buffer what to kill
|
||||||
|
std::string kill = "";
|
||||||
|
|
||||||
|
// read until end of line
|
||||||
|
while (!std::feof(pipe.get())) {
|
||||||
|
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL) {
|
||||||
|
int pid = std::atoi(buffer.data());
|
||||||
|
if (pid != getpid()) {
|
||||||
|
kill += " ";
|
||||||
|
kill += std::to_string(pid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run "kill {pid1} {pid2}..."
|
||||||
|
if (kill.length()) {
|
||||||
|
std::printf("Stopped%s\n", kill.c_str());
|
||||||
|
(void)std::system(("kill" + kill).c_str());
|
||||||
|
} else {
|
||||||
|
std::printf("No program to stop\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::service
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_stop__ */
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from comfortable_swipe import autostart
|
|
||||||
from comfortable_swipe.cpp import service
|
|
||||||
from comfortable_swipe.constants import NAME, exe
|
|
||||||
|
|
||||||
def print_status():
|
|
||||||
service.status()
|
|
||||||
print('autostart is', autostart.get_status().upper())
|
|
||||||
print('{} program is {}'.format(NAME, 'RUNNING' if is_running() else 'STOPPED'))
|
|
||||||
|
|
||||||
|
|
||||||
def is_running():
|
|
||||||
import psutil
|
|
||||||
for process in psutil.process_iter():
|
|
||||||
process_args = [process.name()] + process.cmdline()
|
|
||||||
for index in range(len(process_args) - 1):
|
|
||||||
if process_args[index + 1] == 'start' and process_args[index].endswith(NAME):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__util_autostart_filename__
|
||||||
|
#define __COMFORTABLE_SWIPE__util_autostart_filename__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <string> // std::string
|
||||||
|
#include <unistd.h> // getenv
|
||||||
|
|
||||||
|
namespace comfortable_swipe::util {
|
||||||
|
/**
|
||||||
|
* The path where the autostart configuration is located.
|
||||||
|
*/
|
||||||
|
const char *autostart_filename() {
|
||||||
|
static std::string filename;
|
||||||
|
if (filename.empty()) {
|
||||||
|
const char *xdg_config = getenv("XDG_CONFIG_HOME");
|
||||||
|
std::string config(xdg_config == NULL
|
||||||
|
? std::string(getenv("HOME")) + "/.config"
|
||||||
|
: xdg_config);
|
||||||
|
filename = config + "/autostart/comfortable-swipe.desktop";
|
||||||
|
}
|
||||||
|
return filename.data();
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::util
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_autostart_filename__ */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__
|
#ifndef __COMFORTABLE_SWIPE__util_conf_filename__
|
||||||
#define __COMFORTABLE_SWIPE__
|
#define __COMFORTABLE_SWIPE__util_conf_filename__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
@@ -19,8 +19,13 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "_macro.cpp"
|
#include "../all_headers.hpp"
|
||||||
#include "_index.hpp"
|
|
||||||
#include "_index.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__ */
|
namespace comfortable_swipe::util {
|
||||||
|
/**
|
||||||
|
* The path where the configuration file is located.
|
||||||
|
*/
|
||||||
|
constexpr const char *conf_filename() { return __COMFORTABLE_SWIPE__CONFIG__; }
|
||||||
|
} // namespace comfortable_swipe::util
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_conf_filename__ */
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__util_read_config_file__
|
||||||
|
#define __COMFORTABLE_SWIPE__util_read_config_file__
|
||||||
|
|
||||||
|
/*
|
||||||
|
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 <cctype> // std::isspace
|
||||||
|
#include <cstdlib> // exit
|
||||||
|
#include <fstream> // std::ifstream
|
||||||
|
#include <iostream> // std::endl, std::getline
|
||||||
|
#include <map> // std::map
|
||||||
|
#include <sstream> // std::ostringstream
|
||||||
|
#include <stdexcept> // std::runtime_error
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
namespace comfortable_swipe::util {
|
||||||
|
/**
|
||||||
|
* A utility method for reading the config file.
|
||||||
|
*
|
||||||
|
* @param filename (const char*) the path of the config file.
|
||||||
|
*/
|
||||||
|
std::map<std::string, std::string> read_config_file(const char *filename) {
|
||||||
|
|
||||||
|
std::map<std::string, std::string> conf;
|
||||||
|
std::ifstream fin(filename);
|
||||||
|
|
||||||
|
if (!fin.is_open()) {
|
||||||
|
throw std::runtime_error("config file does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string line, token[2];
|
||||||
|
int line_number = 0;
|
||||||
|
|
||||||
|
while (std::getline(fin, line)) {
|
||||||
|
++line_number;
|
||||||
|
token[0].clear();
|
||||||
|
token[1].clear();
|
||||||
|
int length = line.length();
|
||||||
|
int equal_flag = 0;
|
||||||
|
|
||||||
|
// tokenize comfig config
|
||||||
|
for (int i = 0; i < length; ++i) {
|
||||||
|
if (line[i] == '#') // skip comments
|
||||||
|
break;
|
||||||
|
if (line[i] == '=') // flag equal sign
|
||||||
|
{
|
||||||
|
if (++equal_flag > 1) {
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "error in conf file " << filename << std::endl;
|
||||||
|
stream << "multiple equal signs in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
|
}
|
||||||
|
} else if (!std::isspace(line[i])) {
|
||||||
|
// add to buffer
|
||||||
|
token[equal_flag].push_back(line[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ignore empty lines
|
||||||
|
if (equal_flag == 0 && token[0].length() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// no equal sign found in non-empty line
|
||||||
|
if (equal_flag == 0) {
|
||||||
|
std::ostringstream stream;
|
||||||
|
stream << "error in conf file: " << filename << std::endl;
|
||||||
|
stream << "equal sign expected in line " << line_number << std::endl;
|
||||||
|
throw std::runtime_error(stream.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// equal sign found, add to tokens
|
||||||
|
if (token[1].length() > 0)
|
||||||
|
conf[token[0]] = token[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf;
|
||||||
|
}
|
||||||
|
} // namespace comfortable_swipe::util
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__util_read_config_file__ */
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
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/lib"
|
||||||
|
#include <ios> // std::ios
|
||||||
|
#include <iostream> // std::cin, std::cout, std::cerr
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
|
/* Command-line function. */
|
||||||
|
|
||||||
|
int main(int argc, char **args) {
|
||||||
|
// improve buffering by decoupling loggers from stdio
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
std::cin.tie(0);
|
||||||
|
std::cout.tie(0);
|
||||||
|
std::cerr.tie(0);
|
||||||
|
|
||||||
|
if (argc > 1) {
|
||||||
|
std::string arg = args[1];
|
||||||
|
|
||||||
|
// select based on argument
|
||||||
|
if (arg == "start")
|
||||||
|
comfortable_swipe::service::start();
|
||||||
|
|
||||||
|
else if (arg == "stop")
|
||||||
|
comfortable_swipe::service::stop();
|
||||||
|
|
||||||
|
else if (arg == "restart")
|
||||||
|
comfortable_swipe::service::restart();
|
||||||
|
|
||||||
|
else if (arg == "buffer")
|
||||||
|
comfortable_swipe::service::buffer();
|
||||||
|
|
||||||
|
else if (arg == "autostart")
|
||||||
|
comfortable_swipe::service::autostart();
|
||||||
|
|
||||||
|
else if (arg == "config")
|
||||||
|
comfortable_swipe::service::config();
|
||||||
|
|
||||||
|
else if (arg == "debug")
|
||||||
|
comfortable_swipe::service::debug();
|
||||||
|
|
||||||
|
else if (arg == "status")
|
||||||
|
comfortable_swipe::service::status();
|
||||||
|
|
||||||
|
else /* if (arg == "help") */
|
||||||
|
comfortable_swipe::service::help();
|
||||||
|
} else
|
||||||
|
comfortable_swipe::service::help();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
dir="$(dirname $0)"
|
||||||
|
version="$(cat "$dir/VERSION" | tr -d '[:space:]')"
|
||||||
|
|
||||||
|
exec g++ $@ \
|
||||||
|
-std=c++11 \
|
||||||
|
-O2 -lxdo -Wno-unused-result \
|
||||||
|
-DCOMFORTABLE_SWIPE_VERSION="\"$version\""
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__index_cpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__index_cpp__
|
|
||||||
|
|
||||||
#include "gesture/_index.cpp"
|
|
||||||
#include "service/_index.cpp"
|
|
||||||
#include "util/_index.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__index_cpp__ */
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__index_hpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__index_hpp__
|
|
||||||
|
|
||||||
#include "gesture/_index.hpp"
|
|
||||||
#include "service/_index.hpp"
|
|
||||||
#include "util/_index.hpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__index_hpp__ */
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__macro_hpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__macro_hpp__
|
|
||||||
|
|
||||||
#ifndef COMFORTABLE_SWIPE_CONFIG
|
|
||||||
#error "COMFORTABLE_SWIPE_CONFIG must be defined."
|
|
||||||
#endif /* COMFORTABLE_SWIPE_CONFIG */
|
|
||||||
|
|
||||||
#ifndef COMFORTABLE_SWIPE_VERSION
|
|
||||||
#warning "COMFORTABLE_SWIPE_VERSION is not defined."
|
|
||||||
#endif /* COMFORTABLE_SWIPE_VERSION */
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__macro_hpp__ */
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__python_cpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__python_cpp__
|
|
||||||
|
|
||||||
#include "service/_python.cpp"
|
|
||||||
#include "comfortable-swipe.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__python_cpp__ */
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
#include "comfortable-swipe.cpp"
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_index_cpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_index_cpp__
|
|
||||||
|
|
||||||
#include "_index.hpp"
|
|
||||||
#include "xdo_gesture.cpp"
|
|
||||||
#include "swipe_gesture.cpp"
|
|
||||||
#include "swipe_gesture.regex.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_index_cpp__ */
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_index_hpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_index_hpp__
|
|
||||||
|
|
||||||
#include "xdo_gesture.h"
|
|
||||||
#include "swipe_gesture.h"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_index_hpp__ */
|
|
||||||
@@ -1,216 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 <string> // std::stoi, std::stof
|
|
||||||
#include <regex> // std::regex, std::regex_match, std::cmatch
|
|
||||||
#include <ctime>
|
|
||||||
#include "swipe_gesture.h"
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
|
||||||
// xdo_get_mouse_location
|
|
||||||
// CURRENT_WINDOW
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace gesture
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructs a new swipe gesture, given configurations for certain swipe events.
|
|
||||||
*/
|
|
||||||
swipe_gesture::swipe_gesture
|
|
||||||
(
|
|
||||||
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 */
|
|
||||||
):
|
|
||||||
comfortable_swipe::gesture::xdo_gesture(),
|
|
||||||
threshold_squared(threshold*threshold),
|
|
||||||
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}),
|
|
||||||
flag_swiping(false)
|
|
||||||
{
|
|
||||||
// improve responsiveness of first gesture by pre-empting xdotool runtime
|
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructs this swipe gesture.
|
|
||||||
*/
|
|
||||||
swipe_gesture::~swipe_gesture()
|
|
||||||
{
|
|
||||||
delete[] commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on begin of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::begin()
|
|
||||||
{
|
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
|
||||||
this->previous_gesture = swipe_gesture::FRESH;
|
|
||||||
this->x = 0;
|
|
||||||
this->y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on update of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::update()
|
|
||||||
{
|
|
||||||
this->x += this->dx;
|
|
||||||
this->y += this->dy;
|
|
||||||
// scale threshold to 1/10 when gesture is not fresh
|
|
||||||
float scale = this->previous_gesture == swipe_gesture::FRESH
|
|
||||||
? 1.00f
|
|
||||||
: 0.01f; // square root of 1/10
|
|
||||||
static const float EPSILON = 1e-6f;
|
|
||||||
if (this->x * this->x + this->y * this->y
|
|
||||||
> this->threshold_squared * scale + EPSILON)
|
|
||||||
{
|
|
||||||
int mask = 0;
|
|
||||||
if (this->fingers == 3) mask |= swipe_gesture::MSK_THREE_FINGERS;
|
|
||||||
else if (this->fingers == 4) mask |= swipe_gesture::MSK_FOUR_FINGERS;
|
|
||||||
|
|
||||||
const float absx = x >= 0 ? x : -x;
|
|
||||||
const float absy = y >= 0 ? y : -y;
|
|
||||||
if (absx > absy)
|
|
||||||
{ // horizontal
|
|
||||||
mask |= swipe_gesture::MSK_HORIZONTAL;
|
|
||||||
if (x < 0)
|
|
||||||
mask |= swipe_gesture::MSK_NEGATIVE;
|
|
||||||
else
|
|
||||||
mask |= swipe_gesture::MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
else /* std::abs(x) <= std::abs(y) */
|
|
||||||
{ // vertical
|
|
||||||
mask |= swipe_gesture::MSK_VERTICAL;
|
|
||||||
if (y < 0)
|
|
||||||
mask |= swipe_gesture::MSK_NEGATIVE;
|
|
||||||
else
|
|
||||||
mask |= swipe_gesture::MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send command on fresh OR opposite gesture
|
|
||||||
if (this->previous_gesture == swipe_gesture::FRESH
|
|
||||||
|| this->previous_gesture == (mask ^ swipe_gesture::MSK_POSITIVE))
|
|
||||||
{
|
|
||||||
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, swipe_gesture::commands[mask], 0);
|
|
||||||
this->x = this->y = 0;
|
|
||||||
this->previous_gesture = mask;
|
|
||||||
std::cout << "SWIPE " << swipe_gesture::command_map[mask] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on end of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::end()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatches begin/update/end depending on the regex pattern provided by this class.
|
|
||||||
*
|
|
||||||
* @param line the line from libinput debug-events to parse
|
|
||||||
* @return true if begin/update/end was dispatched
|
|
||||||
*/
|
|
||||||
bool swipe_gesture::parse_line(const char * line)
|
|
||||||
{
|
|
||||||
static const std::regex gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
|
||||||
|
|
||||||
// prepare holder for regex matches
|
|
||||||
static std::cmatch matches;
|
|
||||||
|
|
||||||
if (this->flag_swiping)
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* STATICS DEFINITIONS */
|
|
||||||
const int swipe_gesture::MSK_THREE_FINGERS = 0;
|
|
||||||
const int swipe_gesture::MSK_FOUR_FINGERS = 1;
|
|
||||||
const int swipe_gesture::MSK_NEGATIVE = 0;
|
|
||||||
const int swipe_gesture::MSK_POSITIVE = 2;
|
|
||||||
const int swipe_gesture::MSK_HORIZONTAL = 0;
|
|
||||||
const int swipe_gesture::MSK_VERTICAL = 4;
|
|
||||||
const int swipe_gesture::FRESH = -1;
|
|
||||||
const char * const swipe_gesture::command_map[8] = {
|
|
||||||
"left3",
|
|
||||||
"left4",
|
|
||||||
"right3",
|
|
||||||
"right4",
|
|
||||||
"up3",
|
|
||||||
"up4",
|
|
||||||
"down3",
|
|
||||||
"down4"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 "xdo_gesture.h"
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace gesture
|
|
||||||
{
|
|
||||||
class swipe_gesture : protected xdo_gesture
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// constructor
|
|
||||||
swipe_gesture(
|
|
||||||
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();
|
|
||||||
|
|
||||||
// fields for xdo
|
|
||||||
int fingers;
|
|
||||||
float dx, dy, udx, udy;
|
|
||||||
|
|
||||||
void begin() override;
|
|
||||||
void update() override;
|
|
||||||
void end() override;
|
|
||||||
bool parse_line(const char *) override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// location of mouse
|
|
||||||
int screen_num, ix, iy;
|
|
||||||
|
|
||||||
// current location
|
|
||||||
float x, y, threshold_squared;
|
|
||||||
int previous_gesture;
|
|
||||||
const char ** commands;
|
|
||||||
|
|
||||||
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
|
||||||
bool flag_swiping;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// static constants
|
|
||||||
static const int MSK_THREE_FINGERS;
|
|
||||||
static const int MSK_FOUR_FINGERS;
|
|
||||||
static const int MSK_NEGATIVE;
|
|
||||||
static const int MSK_POSITIVE;
|
|
||||||
static const int MSK_HORIZONTAL;
|
|
||||||
static const int MSK_VERTICAL;
|
|
||||||
static const int FRESH;
|
|
||||||
static const char * const command_map[8];
|
|
||||||
// regex patterns
|
|
||||||
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
|
||||||
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
|
||||||
static const char* GESTURE_END_REGEX_PATTERN;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_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 "swipe_gesture.h"
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace gesture
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 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 char* swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN =
|
|
||||||
"^" // 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 char* swipe_gesture::GESTURE_END_REGEX_PATTERN =
|
|
||||||
"^" // 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 CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
|
||||||
|
|
||||||
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
|
||||||
#define CF_NUMBER_DIVISION "\\s*(" CF_NUMBER_REGEX ")/\\s*(" CF_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 char* swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN =
|
|
||||||
"^" // start of string
|
|
||||||
"[ -]event\\d+" // event
|
|
||||||
"\\s+GESTURE_SWIPE_UPDATE" // gesture
|
|
||||||
"\\s+\\S+" // timestamp
|
|
||||||
"\\s+(\\d+)" // fingers
|
|
||||||
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
|
||||||
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
|
||||||
"\\s*$" // end of string
|
|
||||||
;
|
|
||||||
|
|
||||||
// delete macros
|
|
||||||
#undef CF_NUMBER_DIVISION
|
|
||||||
#undef CF_NUMBER_EXTRACT
|
|
||||||
#undef CF_NUMBER_REGEX
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_regex__ */
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_index_cpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_index_cpp__
|
|
||||||
|
|
||||||
#include "_index.hpp"
|
|
||||||
#include "buffer.cpp"
|
|
||||||
#include "debug.cpp"
|
|
||||||
#include "help.cpp"
|
|
||||||
#include "restart.cpp"
|
|
||||||
#include "start.cpp"
|
|
||||||
#include "status.cpp"
|
|
||||||
#include "stop.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_index_cpp__ */
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_index_hpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_index_hpp__
|
|
||||||
|
|
||||||
#include <map> // std::map
|
|
||||||
#include <string> // std::string
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
void buffer();
|
|
||||||
void debug();
|
|
||||||
void help();
|
|
||||||
void restart();
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
void status();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_index_hpp__ */
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_python__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_python__
|
|
||||||
|
|
||||||
#include "_index.hpp"
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <Python.h>
|
|
||||||
}
|
|
||||||
|
|
||||||
// export as python module
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
namespace python
|
|
||||||
{
|
|
||||||
#define __comfortable_swipe_void_method(method) \
|
|
||||||
static PyObject * \
|
|
||||||
method(PyObject * self, PyObject * args) \
|
|
||||||
{ \
|
|
||||||
comfortable_swipe::service::method(); \
|
|
||||||
Py_RETURN_NONE; \
|
|
||||||
}
|
|
||||||
|
|
||||||
// create the python method signatures
|
|
||||||
__comfortable_swipe_void_method(status);
|
|
||||||
__comfortable_swipe_void_method(start);
|
|
||||||
__comfortable_swipe_void_method(stop);
|
|
||||||
__comfortable_swipe_void_method(restart);
|
|
||||||
// __comfortable_swipe_void_method(autostart);
|
|
||||||
__comfortable_swipe_void_method(buffer);
|
|
||||||
__comfortable_swipe_void_method(help);
|
|
||||||
// __comfortable_swipe_void_method(config);
|
|
||||||
__comfortable_swipe_void_method(debug);
|
|
||||||
|
|
||||||
#undef __comfortable_swipe_void_method
|
|
||||||
|
|
||||||
// create the method list for C++
|
|
||||||
static PyMethodDef methods[] =
|
|
||||||
{
|
|
||||||
{ "status", &status, METH_VARARGS , "checks status of program, autostart, and config" },
|
|
||||||
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
|
|
||||||
{ "stop", &stop, METH_VARARGS , "stops 3/4-finger gesture service" },
|
|
||||||
{ "restart", &restart, METH_VARARGS , "stops then starts 3/4-finger gesture service" },
|
|
||||||
// { "autostart", &autostart, METH_VARARGS , "automatically run on startup (toggleable)" },
|
|
||||||
{ "buffer", &buffer, METH_VARARGS , "parses output of libinput debug-events" },
|
|
||||||
{ "help", &help, METH_VARARGS , "shows the help dialog" },
|
|
||||||
// { "config", &config, METH_VARARGS , "locates the config file " },
|
|
||||||
{ "debug", &debug, METH_VARARGS , "logs raw output from input events taken from libinput" },
|
|
||||||
{ NULL, NULL, 0, NULL } // sentinel
|
|
||||||
};
|
|
||||||
|
|
||||||
// create the module configuration
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
static struct PyModuleDef module_def =
|
|
||||||
{
|
|
||||||
PyModuleDef_HEAD_INIT,
|
|
||||||
"service",
|
|
||||||
"Comfortable swipe service",
|
|
||||||
-1,
|
|
||||||
methods
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PyObject * module;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize module
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
PyInit_service(void)
|
|
||||||
{
|
|
||||||
using comfortable_swipe::service::python::module_def;
|
|
||||||
using comfortable_swipe::service::python::module;
|
|
||||||
if (module != NULL) return module;
|
|
||||||
return module = PyModule_Create(&module_def);
|
|
||||||
}
|
|
||||||
#else /* PY_MAJOR_VERSION < 3 */
|
|
||||||
PyMODINIT_FUNC
|
|
||||||
initservice(void)
|
|
||||||
{
|
|
||||||
using comfortable_swipe::service::python::methods;
|
|
||||||
using comfortable_swipe::service::python::module;
|
|
||||||
if (module != NULL) return;
|
|
||||||
module = Py_InitModule("service", methods);
|
|
||||||
}
|
|
||||||
#endif /* PY_MAJOR_VERSION */
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_python__ */
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_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 "../_macro.cpp"
|
|
||||||
#include "../util/_index.hpp"
|
|
||||||
#include "../gesture/_index.hpp"
|
|
||||||
#include <cstdio> // fgets_unlocked, stdin
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
|
||||||
*/
|
|
||||||
namespace comfortable_swipe::service
|
|
||||||
{
|
|
||||||
void buffer()
|
|
||||||
{
|
|
||||||
// read config file
|
|
||||||
auto config = comfortable_swipe::util::read_config_file(COMFORTABLE_SWIPE_CONFIG);
|
|
||||||
|
|
||||||
// initialize swipe gesture handler
|
|
||||||
comfortable_swipe::gesture::swipe_gesture swipe_gesture_handler
|
|
||||||
(
|
|
||||||
config.count("threshold") ? std::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()
|
|
||||||
);
|
|
||||||
|
|
||||||
// prepare data containers
|
|
||||||
std::array<char, 256> line;
|
|
||||||
|
|
||||||
// start reading lines from input one by one
|
|
||||||
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
|
||||||
{
|
|
||||||
// attempt to parse swipe gestures
|
|
||||||
swipe_gesture_handler.parse_line(line.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_help__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_help__
|
|
||||||
|
|
||||||
/*
|
|
||||||
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::puts, std::printf
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Shows the help window.
|
|
||||||
*/
|
|
||||||
void help()
|
|
||||||
{
|
|
||||||
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
|
||||||
std::puts("");
|
|
||||||
std::puts("start - starts 3/4-finger gesture service");
|
|
||||||
std::puts("stop - stops 3/4-finger gesture service");
|
|
||||||
std::puts("restart - stops then starts 3/4-finger gesture service");
|
|
||||||
std::puts("autostart - automatically run on startup (toggleable)");
|
|
||||||
std::puts("buffer - parses output of libinput debug-events");
|
|
||||||
std::puts("help - shows the help dialog");
|
|
||||||
std::puts("config - locates the config file");
|
|
||||||
std::puts("debug - logs raw output from input events taken from libinput");
|
|
||||||
std::puts("status - checks status of program and autostart");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_help__ */
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_start__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_start__
|
|
||||||
|
|
||||||
/*
|
|
||||||
Comfortable Swipe
|
|
||||||
by Rico Tiongson
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "_index.hpp"
|
|
||||||
#include <iostream> // std::cin, std::cout, std::ios
|
|
||||||
#include <cstdlib> // std::system
|
|
||||||
#include <unistd.h> // pipe, fork, perror, exit
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
|
||||||
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
|
|
||||||
* for the technical implementation.
|
|
||||||
*/
|
|
||||||
void start()
|
|
||||||
{
|
|
||||||
std::ios::sync_with_stdio(false);
|
|
||||||
std::cin.tie(0);
|
|
||||||
std::cout.tie(0);
|
|
||||||
std::cout.flush();
|
|
||||||
|
|
||||||
// redirect stdout to stdin
|
|
||||||
int fd[2];
|
|
||||||
pipe(fd); // create the pipes
|
|
||||||
|
|
||||||
int child;
|
|
||||||
if ((child = fork()) == -1) {
|
|
||||||
perror("fork");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
if (child) {
|
|
||||||
dup2(fd[1], STDOUT_FILENO);
|
|
||||||
comfortable_swipe::service::debug();
|
|
||||||
close(fd[0]);
|
|
||||||
} else {
|
|
||||||
dup2(fd[0], STDIN_FILENO);
|
|
||||||
comfortable_swipe::service::buffer();
|
|
||||||
close(fd[1]);
|
|
||||||
}
|
|
||||||
comfortable_swipe::service::stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_start__ */
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_status__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_status__
|
|
||||||
|
|
||||||
/*
|
|
||||||
Comfortable Swipe
|
|
||||||
by Rico Tiongson
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../_macro.cpp"
|
|
||||||
#include "../util/_index.hpp"
|
|
||||||
#include "../gesture/_index.hpp"
|
|
||||||
#include <stdexcept> // std::runtime_error
|
|
||||||
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
|
||||||
#include <memory> // std::unique_ptr
|
|
||||||
#include <array> // std::array
|
|
||||||
#include <cstdlib> // std::atoi
|
|
||||||
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
|
||||||
#include <regex> // std::cmatch, std::regex, std::regex_match
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Prints the status of comfortable-swipe.
|
|
||||||
*/
|
|
||||||
void status()
|
|
||||||
{
|
|
||||||
// std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
|
|
||||||
|
|
||||||
// check status of configuration file
|
|
||||||
try
|
|
||||||
{
|
|
||||||
std::puts(COMFORTABLE_SWIPE_CONFIG);
|
|
||||||
auto config = comfortable_swipe::util::read_config_file(COMFORTABLE_SWIPE_CONFIG);
|
|
||||||
// print threshold
|
|
||||||
if (config.count("threshold") > 0)
|
|
||||||
{
|
|
||||||
auto & threshold = config["threshold"];
|
|
||||||
// std::cmatch matches;
|
|
||||||
// bool ok = (std::regex_match(threshold.data(), matches, std::regex("^\\d+(?:\\.\\d+)??$")) != 0);
|
|
||||||
// print status of threshold
|
|
||||||
std::printf(" %9s = %s\n", "threshold", threshold.data()); // ok ? "VALID" : "INVALID"
|
|
||||||
}
|
|
||||||
else
|
|
||||||
std::printf(" %9s is OFF\n", "threshold");
|
|
||||||
|
|
||||||
// print swipe commands
|
|
||||||
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
|
|
||||||
{
|
|
||||||
if (config.count(command) > 0)
|
|
||||||
std::printf(" %9s = %s\n", command, config[command].data());
|
|
||||||
else
|
|
||||||
std::printf(" %9s NOT SET\n", command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::runtime_error& e)
|
|
||||||
{
|
|
||||||
std::printf("config error: %s\n", e.what());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_restart__ */
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_stop__
|
|
||||||
#define __COMFORTABLE_SWIPE__service_stop__
|
|
||||||
|
|
||||||
#include <cstdio> // std::FILE, std::feof, std::fgets
|
|
||||||
#include <cstdlib> // std::atoi, std::system
|
|
||||||
#include <string> // std::string, std::to_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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdexcept> // std::runtime_error
|
|
||||||
#include <unistd.h> // popen, pclose, getpid
|
|
||||||
#include <memory> // std::unique_ptr
|
|
||||||
#include <array> // std::array
|
|
||||||
#include <cstdlib> // std::atoi
|
|
||||||
#include <cstdio> // FILE, std::feof, std::fgets
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace service
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Stops all comfortable-swipe instances.
|
|
||||||
*/
|
|
||||||
void stop()
|
|
||||||
{
|
|
||||||
|
|
||||||
// read all service names from process (pgrep)
|
|
||||||
std::array<char, 128> buffer;
|
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
|
||||||
|
|
||||||
// make sure pipe exists
|
|
||||||
if (!pipe)
|
|
||||||
throw std::runtime_error("stop command failed");
|
|
||||||
|
|
||||||
// buffer what to kill
|
|
||||||
std::string kill = "kill";
|
|
||||||
|
|
||||||
// read until end of line
|
|
||||||
while (!std::feof(pipe.get()))
|
|
||||||
{
|
|
||||||
if (std::fgets(buffer.data(), buffer.size(), pipe.get()) != NULL)
|
|
||||||
{
|
|
||||||
int pid = std::atoi(buffer.data());
|
|
||||||
if (pid != getpid())
|
|
||||||
{
|
|
||||||
kill += " ";
|
|
||||||
kill += std::to_string(pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// run "kill {pid1} {pid2}..."
|
|
||||||
(void) std::system(kill.data());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_stop__ */
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__util_index_cpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__util_index_cpp__
|
|
||||||
|
|
||||||
#include "_index.hpp"
|
|
||||||
#include "read_config_file.cpp"
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__util_index_cpp__ */
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__util_index_hpp__
|
|
||||||
#define __COMFORTABLE_SWIPE__util_index_hpp__
|
|
||||||
|
|
||||||
#include <map> // std::map
|
|
||||||
#include <string> // std::string
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace util
|
|
||||||
{
|
|
||||||
std::map<std::string, std::string> read_config_file(const char*);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__util_index_hpp__ */
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__util_read_config_file__
|
|
||||||
#define __COMFORTABLE_SWIPE__util_read_config_file__
|
|
||||||
|
|
||||||
/*
|
|
||||||
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 <map> // std::map
|
|
||||||
#include <string> // std::string
|
|
||||||
#include <fstream> // std::ifstream
|
|
||||||
#include <iostream> // std::endl, std::getline
|
|
||||||
#include <sstream> // std::ostringstream
|
|
||||||
#include <cstdlib> // exit
|
|
||||||
#include <cctype> // std::isspace
|
|
||||||
#include <stdexcept> // std::runtime_error
|
|
||||||
|
|
||||||
namespace comfortable_swipe
|
|
||||||
{
|
|
||||||
namespace util
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* A utility method for reading the config file.
|
|
||||||
*
|
|
||||||
* @param filename (const char*) the path of the config file.
|
|
||||||
*/
|
|
||||||
std::map<std::string, std::string> read_config_file(const char* filename)
|
|
||||||
{
|
|
||||||
|
|
||||||
std::map<std::string, std::string> conf;
|
|
||||||
std::ifstream fin(filename, std::ios::in);
|
|
||||||
|
|
||||||
if (!fin.is_open())
|
|
||||||
{
|
|
||||||
throw std::runtime_error("config file does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string line, token[2];
|
|
||||||
int line_number = 0;
|
|
||||||
|
|
||||||
while (std::getline(fin, line))
|
|
||||||
{
|
|
||||||
++line_number;
|
|
||||||
token[0].clear();
|
|
||||||
token[1].clear();
|
|
||||||
int length = line.length();
|
|
||||||
int equal_flag = 0;
|
|
||||||
|
|
||||||
// tokenize comfig config
|
|
||||||
for (int i = 0; i < length; ++i)
|
|
||||||
{
|
|
||||||
if (line[i] == '#') // skip comments
|
|
||||||
break;
|
|
||||||
if (line[i] == '=') // flag equal sign
|
|
||||||
{
|
|
||||||
if (++equal_flag > 1)
|
|
||||||
{
|
|
||||||
std::ostringstream stream;
|
|
||||||
stream << "error in conf file " << filename << std::endl;
|
|
||||||
stream << "multiple equal signs in line " << line_number << std::endl;
|
|
||||||
throw std::runtime_error(stream.str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!std::isspace(line[i]))
|
|
||||||
{
|
|
||||||
// add to buffer
|
|
||||||
token[equal_flag].push_back(line[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignore empty lines
|
|
||||||
if (equal_flag == 0 && token[0].length() == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// no equal sign found in non-empty line
|
|
||||||
if (equal_flag == 0)
|
|
||||||
{
|
|
||||||
std::ostringstream stream;
|
|
||||||
stream << "error in conf file: " << filename << std::endl;
|
|
||||||
stream << "equal sign expected in line " << line_number << std::endl;
|
|
||||||
throw std::runtime_error(stream.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// equal sign found, add to tokens
|
|
||||||
if (token[1].length() > 0)
|
|
||||||
conf[token[0]] = token[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return conf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__util_read_config_file__ */
|
|
||||||
@@ -5,47 +5,76 @@
|
|||||||
#
|
#
|
||||||
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a list of
|
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a list of
|
||||||
# keycodes you can use.
|
# 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.
|
|
||||||
# (Note: Sky is the limit! Can be as large as 1000.0)
|
|
||||||
# Default: threshold = 0.0
|
|
||||||
threshold = 0.0
|
|
||||||
#############################
|
#############################
|
||||||
# THREE / FOUR FINGER SWIPE #
|
# THREE / FOUR FINGER SWIPE #
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
# 3-finger swipe left
|
# 3-finger swipe left
|
||||||
# The default shortcut is switching to the right workspace.
|
# The default shortcut is switching to the right workspace.
|
||||||
# Default: left3 = ctrl+alt+Right
|
# Default: left3 = ctrl+alt+Right
|
||||||
left3 = ctrl+alt+Right
|
left3 = ctrl+alt+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 left
|
# 4-finger swipe left
|
||||||
# The default shortcut is moving current window to the right workspace.
|
# The default shortcut is moving current window to the right workspace.
|
||||||
# Default: left4=ctrl+alt+shift+Right
|
# Default: left4=ctrl+alt+shift+Right
|
||||||
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
|
# 4-finger swipe right
|
||||||
# The default shortcut is moving current window to the left workspace.
|
# The default shortcut is moving current window to the left workspace.
|
||||||
# Default: right4=ctrl+alt+shift+Left
|
# Default: right4=ctrl+alt+shift+Left
|
||||||
right4 = ctrl+alt+shift+Left
|
right4 = ctrl+alt+shift+Left
|
||||||
|
|
||||||
# 3-finger swipe up
|
# 3-finger swipe up
|
||||||
# The default shortcut is switching to the workspace below.
|
# The default shortcut is switching to the workspace below.
|
||||||
# Default: up3 = ctrl+alt+Down
|
# Default: up3 = ctrl+alt+Down
|
||||||
up3 = ctrl+alt+Down
|
up3 = ctrl+alt+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 up
|
# 4-finger swipe up
|
||||||
# The default shortcut is moving current window to the bottom workspace.
|
# The default shortcut is moving current window to the bottom workspace.
|
||||||
# Default: ctrl+alt+shift+Down
|
# Default: ctrl+alt+shift+Down
|
||||||
up4 = 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
|
# 4-finger swipe down
|
||||||
# The default shortcut is moving current window to the above workspace.
|
# The default shortcut is moving current window to the above workspace.
|
||||||
# Default: ctrl+alt+shift+Up
|
# Default: ctrl+alt+shift+Up
|
||||||
down4 = ctrl+alt+shift+Up
|
down4 = ctrl+alt+shift+Up
|
||||||
|
|
||||||
|
#################
|
||||||
|
# MISCELLANEOUS #
|
||||||
|
#################
|
||||||
|
|
||||||
|
# Threshold
|
||||||
|
# Tweak this value depending on the sensitivity of your mousepad to perform
|
||||||
|
# gestures. A higher value means less sensitive (Sky is the limit! Can be as
|
||||||
|
# large as 1000.0).
|
||||||
|
# Default: threshold = 0.0
|
||||||
|
threshold = 0.0
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Experimental: MOUSE HOLD #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
# (1: left click, 2: middle click, 3: right click, 4: wheel up, 5: wheel down)
|
||||||
|
|
||||||
|
# You can set mouse buttons to hold
|
||||||
|
# hold3 = button1
|
||||||
|
# hold3 = button2
|
||||||
|
# hold3 = button3
|
||||||
|
|
||||||
|
# Or you can just let the mouse move with the cursor
|
||||||
|
# hold3 = move
|
||||||
|
|
||||||
|
# Use wheel scroll (experimental)
|
||||||
|
# hold4 = scroll
|
||||||
|
# hold4 = scroll_reverse
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
function install {
|
||||||
|
# prefer running as root
|
||||||
|
local dir="$(dirname "$0")"
|
||||||
|
local program="comfortable-swipe"
|
||||||
|
local program_exe="/usr/local/bin/$program"
|
||||||
|
local compile_command="$dir/cpp.compile.sh"
|
||||||
|
local compile_target="$dir/command_line.cpp"
|
||||||
|
local conf_path="/usr/local/share/$program/$program.conf"
|
||||||
|
local dconf_path="$dir/defaults.conf"
|
||||||
|
local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf"
|
||||||
|
|
||||||
|
if [ -x "$(command -v "$program_exe")" ]; then
|
||||||
|
# stop any running $program if it exists
|
||||||
|
"$program_exe" stop > /dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
#copy config file
|
||||||
|
abort () {
|
||||||
|
exec echo "Installation aborted"
|
||||||
|
}
|
||||||
|
sudo mkdir -p "$(dirname $conf_path)" || abort
|
||||||
|
|
||||||
|
# check if "-y" or "--yes" is passed as an argument
|
||||||
|
YES=false
|
||||||
|
while test $# -gt 0
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-y) YES=true
|
||||||
|
;;
|
||||||
|
--yes) YES=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
sudo chown $USER "$(dirname $conf_path)"
|
||||||
|
if [ ! -f "$conf_path" ]; then
|
||||||
|
if [ ! -f "$old_conf_path" ]; then
|
||||||
|
# old config file not found, create from scratch
|
||||||
|
cat "$dconf_path" > "$conf_path" || abort
|
||||||
|
else
|
||||||
|
# old config file found, move to the new path
|
||||||
|
cat "$old_conf_path" > "$conf_path" || abort
|
||||||
|
echo "Configuration copied from $old_conf_path to $conf_path"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# config file found, ask user if overwrite
|
||||||
|
echo "Old conf file found in $conf_path"
|
||||||
|
if [ "$YES" == false ]; then
|
||||||
|
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
||||||
|
response="${response,,}" # tolower
|
||||||
|
if [[ "$response" =~ ^(no|n)$ ]]; then
|
||||||
|
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
||||||
|
response="${response,,}"
|
||||||
|
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
||||||
|
cat "$dconf_path" > "$conf_path" || abort
|
||||||
|
else
|
||||||
|
abort
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installing to $program_exe ..."
|
||||||
|
|
||||||
|
# remove existing $program
|
||||||
|
if [ -x "$(command -v "$program_exe")" ]; then
|
||||||
|
sudo rm -f "$(which "$program")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# compile library
|
||||||
|
sudo "$compile_command" "$compile_target" -o "$program_exe" || abort
|
||||||
|
|
||||||
|
# add permissions to input group (defer)
|
||||||
|
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
|
||||||
|
|
||||||
|
# turn on autostart by default
|
||||||
|
local autostart_status="$("$program_exe" autostart)"
|
||||||
|
if [[ "$autostart_status" == *off* ]]; then
|
||||||
|
autostart_status="$("$program_exe" autostart)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Successfully installed $program $(cat $dir/VERSION | tr -d '[:space:]')"
|
||||||
|
echo ""
|
||||||
|
echo "$autostart_status"
|
||||||
|
echo "Edit configuration file: gedit \$($program config)"
|
||||||
|
echo ""
|
||||||
|
echo "Try running: $program start"
|
||||||
|
}
|
||||||
|
|
||||||
|
install
|
||||||
|
unset -f install
|
||||||
@@ -1 +0,0 @@
|
|||||||
psutil==5.6.0
|
|
||||||
@@ -1,179 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import setuptools
|
|
||||||
|
|
||||||
from shutil import copyfile
|
|
||||||
from setuptools import setup, find_packages
|
|
||||||
from setuptools.extension import Extension
|
|
||||||
from setuptools.command.develop import develop
|
|
||||||
from setuptools.command.install import install
|
|
||||||
from setuptools.command.easy_install import easy_install
|
|
||||||
from wheel.bdist_wheel import bdist_wheel
|
|
||||||
|
|
||||||
|
|
||||||
VERSION = '1.1.0-beta'
|
|
||||||
__CWD__ = os.getcwd()
|
|
||||||
__DIR__ = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
__URL__ = 'https://github.com/Hikari9/comfortable-swipe-ubuntu'
|
|
||||||
|
|
||||||
extension_names = ['service']
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
# make sure working directory is here
|
|
||||||
os.chdir(__DIR__)
|
|
||||||
|
|
||||||
|
|
||||||
# save README as long_description
|
|
||||||
with open('README.md', 'r') as README_file:
|
|
||||||
README = README_file.read()
|
|
||||||
|
|
||||||
|
|
||||||
# match constants with source
|
|
||||||
from comfortable_swipe.constants import *
|
|
||||||
|
|
||||||
# include old conf paths to list from previous versions
|
|
||||||
conf_paths = [
|
|
||||||
DEFAULT_CONFIG,
|
|
||||||
os.path.join(os.getenv('HOME', ''), '.config', 'comfortable-swipe', 'comfortable-swipe.conf'),
|
|
||||||
os.path.join('/usr/local/share', 'comfortable-swipe', 'comfortable-swipe.conf'),
|
|
||||||
CONFIG
|
|
||||||
]
|
|
||||||
|
|
||||||
# for C++ library
|
|
||||||
cpp_macros = dict(
|
|
||||||
COMFORTABLE_SWIPE_VERSION='"{}"'.format(VERSION),
|
|
||||||
COMFORTABLE_SWIPE_CONFIG='"{}"'.format(CONFIG)
|
|
||||||
)
|
|
||||||
|
|
||||||
# read C++ libraries for comfortable swipe
|
|
||||||
extensions = [Extension(
|
|
||||||
name='{}.cpp.{}'.format(PYTHON_NAME, extension_name),
|
|
||||||
define_macros=list(cpp_macros.items()),
|
|
||||||
sources=[os.path.join('cpp', '_python.cpp')],
|
|
||||||
extra_compile_args=['-O2', '-Wno-unused-result', '-std=c++11', '-lstdc++'],
|
|
||||||
libraries=['xdo']
|
|
||||||
) for extension_name in extension_names]
|
|
||||||
|
|
||||||
|
|
||||||
class Command:
|
|
||||||
outer_installer = None
|
|
||||||
outer_uninstaller = None
|
|
||||||
|
|
||||||
def pre_install(self):
|
|
||||||
# make sure only outer install script will run post_install
|
|
||||||
if self.__class__.outer_installer is not None: return
|
|
||||||
self.__class__.outer_installer = self
|
|
||||||
print('running pre_install')
|
|
||||||
|
|
||||||
def post_install(self):
|
|
||||||
# make sure post_install will only run when command is outer installer
|
|
||||||
if self.__class__.outer_installer is not self: return
|
|
||||||
print('running post_install')
|
|
||||||
|
|
||||||
# create program/config directories
|
|
||||||
if not os.path.exists(os.path.dirname(CONFIG)):
|
|
||||||
os.makedirs(os.path.dirname(CONFIG))
|
|
||||||
|
|
||||||
# copy any of the old config files
|
|
||||||
conf_files = [path for path in conf_paths if os.path.exists(path) and os.path.isfile(path)]
|
|
||||||
print('Using configuration file at', conf_files[-1])
|
|
||||||
|
|
||||||
if conf_files[-1] != CONFIG:
|
|
||||||
# new installation or upgrading from old version, copy to new location
|
|
||||||
copyfile(conf_files[-1], CONFIG)
|
|
||||||
if conf_files[-1] == DEFAULT_CONFIG:
|
|
||||||
# new installation - copy default configuration
|
|
||||||
print('Copying configuration file to', CONFIG)
|
|
||||||
else:
|
|
||||||
# upgrading - delete the deprecated config file (failsafe)
|
|
||||||
print('warning: depcrecated configuration file at', conf_files[-1])
|
|
||||||
print(' you have to remove this manually')
|
|
||||||
|
|
||||||
# enable autostart by default
|
|
||||||
from comfortable_swipe import autostart
|
|
||||||
autostart.set_status(autostart.ON)
|
|
||||||
print('Autostart created at', autostart.target_path())
|
|
||||||
print('\nInstallation successful\nTry running: {} start'.format(NAME))
|
|
||||||
|
|
||||||
def pre_uninstall(self):
|
|
||||||
# make sure only outer uninstall script will run post_uninstall
|
|
||||||
if self.__class__.outer_uninstaller is not None: return
|
|
||||||
self.__class__.outer_uninstaller = self
|
|
||||||
print('running pre_uninstall')
|
|
||||||
|
|
||||||
|
|
||||||
def post_uninstall(self):
|
|
||||||
# make sure post_uninstall will only run when command is outer uninstaller
|
|
||||||
if self.__class__.outer_uninstaller is not self: return
|
|
||||||
print('running post_uninstall')
|
|
||||||
from comfortable_swipe import autostart
|
|
||||||
if autostart.get_status() is autostart.ON:
|
|
||||||
print('Removing autostart at', autostart.target_path())
|
|
||||||
autostart.set_status(autostart.OFF)
|
|
||||||
|
|
||||||
# add post_install script to install method
|
|
||||||
def wrap_command(base_cls, uninstall=False):
|
|
||||||
class InstallCommand(Command, base_cls):
|
|
||||||
def run(self):
|
|
||||||
self.pre_uninstall() if uninstall and self.uninstall else self.pre_install()
|
|
||||||
base_cls.run(self)
|
|
||||||
self.post_uninstall() if uninstall and self.uninstall else self.post_install()
|
|
||||||
|
|
||||||
InstallCommand.__name__ = base_cls.__name__
|
|
||||||
return InstallCommand
|
|
||||||
|
|
||||||
# Override command classes here
|
|
||||||
cmdclass = dict(
|
|
||||||
install=wrap_command(install),
|
|
||||||
easy_install=wrap_command(easy_install),
|
|
||||||
develop=wrap_command(develop, uninstall=True),
|
|
||||||
bdist_wheel=wrap_command(bdist_wheel)
|
|
||||||
)
|
|
||||||
|
|
||||||
# install requiremenh open('requirements.txt', 'r') as requirements:
|
|
||||||
with open('requirements.txt', 'r') as requirements:
|
|
||||||
install_requires = requirements.read().splitlines()
|
|
||||||
|
|
||||||
# classifiers
|
|
||||||
# https://pypi.org/classifiers/
|
|
||||||
classifiers = [
|
|
||||||
'Development Status :: 4 - Beta'
|
|
||||||
'Intended Audience :: End Users/Desktop',
|
|
||||||
'Operating System :: POSIX :: Linux',
|
|
||||||
'Operating System :: Unix',
|
|
||||||
'Programming Language :: C++',
|
|
||||||
'Programming Language :: Python :: 2.7',
|
|
||||||
'Programming Language :: Python :: 3.5',
|
|
||||||
'Programming Language :: Python :: 3.6',
|
|
||||||
'Programming Language :: Python :: 3.7',
|
|
||||||
'Programming Language :: Python :: 3.8',
|
|
||||||
'Environment :: Console'
|
|
||||||
]
|
|
||||||
|
|
||||||
# setup python script
|
|
||||||
setup_script = setup(
|
|
||||||
name=NAME,
|
|
||||||
version=VERSION,
|
|
||||||
description=DESCRIPTION,
|
|
||||||
long_description=README,
|
|
||||||
license='MIT',
|
|
||||||
author='Rico Tiongson',
|
|
||||||
author_email='thericotiongson@gmail.com',
|
|
||||||
url=__URL__,
|
|
||||||
zip_safe=False,
|
|
||||||
packages=find_packages(),
|
|
||||||
include_package_data=True,
|
|
||||||
entry_points=dict(console_scripts=['{}={}.__main__:main'.format(NAME, PYTHON_NAME)]),
|
|
||||||
ext_modules=extensions,
|
|
||||||
cmdclass=cmdclass,
|
|
||||||
install_requires=install_requires,
|
|
||||||
classifiers=classifiers
|
|
||||||
)
|
|
||||||
|
|
||||||
finally:
|
|
||||||
# move working directory back to where it was before
|
|
||||||
os.chdir(__CWD__)
|
|
||||||
+23
-5
@@ -1,6 +1,24 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
DIR=$(dirname $0)
|
set -e
|
||||||
g++ -std=c++11 -O2 $DIR/test_regex.cpp -lxdo -o test.out || exec "Test aborted"
|
|
||||||
./test.out || rm test.out
|
DIR="$(dirname "$0")"
|
||||||
rm test.out
|
|
||||||
|
# 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
|
||||||
|
/bin/bash "$sh" || abort
|
||||||
|
done
|
||||||
|
|
||||||
|
# run all cpp files in this directory
|
||||||
|
for cpp in "$DIR/test_"*.cpp; do
|
||||||
|
g++ -std=c++11 -O2 "$cpp" -lxdo -o "$tempout" || abort
|
||||||
|
"$tempout" || abort
|
||||||
|
done
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
DIR="$(dirname "$0")"
|
||||||
|
root="$(dirname "$DIR")"
|
||||||
|
compiler="$root/cpp.compile.sh"
|
||||||
|
command_line="$root/command_line.cpp"
|
||||||
|
module="$root/comfortable_swipe"
|
||||||
|
|
||||||
|
# just call abort on error
|
||||||
|
tempout="$(mktemp)"
|
||||||
|
abort () {
|
||||||
|
rm "$tempout"
|
||||||
|
echo "Test aborted"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# try to compile every cpp/hpp file in module
|
||||||
|
# header files first
|
||||||
|
# then compile cpp files
|
||||||
|
# finally, compile command line
|
||||||
|
shopt -s nullglob
|
||||||
|
for cpp in \
|
||||||
|
"$module"/**/*.h \
|
||||||
|
"$module"/**/*.hpp \
|
||||||
|
"$module"/**/*.cpp \
|
||||||
|
"$module"/lib \
|
||||||
|
"$command_line"
|
||||||
|
do
|
||||||
|
"$compiler" -c "$cpp" -o "$tempout" || abort
|
||||||
|
done
|
||||||
+29
-30
@@ -1,9 +1,9 @@
|
|||||||
#include <iostream>
|
#include "../comfortable_swipe/gesture/swipe_gesture.h"
|
||||||
|
#include "../comfortable_swipe/gesture/swipe_gesture.regex.cpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../lib/gesture/swipe_gesture.h"
|
|
||||||
#include "../lib/gesture/swipe_gesture.regex.cpp"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
@@ -23,15 +23,13 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace test
|
namespace test {
|
||||||
{
|
|
||||||
void gesture_begin_should_match_regex();
|
void gesture_begin_should_match_regex();
|
||||||
void gesture_update_should_match_regex();
|
void gesture_update_should_match_regex();
|
||||||
void gesture_end_should_match_regex();
|
void gesture_end_should_match_regex();
|
||||||
}
|
} // namespace test
|
||||||
|
|
||||||
int main()
|
int main() {
|
||||||
{
|
|
||||||
std::cout << "(1) Testing gesture_begin_should_match_regex()" << std::endl;
|
std::cout << "(1) Testing gesture_begin_should_match_regex()" << std::endl;
|
||||||
test::gesture_begin_should_match_regex();
|
test::gesture_begin_should_match_regex();
|
||||||
|
|
||||||
@@ -43,13 +41,9 @@ int main()
|
|||||||
std::cout << "ALL TEST PASSED" << std::endl;
|
std::cout << "ALL TEST PASSED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace test
|
namespace test {
|
||||||
{
|
void gesture_begin_test(const std::regex &matcher, const char *data,
|
||||||
void gesture_begin_test(
|
const char *expected_fingers) {
|
||||||
const std::regex& matcher,
|
|
||||||
const char* data,
|
|
||||||
const char* expected_fingers)
|
|
||||||
{
|
|
||||||
std::cout << " testing against \"" << data << "\"...";
|
std::cout << " testing against \"" << data << "\"...";
|
||||||
std::cmatch matches;
|
std::cmatch matches;
|
||||||
int result = std::regex_match(data, matches, matcher);
|
int result = std::regex_match(data, matches, matcher);
|
||||||
@@ -58,19 +52,24 @@ namespace test
|
|||||||
std::cout << "PASSED" << std::endl;
|
std::cout << "PASSED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gesture_begin_should_match_regex()
|
void gesture_begin_should_match_regex() {
|
||||||
{
|
std::regex matcher(
|
||||||
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
comfortable_swipe::gesture::swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
||||||
test::gesture_begin_test(matcher, " event15 GESTURE_SWIPE_BEGIN +34.33s 3\n", "3");
|
test::gesture_begin_test(matcher, " event15 GESTURE_SWIPE_BEGIN +34.33s 3\n",
|
||||||
test::gesture_begin_test(matcher, "-event4 GESTURE_SWIPE_BEGIN +3.12s 4\n", "4");
|
"3");
|
||||||
test::gesture_begin_test(matcher, "-event7 GESTURE_SWIPE_BEGIN +4.72s 3\n", "3");
|
test::gesture_begin_test(matcher, "-event4 GESTURE_SWIPE_BEGIN +3.12s 4\n",
|
||||||
test::gesture_begin_test(matcher, " event9 GESTURE_SWIPE_BEGIN +45.80s 4\n", "4");
|
"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()
|
void gesture_update_should_match_regex() {
|
||||||
{
|
const char *data = " event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 "
|
||||||
const char* data = " event15 GESTURE_SWIPE_UPDATE +34.70s 3 -0.12/ 4.99 (-0.33/13.50 unaccelerated)\n";
|
"(-0.33/13.50 unaccelerated)\n";
|
||||||
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
std::regex matcher(
|
||||||
|
comfortable_swipe::gesture::swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
||||||
std::cmatch matches;
|
std::cmatch matches;
|
||||||
auto result = std::regex_match(data, matches, matcher);
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
assert(result != 0);
|
assert(result != 0);
|
||||||
@@ -81,13 +80,13 @@ namespace test
|
|||||||
assert((std::string)matches[5] == "13.50");
|
assert((std::string)matches[5] == "13.50");
|
||||||
}
|
}
|
||||||
|
|
||||||
void gesture_end_should_match_regex()
|
void gesture_end_should_match_regex() {
|
||||||
{
|
|
||||||
const char *data = " event15 GESTURE_SWIPE_END +35.03s 3\n";
|
const char *data = " event15 GESTURE_SWIPE_END +35.03s 3\n";
|
||||||
std::regex matcher(comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
std::regex matcher(
|
||||||
|
comfortable_swipe::gesture::swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
std::cmatch matches;
|
std::cmatch matches;
|
||||||
auto result = std::regex_match(data, matches, matcher);
|
auto result = std::regex_match(data, matches, matcher);
|
||||||
assert(result != 0);
|
assert(result != 0);
|
||||||
assert((std::string)matches[1] == "3");
|
assert((std::string)matches[1] == "3");
|
||||||
}
|
}
|
||||||
}
|
} // namespace test
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo "Uninstalling..."
|
||||||
|
rm "${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop" 2> /dev/null
|
||||||
|
comfortable-swipe stop 2> /dev/null
|
||||||
|
rm "$HOME/.local/bin/comfortable-swipe" 2> /dev/null # compat
|
||||||
|
sudo rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
||||||
|
echo "Successfully uninstalled comfortable-swipe"
|
||||||
Reference in new issue
Block a user