Compare commits
8 Commits
master
...
feature-sy
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10fbe13647 | ||
|
|
8b9b960154 | ||
|
|
7900cc95e1 | ||
|
|
08e08a0f90 | ||
|
|
f797290174 | ||
|
|
3969b69e12 | ||
|
|
a84ff2ad23 | ||
|
|
2dbc2be653 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.log
|
||||||
64
README.md
64
README.md
@ -28,43 +28,39 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
1. Make sure `~/.local/bin/` is added to your PATH.
|
Comfortable swipe should already be running as a service upon installation. Some notes:
|
||||||
2. Run
|
|
||||||
|
|
||||||
```
|
|
||||||
comfortable-swipe start
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Optional: Automatically run on startup
|
|
||||||
|
|
||||||
```
|
- The program makes use of **keyboard gestures** for swiping (e.g. `ctrl+alt+Right`)
|
||||||
comfortable-swipe autostart
|
- By default, comfortable swipe uses Ubuntu workspace shortcuts (see [configurations](#configurations)).
|
||||||
```
|
|
||||||
|
|
||||||
### Permissions
|
Useful References:
|
||||||
Sometimes, you'll need some permissions to read touchpad input data.
|
|
||||||
|
|
||||||
1. Find out your permission group with `ls -l /dev/input/event*`
|
- [Xdotool keycodes](https://www.linux.org/threads/xdotool-keyboard.10528/)
|
||||||
```bash
|
- [How to turn on Workspaces?](https://askubuntu.com/questions/260510/how-do-i-turn-on-workspaces-why-do-i-only-have-one-workspace)
|
||||||
$ ls -l /dev/input/event*
|
- [How to set keyboard shortcuts in Ubuntu](https://help.ubuntu.com/stable/ubuntu-help/keyboard-shortcuts-set.html)
|
||||||
|
|
||||||
crw-rw---- 1 root input 13, 64 Oct 23 23:09 /dev/input/event0
|
### Other Commands
|
||||||
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:
|
You can run `comfortable-swipe help` to see a list of commands:
|
||||||
```bash
|
|
||||||
sudo gpasswd -a $USER input
|
|
||||||
```
|
|
||||||
> Note: Don't forget to input your `sudo` password!
|
|
||||||
|
|
||||||
3. ***Important***: Log out / Log back in
|
```
|
||||||
|
$ comfortable-swipe help
|
||||||
|
|
||||||
## Configurations
|
comfortable-swipe [start|stop|status|restart|buffer|help]
|
||||||
The configuration file is located at `~/.config/comfortable-swipe.conf`.
|
|
||||||
Make sure to run `comfortable-swipe restart` after making changes.
|
start - starts 3/4-finger gesture service
|
||||||
|
stop - stops 3/4-finger gesture service
|
||||||
|
status - shows the status of the program (service log)
|
||||||
|
restart - stops then starts 3/4-finger gesture service
|
||||||
|
buffer - parses output of libinput-debug-events
|
||||||
|
help - shows the help dialog
|
||||||
|
|
||||||
|
Configuration file can be found in /usr/local/share/comfortable-swipe.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
### Configurations
|
||||||
|
The configuration file is located at `/usr/local/share/comfortable-swipe.conf`.
|
||||||
|
Run `comfortable-swipe restart` after making changes.
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
Property | Description | Default Value | Default Behavior
|
||||||
--------- | ----------- | -------------- | -----
|
--------- | ----------- | -------------- | -----
|
||||||
@ -79,7 +75,11 @@ 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
|
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
||||||
|
|
||||||
## Uninstall
|
## Uninstall
|
||||||
Download the `uninstall` script then run `bash uninstall`
|
Clone the repository then run `bash uninstall`.
|
||||||
|
|
||||||
## Bug Reports
|
## Bug Reports
|
||||||
Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug.
|
Create an issue [here](https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new) to report a bug. Please make sure
|
||||||
|
to add the following to your issue:
|
||||||
|
|
||||||
|
1. Content of `.log` (found in the cloned folder)
|
||||||
|
2. Output of `comfortable-swipe status`
|
||||||
|
|||||||
79
install
79
install
@ -1,20 +1,37 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# prefer running as root
|
||||||
|
if [ $(id -u) != "0" ]; then
|
||||||
|
sudo bash "$0" "$@"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "
|
||||||
|
Install $(date)" >> .log
|
||||||
|
|
||||||
DIR=$(dirname $0)
|
DIR=$(dirname $0)
|
||||||
PROGRAM=/usr/local/bin/comfortable-swipe
|
PROGRAM=/usr/local/bin/comfortable-swipe
|
||||||
|
CONF_PATH=/usr/local/share/comfortable-swipe.conf
|
||||||
|
OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
||||||
|
DCONF_PATH=$DIR/src/defaults.conf
|
||||||
|
|
||||||
if [ -x "$(command -v $PROGRAM)" ]; then
|
if [ -x "$(command -v $PROGRAM)" ]; then
|
||||||
# stop any running comfortable-swipe if it exists
|
# stop any running comfortable-swipe if it exists
|
||||||
$PROGRAM stop
|
systemctl stop comfortable-swipe.service >> .log 2>> .log
|
||||||
# remove existing comfortable-swipe
|
systemctl disable comfortable-swipe.service >> .log 2>> .log
|
||||||
rm $(which comfortable-swipe)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#copy config file
|
mkdir -p $(dirname $CONF_PATH)
|
||||||
mkdir -p ~/.config
|
|
||||||
DCONF_PATH=$DIR/src/defaults.conf
|
# copy config file
|
||||||
CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf
|
|
||||||
if [ ! -f $CONF_PATH ]; then
|
if [ ! -f $CONF_PATH ]; then
|
||||||
cat $DCONF_PATH > $CONF_PATH
|
if [ ! -f $OLD_CONF_PATH ]; then
|
||||||
|
# old config file not found, create from scratch
|
||||||
|
cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
||||||
|
else
|
||||||
|
# old config file found, move to the new path
|
||||||
|
echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH"
|
||||||
|
cp -a $OLD_CONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
||||||
|
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"
|
||||||
@ -24,18 +41,50 @@ else
|
|||||||
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
|
cp -a $DCONF_PATH $(dirname $CONF_PATH) >> .log 2>> .log
|
||||||
else
|
else
|
||||||
|
echo "Installation aborted." >> .log
|
||||||
exec echo "Installation aborted."
|
exec echo "Installation aborted."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# install with g++
|
||||||
echo "Installing..."
|
echo "Installing..."
|
||||||
# mkdir -p ~/.local/bin
|
echo "
|
||||||
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM || exec echo "Installation aborted"
|
Install $(date)" >> .log
|
||||||
|
echo "Running g++" >> .log
|
||||||
|
g++ -std=c++11 -O2 $DIR/src/comfortable-swipe.cpp -lxdo -o $PROGRAM >> .log 2>> .log || exec echo "Installation aborted"
|
||||||
|
|
||||||
# toggle autostart twice to refresh any changes
|
# add as service
|
||||||
$PROGRAM autostart > /dev/null || exec echo "Installation aborted"
|
SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service"
|
||||||
$PROGRAM autostart > /dev/null || exec echo "Installation aborted"
|
|
||||||
|
|
||||||
echo "Successfully installed. You may now run 'comfortable-swipe start'."
|
echo "[Unit]
|
||||||
|
Description=Comfortable 3 or 4 finger gestures
|
||||||
|
After=display-manager.service keyboard-setup.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment=DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY
|
||||||
|
ExecStart=$PROGRAM exec
|
||||||
|
Restart=always
|
||||||
|
RestartSec=2
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=graphical.target" \
|
||||||
|
> $SERVICE_PATH
|
||||||
|
|
||||||
|
# run immediately
|
||||||
|
systemctl daemon-reload >> .log 2>> .log
|
||||||
|
systemctl enable comfortable-swipe.service >> .log 2>> .log
|
||||||
|
systemctl start comfortable-swipe.service >> .log 2>> .log
|
||||||
|
sleep 1
|
||||||
|
echo "Installation successful" >> .log
|
||||||
|
|
||||||
|
# prvide success message
|
||||||
|
echo ""
|
||||||
|
echo "Successfully installed comfortable-swipe. Try swiping and see if it works."
|
||||||
|
echo "Configuration file is located at $CONF_PATH"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "[Report bugs to https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/new]"
|
||||||
|
echo ""
|
||||||
|
|||||||
@ -66,9 +66,10 @@ namespace service {
|
|||||||
void buffer();
|
void buffer();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
void status();
|
||||||
void restart();
|
void restart();
|
||||||
void autostart();
|
|
||||||
void help();
|
void help();
|
||||||
|
void exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MAIN DRIVER FUNCTION */
|
/* MAIN DRIVER FUNCTION */
|
||||||
@ -79,9 +80,10 @@ int main(int argc, char** args) {
|
|||||||
// select based on argument
|
// select based on argument
|
||||||
if (arg == "start") service::start();
|
if (arg == "start") service::start();
|
||||||
else if (arg == "stop") service::stop();
|
else if (arg == "stop") service::stop();
|
||||||
|
else if (arg == "status") service::status();
|
||||||
else if (arg == "restart") service::restart();
|
else if (arg == "restart") service::restart();
|
||||||
else if (arg == "buffer") service::buffer();
|
else if (arg == "buffer") service::buffer();
|
||||||
else if (arg == "autostart") service::autostart();
|
else if (arg == "exec") service::exec();
|
||||||
else service::help();
|
else service::help();
|
||||||
} else {
|
} else {
|
||||||
service::help();
|
service::help();
|
||||||
@ -186,36 +188,17 @@ namespace service {
|
|||||||
// get the full path of the .conf file
|
// get the full path of the .conf file
|
||||||
string conf_filename() {
|
string conf_filename() {
|
||||||
static string *filename = NULL;
|
static string *filename = NULL;
|
||||||
if (filename == NULL) {
|
if (filename == NULL)
|
||||||
const char* xdg_config = getenv("XDG_CONFIG_HOME");
|
filename = new string("/usr/local/share/comfortable-swipe.conf");
|
||||||
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;
|
return *filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace service {
|
namespace service {
|
||||||
|
void exec() {
|
||||||
|
sleep(1);
|
||||||
|
exit(system("/usr/bin/stdbuf -oL -eL /usr/bin/libinput-debug-events 2>&1 | " PROGRAM " buffer"));
|
||||||
|
}
|
||||||
// parses output from libinput-debug-events
|
// parses output from libinput-debug-events
|
||||||
void buffer() {
|
void buffer() {
|
||||||
// check first if $user
|
// check first if $user
|
||||||
@ -263,78 +246,37 @@ namespace service {
|
|||||||
swipe.udx = matches[6];
|
swipe.udx = matches[6];
|
||||||
swipe.udy = matches[7];
|
swipe.udy = matches[7];
|
||||||
swipe.on_update();
|
swipe.on_update();
|
||||||
|
} else if (sentence.find("Segmentation fault") != string::npos) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
} else if (sentence.find("Error") != string::npos) {
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// starts service
|
// starts service
|
||||||
void start() {
|
void start() {
|
||||||
int x = system("stdbuf -oL -eL libinput-debug-events | " PROGRAM " buffer");
|
exit(system("systemctl start comfortable-swipe.service"));
|
||||||
}
|
}
|
||||||
// stops service
|
// stops service
|
||||||
void stop() {
|
void stop() {
|
||||||
// kill all comfortable-swipe, except self
|
exit(system("systemctl stop comfortable-swipe.service"));
|
||||||
char* buffer = new char[20];
|
}
|
||||||
FILE* pipe = popen("pgrep -f comfortable-swipe", "r");
|
// shows the status of the program
|
||||||
if (!pipe) throw std::runtime_error("stop command failed");
|
void status() {
|
||||||
string kill = "kill";
|
exit(system("systemctl status comfortable-swipe.service"));
|
||||||
while (!feof(pipe)) {
|
|
||||||
if (fgets(buffer, 20, pipe) != NULL) {
|
|
||||||
int pid = atoi(buffer);
|
|
||||||
if (pid != getpid()) {
|
|
||||||
kill += " " + to_string(pid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int result = system(kill.data());
|
|
||||||
delete[] buffer;
|
|
||||||
pclose(pipe);
|
|
||||||
}
|
}
|
||||||
// stops then starts service
|
// stops then starts service
|
||||||
void restart() {
|
void restart() {
|
||||||
service::stop();
|
exit(system("systemctl restart comfortable-swipe.service"));
|
||||||
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=bash -c \"" 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";
|
|
||||||
cout << "Autostart switched on" << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// shows help
|
// shows help
|
||||||
void help() {
|
void help() {
|
||||||
puts("comfortable-swipe [start|stop|restart|autostart|buffer|help]");
|
puts("comfortable-swipe [start|stop|status|restart|buffer|help]");
|
||||||
puts("");
|
puts("");
|
||||||
puts("start - starts 3/4-finger gesture service");
|
puts("start - starts 3/4-finger gesture service");
|
||||||
puts("stop - stops 3/4-finger gesture service");
|
puts("stop - stops 3/4-finger gesture service");
|
||||||
|
puts("status - shows the status of the program (service log)");
|
||||||
puts("restart - stops then starts 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("buffer - parses output of libinput-debug-events");
|
||||||
puts("help - shows the help dialog");
|
puts("help - shows the help dialog");
|
||||||
puts("");
|
puts("");
|
||||||
|
|||||||
27
uninstall
27
uninstall
@ -1,7 +1,26 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
if [ $(id -u) != "0" ]; then
|
||||||
|
sudo bash "$0" "$@"
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
echo "Uninstalling..."
|
echo "Uninstalling..."
|
||||||
rm ${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop 2> /dev/null
|
echo "
|
||||||
comfortable-swipe stop 2> /dev/null
|
Uninstall $(date)" >> .log
|
||||||
rm $HOME/.local/bin/comfortable-swipe 2> /dev/null # compat
|
|
||||||
rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
# stop service
|
||||||
|
systemctl stop comfortable-swipe.service >> .log 2>> .log
|
||||||
|
systemctl disable comfortable-swipe.service >> .log 2>> .log
|
||||||
|
systemctl daemon-reload
|
||||||
|
|
||||||
|
# remove service
|
||||||
|
SERVICE_PATH="/lib/systemd/system/comfortable-swipe.service"
|
||||||
|
rm $SERVICE_PATH >> .log 2>> .log
|
||||||
|
|
||||||
|
# remove old program
|
||||||
|
OLD_PROGRAM=$HOME/.local/bin/comfortable-swipe
|
||||||
|
rm $OLD_PROGRAM >> .log 2>> .log # compat
|
||||||
|
|
||||||
|
# remove program
|
||||||
|
PROGRAM=/usr/local/bin/comfortable-swipe
|
||||||
|
rm $PROGRAM >> .log 2>> .log
|
||||||
echo "Successfully uninstalled comfortable-swipe"
|
echo "Successfully uninstalled comfortable-swipe"
|
||||||
Loading…
Reference in New Issue
Block a user