Improve README and install script

This commit is contained in:
Rico Tiongson 2019-03-15 10:35:09 +08:00
parent 9a3a2b7da6
commit 738fe57be3
4 changed files with 101 additions and 87 deletions

View File

@ -50,7 +50,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
## Configurations ## Configurations
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
``` ```
nano $(comfortable-swipe config) gedit $(comfortable-swipe config)
``` ```
Make sure to run after making changes: Make sure to run after making changes:
@ -130,12 +130,13 @@ Download the `uninstall` script then run `bash uninstall`
Create an issue [here](https://github.com/Hikari9/comfortable-swipe/issues/new) to report a bug. Create an issue [here](https://github.com/Hikari9/comfortable-swipe/issues/new) to report a bug.
Please include the output of the following: Please include the output of the following:
```
lsb_release -a 1. `lsb_release -a`
g++ --version 2. `g++ --version`
xinput list | grep touchpad -i 3. `ls -l /dev/input/event*`
lsmod | grep hid 3. `xinput list | grep touchpad -i`
comfortable-swipe start # if you can run it 4. `lsmod | grep hid`
comfortable-swipe debug # screenshot / first few lines 5. `comfortable-swipe status`
cat $(comfortable-swipe config) 6. `comfortable-swipe start` (if you can run it)
``` 7. `comfortable-swipe debug` (try swiping if you can see `GESTURE_SWIPE_XXX`)
8. `cat $(comfortable-swipe config)`

View File

@ -1,3 +1,7 @@
#!/bin/sh #!/bin/sh
dir="$(dirname $0)" dir="$(dirname $0)"
g++ "$dir/comfortable-swipe.cpp" -std=c++11 -O2 -lxdo -Wno-unused-result -o -DCOMFORTABLE_SWIPE_VERSION="$(cat $dir/VERSION)" "$1" g++ "$dir/comfortable-swipe.cpp" \
-o "$1" \
-std=c++11 \
-O2 -lxdo -Wno-unused-result \
-DCOMFORTABLE_SWIPE_VERSION="\"$(cat $dir/VERSION | tr -d '[:space:]')\""

109
install
View File

@ -1,27 +1,30 @@
#!/bin/bash #!/bin/bash
# prefer running as root
DIR=$(dirname $0)
PROGRAM=/usr/local/bin/comfortable-swipe
COMPILE=$DIR/comfortable-swipe.compile.sh
CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf
DCONF_PATH=$DIR/defaults.conf
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
if [ -x "$(command -v $PROGRAM)" ]; then function install {
# stop any running comfortable-swipe if it exists # prefer running as root
$PROGRAM stop local dir="$(dirname $0)"
fi local program=comfortable-swipe
local program_exe=/usr/local/bin/$program
local compile_command="$dir/$program.compile.sh"
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"
#copy config file if [ -x "$(command -v $program_exe)" ]; then
abort () { # stop any running $program if it exists
$program_exe stop
fi
#copy config file
abort () {
exec echo "Installation aborted" exec echo "Installation aborted"
} }
sudo mkdir -p $(dirname $CONF_PATH) || abort sudo mkdir -p "$(dirname $conf_path)" || abort
# check if "-y" or "--yes" is passed as an argument # check if "-y" or "--yes" is passed as an argument
YES=false YES=false
while test $# -gt 0 while test $# -gt 0
do do
case "$1" in case "$1" in
-y) YES=true -y) YES=true
;; ;;
@ -29,54 +32,62 @@ do
;; ;;
esac esac
shift shift
done done
sudo chown $USER $(dirname $CONF_PATH) sudo chown $USER "$(dirname $conf_path)"
if [ ! -f $CONF_PATH ]; then if [ ! -f "$conf_path" ]; then
if [ ! -f $OLD_CONF_PATH ]; then if [ ! -f "$old_conf_path" ]; then
# old config file not found, create from scratch # old config file not found, create from scratch
cat $DCONF_PATH > $CONF_PATH || abort cat "$dconf_path" > "$conf_path" || abort
else else
# old config file found, move to the new path # old config file found, move to the new path
cat $OLD_CONF_PATH > $CONF_PATH || abort cat "$old_conf_path" > "$conf_path" || abort
echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH" echo "Configuration copied from $old_conf_path to $conf_path"
fi fi
else else
# config file found, ask user if overwrite # config file found, ask user if overwrite
echo "Old conf file found in $CONF_PATH" echo "Old conf file found in $conf_path"
if [ $YES == false ]; then if [ "$YES" == false ]; then
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
response=${response,,} # tolower response="${response,,}" # tolower
if [[ "$response" =~ ^(no|n)$ ]]; then if [[ "$response" =~ ^(no|n)$ ]]; then
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
response=${response,,} response="${response,,}"
if [[ "$response" =~ ^(yes|y)$ ]]; then if [[ "$response" =~ ^(yes|y)$ ]]; then
cat $DCONF_PATH > $CONF_PATH || abort cat "$dconf_path" > "$conf_path" || abort
else else
abort abort
fi fi
fi fi
fi fi
fi fi
echo "Installing..." echo "Installing to $program_exe ..."
# remove existing comfortable-swipe # remove existing $program
if [ -x "$(command -v $PROGRAM)" ]; then if [ -x "$(command -v $program_exe)" ]; then
sudo rm -f $(which comfortable-swipe) sudo rm -f "$(which $program)"
fi fi
# compile library # compile library
sudo $COMPILE $PROGRAM || abort sudo "$compile_command" "$program_exe" || abort
# add permissions to input group (defer) # add permissions to input group (defer)
# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort # GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort
# toggle autostart twice to refresh any changes # turn on autostart by default
$PROGRAM autostart > /dev/null || abort local autostart_status="$($program_exe autostart)"
$PROGRAM autostart > /dev/null || abort if [[ "$autostart_status" == *off* ]]; then
autostart_status="$($program_exe autostart)"
fi
echo "Successfully installed comfortable-swipe." echo "Successfully installed $program $(cat $dir/VERSION | tr -d '[:space:]')"
echo "Configuration file is located at $CONF_PATH" echo ""
echo "" echo "$autostart_status"
echo "Try running 'comfortable-swipe start' to test." echo "Edit configuration file: gedit \$($program config)"
echo ""
echo "Try running: $program start"
}
install
unset -f install

View File

@ -50,19 +50,13 @@ namespace comfortable_swipe::service
auto autostart_f = comfortable_swipe::util::autostart_filename(); auto autostart_f = comfortable_swipe::util::autostart_filename();
bool autostart_on = access(autostart_f, F_OK) != -1; bool autostart_on = access(autostart_f, F_OK) != -1;
// print status std::puts(comfortable_swipe::util::conf_filename());
std::printf("program is %s\n", running ? "ON" : "OFF");
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
std::printf("config file at %s\n", comfortable_swipe::util::conf_filename());
// check status of configuration file // check status of configuration file
try try
{ {
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename()); auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
// print keys and values of config file
std::printf("\nConfigurations:\n");
// print threshold // print threshold
if (config.count("threshold") > 0) if (config.count("threshold") > 0)
{ {
@ -91,6 +85,10 @@ namespace comfortable_swipe::service
{ {
std::printf("config error: %s\n", e.what()); std::printf("config error: %s\n", e.what());
} }
// print status
std::printf("autostart is %s\n", autostart_on ? "ON" : "OFF");
std::printf("comfortable-swipe program is %s\n", running ? "RUNNING" : "STOPPED");
} }
} }