From 6890ec46969944e55591b5145b431465d1d68e35 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Wed, 15 Nov 2017 11:00:06 +0800 Subject: [PATCH 1/2] [move-config] Move configuration file to /usr/local/share/comfortable-swipe/comfortable-swipe.conf --- README.md | 38 +++++++++++--------------------------- install | 35 +++++++++++++++++++++++++---------- src/comfortable-swipe.cpp | 13 ++----------- 3 files changed, 38 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 59c215d..0e0d9bd 100644 --- a/README.md +++ b/README.md @@ -28,43 +28,27 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures ## How to Run -1. Make sure `~/.local/bin/` is added to your PATH. -2. Run - +1. You'll need some group permissions to read touchpad input data. Run + ```bash + sudo gpasswd -a $USER $(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) + ``` +2. ***Important***: After inputing your `sudo` password, log out then log back in +3. Run ``` comfortable-swipe start ``` - -3. Optional: Automatically run on startup - +4. Optional: Automatically run on startup ``` comfortable-swipe autostart ``` - -### Permissions -Sometimes, you'll need some permissions to read touchpad input data. - -1. Find out your permission group with `ls -l /dev/input/event*` - ```bash - $ ls -l /dev/input/event* - - crw-rw---- 1 root input 13, 64 Oct 23 23:09 /dev/input/event0 - crw-rw---- 1 root input 13, 65 Oct 23 23:09 /dev/input/event1 - crw-rw---- 1 root input 13, 66 Oct 23 23:09 /dev/input/event2 - crw-rw---- 1 root input 13, 67 Oct 23 23:09 /dev/input/event3 +5. Optional: Change keyboard configurations (refer [below](#configurations)). + Then restart after making changes with ``` - -2. Check the fourth column (e.g. `input`) then run: - ```bash - sudo gpasswd -a $USER input + comfortable-swipe restart ``` - > Note: Don't forget to input your `sudo` password! - -3. ***Important***: Log out / Log back in ## Configurations -The configuration file is located at `~/.config/comfortable-swipe.conf`. -Make sure to run `comfortable-swipe restart` after making changes. +Comfortable swipe makes use of keyboard shortcuts for configurations. The configuration file is located at `/usr/share/comfortable-swipe/comfortable-swipe.conf`. Make sure to run `comfortable-swipe restart` after making changes. Property | Description | Default Value | Default Behavior --------- | ----------- | -------------- | ----- diff --git a/install b/install index 2108fd1..36752e1 100755 --- a/install +++ b/install @@ -1,6 +1,10 @@ #!/bin/bash +# prefer running as root DIR=$(dirname $0) PROGRAM=/usr/local/bin/comfortable-swipe +CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf +DCONF_PATH=$DIR/src/defaults.conf +OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf if [ -x "$(command -v $PROGRAM)" ]; then # stop any running comfortable-swipe if it exists @@ -10,11 +14,19 @@ if [ -x "$(command -v $PROGRAM)" ]; then fi #copy config file -mkdir -p ~/.config -DCONF_PATH=$DIR/src/defaults.conf -CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf +abort () { + exec echo "Installation aborted" +} +mkdir -p $(dirname $CONF_PATH) || abort if [ ! -f $CONF_PATH ]; then - cat $DCONF_PATH > $CONF_PATH + 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" @@ -24,9 +36,9 @@ else 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 + cat $DCONF_PATH > $CONF_PATH || abort else - exec echo "Installation aborted." + abort fi fi fi @@ -34,8 +46,11 @@ echo "Installing..." # mkdir -p ~/.local/bin g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM || exec echo "Installation aborted" -# toggle autostart twice to refresh any changes -$PROGRAM autostart > /dev/null || exec echo "Installation aborted" -$PROGRAM autostart > /dev/null || exec echo "Installation aborted" +GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort -echo "Successfully installed. You may now run 'comfortable-swipe start'." +# toggle autostart twice to refresh any changes +$PROGRAM autostart > /dev/null || abort +$PROGRAM autostart > /dev/null || abort + +echo "Successfully installed comfortable-swipe." +echo "Configuration file is located at $CONF_PATH" diff --git a/src/comfortable-swipe.cpp b/src/comfortable-swipe.cpp index 20edbc3..8cde1f3 100644 --- a/src/comfortable-swipe.cpp +++ b/src/comfortable-swipe.cpp @@ -32,6 +32,7 @@ along with this program. If not, see . #include #define cstr const string& #define PROGRAM "/usr/local/bin/comfortable-swipe" +#define CONFIG "/usr/local/share/comfortable-swipe/comfortable-swipe.conf" using namespace std; extern "C" { @@ -185,17 +186,7 @@ struct swipe_gesture_impl : swipe_gesture { namespace service { // get the full path of the .conf file string conf_filename() { - static string *filename = NULL; - if (filename == NULL) { - const char* xdg_config = getenv("XDG_CONFIG_HOME"); - string config( - xdg_config == NULL - ? string(getenv("HOME")) + "/.config" - : xdg_config - ); - filename = new string(config + "/comfortable-swipe.conf"); - } - return *filename; + return CONFIG; } // get the full path of the .desktop file associated // with the autostart feature From 823ea396a17c9b5ae523faf70d94b3631330bc2c Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Wed, 15 Nov 2017 11:08:16 +0800 Subject: [PATCH 2/2] [move-config] Update README --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e0d9bd..cda65b6 100644 --- a/README.md +++ b/README.md @@ -37,12 +37,11 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures ``` comfortable-swipe start ``` -4. Optional: Automatically run on startup +4. _Optional_: Automatically run on startup ``` comfortable-swipe autostart ``` -5. Optional: Change keyboard configurations (refer [below](#configurations)). - Then restart after making changes with +5. _Optional_: Change keyboard [configurations](#configurations). After making changes, run ``` comfortable-swipe restart ```