Add --bare flag

This commit is contained in:
Rico Tiongson 2020-05-02 01:27:35 +08:00
parent c399f3d72b
commit b83b01c0ca
3 changed files with 119 additions and 115 deletions

169
README.md
View File

@ -48,34 +48,26 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
1. **_Important_**: After inputing your `sudo` password, log out then log back in
1. Run
```bash
comfortable-swipe start
```
1. (Optional) Automatically run on startup
```bash
comfortable-swipe autostart on
```
1. You can check general program status
```basha
$> comfortable-swipe status
Autostart is ON
Program is RUNNING
```
## List of Commands
1. Program
1. Start the Program
```
comfortable-swipe start
comfortable-swipe stop
comfortable-swipe status
```
You will see this output:
```
$ comfortable-swipe start
Comfortable swipe is RUNNING in the background
```
1. Autostart (this is turned on by default)
```bash
comfortable-swipe autostart [on|off|toggle|status|path]
```
1. Help / version
@ -85,47 +77,76 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
comfortable-swipe --version
```
1. Autostart
1. List configurations
```bash
comfortable-swipe autostart [on|off|toggle|status|path]
```
If you want to list down configurations, you can run:
1. Configurations
```bash
comfortable-swipe config list
comfortable-swipe config get <KEY>
comfortable-swipe config set <KEY> [=] <VALUE>
comfortable-swipe config delete <KEY>
Configuration:
comfortable-swipe <PROPERTY> gets configuration property
comfortable-swipe <PROPERTY> [=] <VALUE> sets configuration to a value
Valid props: left3, left4, right3, right4, up3, up4, down3, down4, threshold, mouse3, mouse4
```
Get config:
1. Get config (examples)
```bash
$> comfortable-swipe config get left3
$ comfortable-swipe left3
ctrl+alt+Right
$ comfortable-swipe left4
ctrl+alt+shift+Right
$ comfortable-swipe right3
ctrl+alt+Left
$ comfortable-swipe right4
ctrl+alt+shift+Left
$ comfortable-swipe up3
ctrl+alt+Down
$ comfortable-swipe up4
ctrl+alt+shift+Down
$ comfortable-swipe down3
ctrl+alt+Up
$ comfortable-swipe down4
ctrl+alt+shift+Up
$ comfortable-swipe threshold
1.0
```
Set config (whitespace ignored):
```bash
$> comfortable-swipe config set up4 super+Up
up4 = super+Up
1. Set config (examples)
$> comfortable-swipe config set left3 = super+Right
```bash
$ comfortable-swipe left3 = super+Right
left3 = super+Right
$> comfortable-swipe config set right3 = super + Left + alt
right3 = super+Left+alt
$ comfortable-swipe right3 = super+Left
right3 = super+Left
$ comfortable-swipe right4 = super + Left + alt
right4 = super+Left+alt
```
Delete config:
1. Delete config
```bash
$> comfortable-swipe config delete mouse3
$ comfortable-swipe config delete mouse3
Deleted:
left3 = ctrl+super+Right
```
List all cofigurations
1. List all cofigurations
```bash
$> comfortable-swipe config list
$ comfortable-swipe config list
threshold = 1.0
left4 = ctrl+super+shift+Right
right3 = ctrl+super+Left
@ -138,60 +159,20 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
left3 = ctrl+super+Right
```
Show all possible keys:
1. Show path to config file:
```bash
$> comfortable-swipe config keys
left3
left4
right3
right4
up3
up4
down3
down4
threshold
mouse3
mouse4
```
$ comfortable-swipe config path
Show path to config file:
```bash
$> comfortable-swipe config path
/home/hikari9/.config/comfortable-swipe.conf
```
1. (Advanced) Invoke program buffer with `comfortable-swipe buffer`
```bash
cat <<"EOF" | comfortable-swipe buffer
-event7 GESTURE_SWIPE_BEGIN +0.45s 3
event7 GESTURE_SWIPE_UPDATE +0.45s 3 8.81/-2.34 (32.48/-8.62 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.46s 3 15.54/-3.88 (41.99/-10.50 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.46s 3 18.09/-4.16 (48.88/-11.25 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.47s 3 19.67/-3.61 (53.15/-9.75 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.48s 3 19.79/-3.19 (53.48/-8.62 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.49s 3 17.72/-2.36 (47.90/-6.37 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.49s 3 15.66/-2.36 (42.32/-6.37 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.50s 3 13.35/-2.08 (36.09/-5.62 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.51s 3 10.80/-1.94 (29.20/-5.25 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.52s 3 8.38/-1.53 (22.64/-4.12 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.53s 3 6.43/-1.25 (17.39/-3.37 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.53s 3 4.86/-0.83 (13.12/-2.25 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.54s 3 3.76/-0.55 (10.17/-1.50 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.55s 3 2.67/-0.28 ( 7.22/-0.75 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.56s 3 1.70/ 0.28 ( 4.59/ 0.75 unaccelerated)
event7 GESTURE_SWIPE_UPDATE +0.56s 3 1.09/ 0.14 ( 2.95/ 0.37 unaccelerated)
event7 GESTURE_SWIPE_END +0.59s 3
EOF
```
## Configuring Swipe Gestures
## Swipe Gesture Configurations
The default configuration file is located at `~/.config/comfortable-swipe.conf`.
Comfortable swipe makes use of keyboard shortcuts to perform swipes through `xdotool`.
Comfortable swipe makes use of **keyboard shortcuts** to perform swipes, through `xdotool`.
Edit configurations by running:
Edit the configuration file by running:
```
gedit ~/.config/comfortable-swipe.conf
@ -200,17 +181,17 @@ gedit ~/.config/comfortable-swipe.conf
After making changes, make sure to restart the program:
```
comfortable-swipe restart
comfortable-swipe start
```
> **Note**: For v1.1.0 below, the configuration file is located at
> **Warning**: For v1.1.0 below, the configuration file is located at
> `/usr/local/share/comfortable-swipe/comfortable-swipe.conf`
> **Note**: You can locate your configuration by running `comfortable-swipe config path`
> **Note**: You can locate the absolute path to your configuration by running: `comfortable-swipe config path`
## Configuration Reference
| Key | Value | Example |
| Key | Value | Defaults |
| --------- | :--------------------------------------------------------------------: | ------------------------------------------------------------ |
| left3 | 3-finger swipe left | ctrl+alt+Right |
| left4 | 4-finger swipe left | ctrl+alt+shift+Right |
@ -220,7 +201,7 @@ comfortable-swipe restart
| up4 | 4-finger swipe up | ctrl+alt+shift+Down |
| down3 | 3-finger swipe down | ctrl+alt+Up |
| down4 | 4-finger swipe down | ctrl+alt+shift+Up |
| thresmouse | mouse movement pixels that trigger a swipe (can be as large as 1000.0) | 0.0, 240.0, 1000.0 |
| threshold | mouse movement pixels that trigger a swipe (can be as large as 1000.0) | 0.0, 240.0, 1000.0 |
| mouse3 | mouses a mouse button when 3 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental)) | |
| mouse4 | mouses a mouse button when 4 fingers are down | button1 (see [Mouse Gestures](#mouse-gestures-experimental) |

View File

@ -37,9 +37,10 @@ Global Options:
-v, --version print the program version
Commands:
start [--attach]
start [--attach|--bare]
starts 3/4-finger gesture service in a detached process
flag '--attach' to attach the output in the console
--attach attach process to console
--bare attach with bare configurations
stop
stops 3/4-finger gesture service
@ -82,14 +83,16 @@ case $i in
echo "comfortable-swipe $VERSION"
exit 0
;;
--attach)
--attach | --bare) # for start
if [[ "$1" != start ]]; then
if [[ "$1" != buffer ]]; then
echo "Unknown option: $i" >&2
exit 1
fi
fi
OPTION_ATTACH="true"
;;
*)
# unknown option
if [[ "$i" == -* ]]; then
echo "Unknown option: $i" >&2
exit 1
@ -98,7 +101,6 @@ case $i in
esac
done
#########
# START #
#########
@ -108,12 +110,12 @@ done
# internally pipes debug text to the buffer
function start {
stop > /dev/null 2>&1
if [[ "$1" == "--attach" ]]; then
if [[ "$OPTION_ATTACH" == "true" ]]; then
# attach the buffered output
debug | buffer
debug | buffer $@
else
# detach buffered output
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer >/dev/null 2>&1 &
nohup "$BASENAME" debug </dev/null 2>&1 | "$BASENAME" buffer $@ >/dev/null 2>&1 &
echo "Comfortable swipe is RUNNING in the background"
fi
}
@ -254,7 +256,7 @@ function config {
# echo >&2
usage >&2
echo >&2
echo "If you want to list down properties, you can instead try:" >&2
echo "If you want to list down configurations, you can run:" >&2
echo >&2
echo " $BASENAME config list" >&2
echo >&2
@ -288,8 +290,11 @@ function config {
echo "$DELETE"
local RESULT="$(egrep -v "^\\s*($(echo "$DELETE" | awk '{print $1}' | paste -s -d '|'))\\s*=" "$CONFIG")"
echo "$RESULT" > "$CONFIG"
# restart comfortable-swipe
start
# restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then
stop > /dev/null 2>&1
start > /dev/null
fi
fi
}
@ -372,7 +377,11 @@ function config {
fi
# show newly set value
echo "$KEY = $(get "$KEY")"
start
# restart comfortable-swipe if it is running
if [[ "$(status)" == ON ]]; then
stop > /dev/null 2>&1
start > /dev/null
fi
}
######################

View File

@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "comfortable-swipe-gesture-swipe.cpp"
#include <iostream> // std::ios, std::cin, std::getline
#include <map> // std::map
#include <set> // std::set
#include <string> // std::string
extern "C" {
@ -53,19 +54,29 @@ int parse_config(void *config, const char section[], const char name[],
/**
* The main driver program.
*/
int main() {
int main(int argc, char* argv[]) {
using namespace std;
using namespace comfortable_swipe;
// unsync stdio for faster IO
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// get configuration file
// parse configuration file
map<string, string> config;
if (ini_parse(COMFORTABLE_SWIPE_CONFIG, parse_config, &config) < 0) {
cerr << "error: config " << COMFORTABLE_SWIPE_CONFIG << endl;
return EXIT_FAILURE;
}
// clear config and just use "threshold" if --bare
if (set<string>(argv + 1, argv + argc).count("--bare")) {
if (config.count("threshold")) {
auto threshold = config["threshold"];
config.clear();
config["threshold"] = threshold;
} else {
config.clear();
}
}
// initialize keyboard swipe gesture handler
// commands are: [left|up|right|down][3|4]
// we will fetch our commands from the config in correct order
@ -75,10 +86,13 @@ int main() {
// up3=super+Up maximize
// down3=super+Down minimize
decltype(gesture_swipe_xdokey::commands) commands;
for (size_t i = 0; i < commands.size(); ++i) {
for (size_t i = 0; i < commands.size(); ++i)
commands[i] = config[gesture_swipe_xdokey::command_name[i]];
}
gesture_swipe_xdokey keyswipe(commands, stof(config["threshold"]));
// correctly parse threshold as float
float threshold = 0.0f;
try { threshold = stof(config["threshold"]); } catch(std::invalid_argument) { }
// create swipe handler
gesture_swipe_xdokey keyswipe(commands, threshold);
// initialize mouse hold gesture handler
// for now, this supports 3-finger and 4-finger hold
// Examples: