Merge pull request #5 from Hikari9/autostart-feature

Autostart feature
This commit is contained in:
Rico Tiongson 2017-10-23 23:39:08 +08:00 committed by GitHub
commit c2ac0e9829
4 changed files with 124 additions and 35 deletions

View File

@ -1,38 +1,58 @@
# Comfortable Swipe (Ubuntu)
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
Comfortable 3-finger (and 4-finger) swipe gestures for Ubuntu 14.04 LTS+
Comfortable 3-finger (and 4-finger) touchpad swipe gestures for Ubuntu 14.04 LTS onwards (and possibly other Linux distros).
## Installation
1. `sudo apt-get install git libinput-tools libxdo-dev`
2. `git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git`
3. `cd comfortable-swipe-ubuntu`
4. `bash install`
5. You may delete the downloaded `comfortable-swipe-ubuntu` folder.
1. Install `libinput-tools` and `libxdo-dev`
```bash
sudo apt-get install libinput-tools libxdo-dev
```
2. Clone this repository
```bash
git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git
```
3. Install
```bash
cd comfortable-swipe-ubuntu
bash install
```
4. You may delete the downloaded `comfortable-swipe-ubuntu` folder.
## How to Run
1. Run `comfortable-swipe start` in Terminal
1. `comfortable-swipe start` or `~/.local/bin/comfortable-swipe start`
2. Flick away!
> If you're getting *command not found*, try running: `/home/$USER/.local/bin/comfortable-swipe start`
### Permissions
Sometimes, you'll need some permissions to read touchpad input data. Perform these steps to solve the permission issue:
Sometimes, you'll need some permissions to read touchpad input data.
1. `sudo gpasswd -a $USER input`
2. Log out / log back in
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
```
2. Check the fourth column (e.g. `input`) then run
```bash
sudo gpasswd -a $USER input
```
3. ***Important***: Log out / Log back in
### Optional: Add to Startup Applications
1. `gnome-session-properties`
2. Click `Add`
3. Enter the following:
Name | Comforable Swipe
------- | -------------------
Command | `comfortable-swipe-start`
Comment | Comfortable 3 or 4 finger swipe gestures
4. Save
Just run `comfortable-swipe autostart`
## Configurations
The configuration file is located at `~/.config/comfortable-swipe.conf`.
@ -51,7 +71,7 @@ down4 | 4-finger swipe down | super+d | show desktop
threshold | mouse pixels to activate swipe; higher = less sensitive; integers only | 20
## Uninstall
1. `bash uninstall`
Download the `uninstall` script then run `bash uninstall`
## Bug Reports
Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug.

View File

@ -3,7 +3,7 @@ DIR=$(dirname $0)
#copy config file
mkdir -p ~/.config
DCONF_PATH=$DIR/src/defaults.conf
CONF_PATH=~/.config/comfortable-swipe.conf
CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
if [ ! -f $CONF_PATH ]; then
cat $DCONF_PATH > $CONF_PATH
else
@ -23,5 +23,5 @@ else
fi
echo "Installing..."
mkdir -p ~/.local/bin
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o ~/.local/bin/comfortable-swipe || exec echo "Installation aborted"
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $HOME/.local/bin/comfortable-swipe || exec echo "Installation aborted"
echo "Successfully installed. You may now run 'comfortable-swipe start'."

View File

@ -63,6 +63,7 @@ namespace service {
void start();
void stop();
void restart();
void autostart();
void help();
}
@ -76,6 +77,7 @@ int main(int argc, char** args) {
else if (arg == "stop") service::stop();
else if (arg == "restart") service::restart();
else if (arg == "buffer") service::buffer();
else if (arg == "autostart") service::autostart();
else service::help();
} else {
service::help();
@ -168,20 +170,52 @@ struct swipe_gesture_impl : swipe_gesture {
}
};
// path services
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;
}
// get the full path of the .desktop file associated
// with the autostart feature
string autostart_filename() {
static string *filename = NULL;
if (filename == NULL) {
const char* xdg_config = getenv("XDG_CONFIG_HOME");
string config(
xdg_config == NULL
? string(getenv("HOME")) + "/.config"
: xdg_config
);
filename = new string(config
+ "/autostart/comfortable-swipe.desktop");
}
return *filename;
}
}
namespace service {
// parses output from libinput-debug-events
void buffer() {
// check first if $user
ios::sync_with_stdio(false);
cin.tie(0);
cin.tie(0); cout.tie(0);
const regex gesture_begin(util::build_gesture_begin());
const regex gesture_update(util::build_gesture_update());
const regex gesture_end(util::build_gesture_end());
string sentence;
// read config file
string conf_filename = string(getenv("HOME"))
+ "/.config/comfortable-swipe.conf";
auto config = util::read_config_file(conf_filename.data());
auto config = util::read_config_file(conf_filename().data());
// initialize gesture handler
swipe_gesture_impl swipe(
config.count("threshold") ? stoi(config["threshold"]) : 20,
@ -223,7 +257,7 @@ namespace service {
}
// starts service
void start() {
int x = system("stdbuf -oL -eL libinput-debug-events | comfortable-swipe buffer");
int x = system("stdbuf -oL -eL libinput-debug-events | $HOME/.local/bin/comfortable-swipe buffer");
}
// stops service
void stop() {
@ -249,16 +283,51 @@ namespace service {
service::stop();
service::start();
}
// toggle automatically start application on startup
void autostart() {
string path = autostart_filename();
if (ifstream(path.data()).good()) {
// file found, delete it
if (remove(path.data()) != 0)
cerr << "Error: failed to switch off autostart. "
<< "Maybe the autostart file is in use?"
<< endl;
else
cout << "Autostart switched off" << endl;
} else {
// file not found, create it
int result = system(("mkdir -p $(dirname " + path + ")").data());
ofstream fout(path.data());
if (result != 0 || !fout.good())
cerr << "Error: failed to switch on autostart. "
<< "Are you sure you have the permissions?"
<< endl;
else {
fout <<
"[Desktop Entry]\n"
"Type=Application\n"
"Exec=comfortable-swipe start\n"
"Hidden=false\n"
"NoDisplay=false\n"
"X-GNOME-Autostart-enabled=true\n"
"Name=Comfortable Swipe\n"
"Comment=3 or 4 touchpad gestures\n";
cout << "Autostart switched on" << endl;
}
}
}
// shows help
void help() {
puts("comfortable-swipe [start|stop|restart|buffer|help]");
puts("comfortable-swipe [start|stop|restart|autostart|buffer|help]");
puts("");
puts("start - starts 3/4-finger gesture service");
puts("stop - stops 3/4-finger gesture service");
puts("restart - stops then starts 3/4-finger gesture service");
puts("autostart - automatically run on startup (toggleable)");
puts("buffer - parses output of libinput-debug-events");
puts("help - shows the help dialog");
puts("");
puts("Configuration file can be found in ~/.config/comfortable-swipe.conf");
puts((("Configuration file can be found in ") + conf_filename()).data());
}
}

View File

@ -1,6 +1,6 @@
#!/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/$USER/.local/bin/comfortable-swipe 2> /dev/null
sleep 1
echo "Successfully uninstalled comfortable-swipe"
rm $HOME/.local/bin/comfortable-swipe 2> /dev/null
echo "Successfully uninstalled comfortablex-swipe"