Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59dfcbfc39 | ||
|
|
3a9d6c26ed | ||
|
|
94858c63fe | ||
|
|
68fce3819f | ||
|
|
169f8dc788 | ||
|
|
435e46373f | ||
|
|
1e900945af | ||
|
|
484e99ce83 | ||
|
|
0a8ec16256 | ||
|
|
07acbb4d1d | ||
|
|
eb69b2fce4 | ||
|
|
d03e6cc081 | ||
|
|
9143c715c6 | ||
|
|
c0b69484a6 | ||
|
|
8f6e231a5e | ||
|
|
dda91b7178 | ||
|
|
4852993663 | ||
|
|
810a20f1ed |
No files matched your search
-31
@@ -1,31 +0,0 @@
|
|||||||
dist: xenial
|
|
||||||
sudo: required
|
|
||||||
language: c++
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- env: {MATRIX_EVAL: '"CC=gcc-7 && CXX=g++-7 && alias g++=g++-7"'}
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
update: true
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- libxdo-dev
|
|
||||||
- libinput-tools
|
|
||||||
- g++-7
|
|
||||||
- env: {MATRIX_EVAL: '"CC=gcc-8 && CXX=g++-8 && alias g++=g+++-8"'}
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
update: true
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
packages:
|
|
||||||
- libxdo-dev
|
|
||||||
- libinput-tools
|
|
||||||
- g++-8
|
|
||||||
before_install:
|
|
||||||
- eval "${MATRIX_EVAL}"
|
|
||||||
- g++ --version
|
|
||||||
install: bash install
|
|
||||||
script: bash tests/run_tests
|
|
||||||
after_script: bash uninstall
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
v1.1.0
|
||||||
|
* Added mouse hold gestures
|
||||||
|
* Added `hold3` configuration
|
||||||
|
* Added `hold4` configuration
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
# Comfortable Swipe (Ubuntu)
|
# Comfortable Swipe (Ubuntu)
|
||||||
|
[](https://github.com/Hikari9/comfortable-swipe/releases)
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
|
||||||
|
> **_New in Version 1.1.0!_** Added mouse move gestures (eg. `hold3 = button1`)
|
||||||
|
|
||||||
Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures for Ubuntu 14.04 LTS and beyond. May work for other Linux distros that support `libinput`.
|
Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures for Ubuntu 14.04 LTS and beyond. May work for other Linux distros that support `libinput`.
|
||||||
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Install git, libinput, and g++
|
1. Install git, libinput, and g++
|
||||||
@@ -14,8 +18,8 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
2. Clone this repository
|
2. Clone this repository
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/Hikari9/comfortable-swipe-ubuntu.git
|
git clone https://github.com/Hikari9/comfortable-swipe.git --depth 1
|
||||||
cd comfortable-swipe-ubuntu
|
cd comfortable-swipe
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Install
|
3. Install
|
||||||
@@ -24,7 +28,7 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
bash install
|
bash install
|
||||||
```
|
```
|
||||||
|
|
||||||
4. You may delete the downloaded `comfortable-swipe-ubuntu` folder after installation.
|
4. You may delete the downloaded `comfortable-swipe` folder after installation.
|
||||||
|
|
||||||
## How to Run
|
## How to Run
|
||||||
|
|
||||||
@@ -46,28 +50,35 @@ Comfortable, seamless, and fast 3-finger (and 4-finger) touchpad swipe gestures
|
|||||||
comfortable-swipe status
|
comfortable-swipe status
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configurations
|
## Swipe Configurations
|
||||||
Comfortable swipe makes use of keyboard shortcuts for configurations. Edit by running
|
|
||||||
```
|
|
||||||
nano $(comfortable-swipe config)
|
|
||||||
```
|
|
||||||
|
|
||||||
Make sure to run after making changes:
|
Comfortable swipe makes use of keyboard shortcuts for configurations.
|
||||||
```
|
|
||||||
comfortable-swipe restart
|
|
||||||
```
|
|
||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
1. Edit by running
|
||||||
--------- | ----------- | -------------- | -----
|
```
|
||||||
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point (Note: Sky is the limit! Can be as large as 1000.0) | 0.0
|
gedit $(comfortable-swipe config)
|
||||||
left3 | 3-finger swipe left | ctrl+shift+Right | switch to right workspace
|
```
|
||||||
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
|
||||||
right3 | 3-finger swipe right | ctrl+shift+Left | switch to left workspace
|
1. List of possible configurations:
|
||||||
right4 | 4-finger swipe right | ctrl+alt+shift+Left | move window to left workspace
|
|
||||||
up3 | 3-finger swipe up | ctrl+shift+Down | switch to bottom workspace
|
Property | Description | Default Value | Default Behavior
|
||||||
up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace
|
--------- | :-----------: | -------------- | -----
|
||||||
down3 | 3-finger swipe down | ctrl+shift+Down | switch to above workspace
|
left3 | 3-finger swipe left | ctrl+alt+Right | switch to right workspace
|
||||||
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
||||||
|
right3 | 3-finger swipe right | ctrl+alt+Left | switch to left workspace
|
||||||
|
right4 | 4-finger swipe right | ctrl+alt+shift+Left | move window to left workspace
|
||||||
|
up3 | 3-finger swipe up | ctrl+alt+Down | switch to bottom workspace
|
||||||
|
up4 | 4-finger swipe up | ctrl+alt+shift+Down | move window to bottom workspace
|
||||||
|
down3 | 3-finger swipe down | ctrl+alt+Down | switch to above workspace
|
||||||
|
down4 | 4-finger swipe down | ctrl+alt+shift+Up | move window to above workpace
|
||||||
|
threshold | mouse pixels to activate swipe | 0.0 | tweak this if you're having troubles with touchpad sensitivity (higher = less sensitive, values can be as large as 1000.0)
|
||||||
|
hold3 | holds a mouse button when 3 fingers are down | (none) | See [Mouse Gestures](#mouse-configurations)
|
||||||
|
hold4 | holds a mouse button when 4 fingers are down | (none) | See [Mouse Gestures](#mouse-configurations)
|
||||||
|
|
||||||
|
1. After making changes, make sure to restart the program:
|
||||||
|
```
|
||||||
|
comfortable-swipe restart
|
||||||
|
```
|
||||||
|
|
||||||
Taken from `man xdotool`:
|
Taken from `man xdotool`:
|
||||||
|
|
||||||
@@ -85,6 +96,54 @@ Taken from `man xdotool`:
|
|||||||
|
|
||||||
Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use.
|
Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a complete list of keycodes you can use.
|
||||||
|
|
||||||
|
## Mouse Gestures
|
||||||
|
|
||||||
|
> **Note**: Setting hold3 or hold4 will ignore its corresponding up/right/down/left command.
|
||||||
|
|
||||||
|
We have included simple mouse gestures on swipe by setting `hold3` and `hold4`.
|
||||||
|
|
||||||
|
**Possible values**:
|
||||||
|
* move - just move the mouse
|
||||||
|
* button1 - left click
|
||||||
|
* button2 - middle click
|
||||||
|
* button3 - right click
|
||||||
|
* button4 - wheel up (experimental)
|
||||||
|
* button5 - wheel down (experimental)
|
||||||
|
* scroll - natural scrolling (experimental)
|
||||||
|
* scroll_reverse - reverse scrolling (experimental)
|
||||||
|
|
||||||
|
## Example Configuration
|
||||||
|
|
||||||
|
Edit with `gedit $(comfortable-swipe config)`:
|
||||||
|
|
||||||
|
```conf
|
||||||
|
# File: comfortable-swipe.conf
|
||||||
|
|
||||||
|
# four-finger drag
|
||||||
|
hold4 = button1
|
||||||
|
|
||||||
|
# show desktop
|
||||||
|
down3 = super+d
|
||||||
|
|
||||||
|
# show workspaces
|
||||||
|
up3 = super+s
|
||||||
|
|
||||||
|
# switch workspace
|
||||||
|
left3 = ctrl+alt+Right
|
||||||
|
right3 = ctrl+alt+Left
|
||||||
|
|
||||||
|
# disabled because of hold4
|
||||||
|
left4 = ctrl+alt+shift+Right
|
||||||
|
right4 = ctrl+alt+shift+Left
|
||||||
|
|
||||||
|
# three-finger middle click (experimental)
|
||||||
|
# hold3 = button2
|
||||||
|
|
||||||
|
# three-finger scroll (experimental)
|
||||||
|
# hold3 = scroll
|
||||||
|
# hold3 = scroll_reverse
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Debugging
|
## Debugging
|
||||||
|
|
||||||
@@ -126,4 +185,18 @@ Download the `uninstall` script 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.
|
Search in [Issues](https://github.com/Hikari9/comfortable-swipe/issues?utf8=%E2%9C%93&q=is%3Aissue) if the problem has already been solved.
|
||||||
|
|
||||||
|
Otherwise, [create a new issue](https://github.com/Hikari9/comfortable-swipe/issues/new) to report your bug.
|
||||||
|
|
||||||
|
Please include the output of the following:
|
||||||
|
|
||||||
|
1. `lsb_release -a`
|
||||||
|
2. `g++ --version`
|
||||||
|
3. `ls -l /dev/input/event*`
|
||||||
|
3. `xinput list | grep touchpad -i`
|
||||||
|
4. `lsmod | grep hid`
|
||||||
|
5. `comfortable-swipe status`
|
||||||
|
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)`
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
g++ $(dirname $0)/comfortable-swipe.cpp -std=c++11 -O2 -lxdo -Wno-unused-result -o $1
|
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__index_hpp__
|
/**
|
||||||
#define __COMFORTABLE_SWIPE__index_hpp__
|
* Add header files will be imported here.
|
||||||
|
* You can import this as a shorthand:
|
||||||
|
*
|
||||||
|
* #include "../all_headers.hpp"
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__all_headers_hpp__
|
||||||
|
#define __COMFORTABLE_SWIPE__all_headers_hpp__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
@@ -28,24 +35,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
#define __COMFORTABLE_SWIPE__CONFIG__ "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
|
||||||
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */
|
#endif /* __COMFORTABLE_SWIPE__CONFIG__ */
|
||||||
|
|
||||||
|
#ifndef COMFORTABLE_SWIPE_VERSION
|
||||||
|
#warning COMFORTABLE_SWIPE_VERSION is not defined
|
||||||
|
#define COMFORTABLE_SWIPE_VERSION "v(UNKNOWN)"
|
||||||
|
#endif /* COMFORTABLE_SWIPE_VERSION */
|
||||||
|
|
||||||
#include <map> // std::map
|
#include <map> // std::map
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure to include your header files here so that they can be imported by other modules.
|
|
||||||
*/
|
|
||||||
#include "gesture/xdo_gesture.h"
|
|
||||||
#include "gesture/swipe_gesture.h"
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
namespace comfortable_swipe
|
namespace comfortable_swipe
|
||||||
{
|
{
|
||||||
|
// driver method
|
||||||
|
int driver();
|
||||||
|
// this is found in the util/ folder
|
||||||
namespace util
|
namespace util
|
||||||
{
|
{
|
||||||
const char* autostart_filename();
|
const char* autostart_filename();
|
||||||
constexpr const char* conf_filename();
|
constexpr const char* conf_filename();
|
||||||
std::map<std::string, std::string> read_config_file(const char*);
|
std::map<std::string, std::string> read_config_file(const char*);
|
||||||
}
|
}
|
||||||
|
// this is found in the service/ folder
|
||||||
namespace service
|
namespace service
|
||||||
{
|
{
|
||||||
void autostart();
|
void autostart();
|
||||||
@@ -61,4 +72,10 @@ extern "C"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__index_hpp__ */
|
// add headers for classes here so it can be imported during include
|
||||||
|
#include "gesture/xdo_gesture.h"
|
||||||
|
#include "gesture/swipe_gesture.h"
|
||||||
|
#include "gesture/keyboard_swipe_gesture.h"
|
||||||
|
#include "gesture/mouse_hold_gesture.h"
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__all_headers_hpp__ */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
#ifndef __COMFORTABLE_SWIPE__driver__
|
||||||
#define __COMFORTABLE_SWIPE__service_buffer__
|
#define __COMFORTABLE_SWIPE__driver__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
@@ -21,25 +21,41 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
#include <cstdio> // fgets_unlocked, stdin
|
#include <cstdio> // fgets_unlocked, stdin
|
||||||
#include <iostream> // std::ios, std::cout, std::cin
|
#include <iostream> // std::ios, std::cout, std::cin
|
||||||
#include "../index.hpp"
|
#include "all_headers.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
* The main driver program.
|
||||||
*/
|
*/
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe
|
||||||
{
|
{
|
||||||
void buffer()
|
int driver()
|
||||||
{
|
{
|
||||||
|
// unsync for faster IO
|
||||||
std::ios::sync_with_stdio(false);
|
std::ios::sync_with_stdio(false);
|
||||||
std::cin.tie(0);
|
std::cin.tie(0);
|
||||||
std::cout.tie(0);
|
std::cout.tie(0);
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
|
||||||
// read config file
|
// read config file
|
||||||
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()
|
||||||
|
);
|
||||||
|
|
||||||
// initialize swipe gesture handler
|
// initialize mouse hold gesture handler
|
||||||
comfortable_swipe::gesture::swipe_gesture swipe_gesture_handler
|
// for now, this supports 3-finger and 4-finger hold
|
||||||
|
// Examples:
|
||||||
|
// hold3=move move mouse on 3 fingers
|
||||||
|
// hold3=button1 hold button 1 on 3 fingers
|
||||||
|
// hold4=button3 hold button 3 (right click) on 3 fingers
|
||||||
|
// hold3=ignore <do nothing>
|
||||||
|
comfortable_swipe::gesture::mouse_hold_gesture mouse_hold
|
||||||
|
(
|
||||||
|
config["hold3"].c_str(),
|
||||||
|
config["hold4"].c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
// initialize keyboard swipe gesture handler
|
||||||
|
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe
|
||||||
(
|
(
|
||||||
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
||||||
config["left3"].c_str(),
|
config["left3"].c_str(),
|
||||||
@@ -58,10 +74,19 @@ namespace comfortable_swipe::service
|
|||||||
// start reading lines from input one by one
|
// start reading lines from input one by one
|
||||||
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
||||||
{
|
{
|
||||||
// attempt to parse swipe gestures
|
// prioritize mouse hold gesture first
|
||||||
swipe_gesture_handler.parse_line(line.data());
|
mouse_hold.parse_line(line.data());
|
||||||
|
|
||||||
|
// if mouse hold fails, try keyboard hold
|
||||||
|
if (!mouse_hold.is_mousedown())
|
||||||
|
{
|
||||||
|
// attempt to parse keyboard gestures
|
||||||
|
keyboard_swipe.parse_line(line.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
#endif /* __COMFORTABLE_SWIPE__driver__ */
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include "keyboard_swipe_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
|
||||||
|
/* STATICS DEFINITIONS */
|
||||||
|
const int keyboard_swipe_gesture::MSK_THREE_FINGERS = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
|
const int keyboard_swipe_gesture::MSK_NEGATIVE = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_POSITIVE = 2;
|
||||||
|
const int keyboard_swipe_gesture::MSK_HORIZONTAL = 0;
|
||||||
|
const int keyboard_swipe_gesture::MSK_VERTICAL = 4;
|
||||||
|
const int keyboard_swipe_gesture::FRESH = -1;
|
||||||
|
const char * const keyboard_swipe_gesture::command_map[8] = {
|
||||||
|
"left3",
|
||||||
|
"left4",
|
||||||
|
"right3",
|
||||||
|
"right4",
|
||||||
|
"up3",
|
||||||
|
"up4",
|
||||||
|
"down3",
|
||||||
|
"down4"
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new keyboard-based swipe gesture, given configurations
|
||||||
|
* for certain swipe events. Here, we construct our definition based on
|
||||||
|
* the four directions (left, up, right, down) for 3-finger and 4-finger
|
||||||
|
* swipes. Note that the direction is based on the Australian natural
|
||||||
|
* scrolling direction (ie. left3 is natural movement of 3 fingers left).
|
||||||
|
*/
|
||||||
|
keyboard_swipe_gesture::keyboard_swipe_gesture
|
||||||
|
(
|
||||||
|
const float threshold,
|
||||||
|
const char* left3 /* 000 */,
|
||||||
|
const char* left4 /* 001 */,
|
||||||
|
const char* right3 /* 010 */,
|
||||||
|
const char* right4 /* 011 */,
|
||||||
|
const char* up3 /* 100 */,
|
||||||
|
const char* up4 /* 101 */,
|
||||||
|
const char* down3 /* 110 */,
|
||||||
|
const char* down4 /* 111 */
|
||||||
|
):
|
||||||
|
// construct superclass
|
||||||
|
comfortable_swipe::gesture::swipe_gesture(),
|
||||||
|
// compute square of threshold because we will use squared distances
|
||||||
|
threshold_squared(threshold*threshold),
|
||||||
|
// register our commands
|
||||||
|
commands(new const char*[8]{
|
||||||
|
left3, left4, right3, right4, up3, up4, down3, down4
|
||||||
|
})
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this keyboard swipe gesture.
|
||||||
|
*/
|
||||||
|
keyboard_swipe_gesture::~keyboard_swipe_gesture()
|
||||||
|
{
|
||||||
|
delete[] commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::begin()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::begin();
|
||||||
|
|
||||||
|
// assign previous gesture to FRESH
|
||||||
|
this->previous_gesture = keyboard_swipe_gesture::FRESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::update()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::update();
|
||||||
|
|
||||||
|
// scale threshold to 1/10 when gesture is not fresh
|
||||||
|
float scale =
|
||||||
|
this->previous_gesture == keyboard_swipe_gesture::FRESH
|
||||||
|
? 1.00f
|
||||||
|
: 0.01f; // square root of 1/10
|
||||||
|
|
||||||
|
// we are working with floating points which are not exact
|
||||||
|
// make sure we compare with a very small value (epsilon)
|
||||||
|
static const float EPSILON = 1e-6f;
|
||||||
|
const float distance_squared = this->x * this->x + this->y * this->y;
|
||||||
|
const float beyond_threshold = this->threshold_squared * scale;
|
||||||
|
|
||||||
|
// apply if strictly beyond threshold
|
||||||
|
if (distance_squared > beyond_threshold + EPSILON)
|
||||||
|
{
|
||||||
|
// we parse our mask based on the values obtained from the regex
|
||||||
|
int mask = 0;
|
||||||
|
|
||||||
|
if (this->fingers == 3)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_THREE_FINGERS;
|
||||||
|
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_FOUR_FINGERS;
|
||||||
|
|
||||||
|
const float absx = x >= 0 ? x : -x;
|
||||||
|
const float absy = y >= 0 ? y : -y;
|
||||||
|
|
||||||
|
if (absx > absy)
|
||||||
|
{
|
||||||
|
// gesture is horizontal
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_HORIZONTAL;
|
||||||
|
if (x < 0)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
else /* std::abs(x) <= std::abs(y) */
|
||||||
|
{
|
||||||
|
// gesture is vertical
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_VERTICAL;
|
||||||
|
if (y < 0)
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_NEGATIVE;
|
||||||
|
else
|
||||||
|
mask |= keyboard_swipe_gesture::MSK_POSITIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if (this->previous_gesture == keyboard_swipe_gesture::FRESH
|
||||||
|
|| this->previous_gesture == (mask ^ keyboard_swipe_gesture::MSK_POSITIVE))
|
||||||
|
{
|
||||||
|
this->do_keyboard_gesture(mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the update given a mask.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::do_keyboard_gesture(int mask)
|
||||||
|
{
|
||||||
|
// perform our keyboard command with xdo_send_keysequence
|
||||||
|
const char * command = keyboard_swipe_gesture::commands[mask];
|
||||||
|
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, command, 0);
|
||||||
|
|
||||||
|
// reset our location variables
|
||||||
|
this->x = this->y = 0;
|
||||||
|
this->previous_gesture = mask;
|
||||||
|
|
||||||
|
// log our command name in stdout
|
||||||
|
const char * command_name = keyboard_swipe_gesture::command_map[mask];
|
||||||
|
std::cout << "SWIPE " << command_name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void keyboard_swipe_gesture::end()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture__ */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
#ifndef __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
|
||||||
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
#define __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xdo_gesture.h"
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -27,11 +27,11 @@ extern "C" {
|
|||||||
|
|
||||||
namespace comfortable_swipe::gesture
|
namespace comfortable_swipe::gesture
|
||||||
{
|
{
|
||||||
class swipe_gesture : protected xdo_gesture
|
class keyboard_swipe_gesture : public swipe_gesture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructor
|
// constructor
|
||||||
swipe_gesture(
|
keyboard_swipe_gesture(
|
||||||
const float threshold,
|
const float threshold,
|
||||||
const char* left3 /* 000 */,
|
const char* left3 /* 000 */,
|
||||||
const char* left4 /* 001 */,
|
const char* left4 /* 001 */,
|
||||||
@@ -43,43 +43,37 @@ namespace comfortable_swipe::gesture
|
|||||||
const char* down4 /* 111 */
|
const char* down4 /* 111 */
|
||||||
);
|
);
|
||||||
|
|
||||||
~swipe_gesture();
|
// destructor
|
||||||
|
virtual ~keyboard_swipe_gesture();
|
||||||
|
|
||||||
// fields for xdo
|
// hooks that we override
|
||||||
int fingers;
|
virtual void begin() override;
|
||||||
float dx, dy, udx, udy;
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
|
||||||
void begin() override;
|
// override this when keyboard gesture is to be performed
|
||||||
void update() override;
|
virtual void do_keyboard_gesture(int mask);
|
||||||
void end() override;
|
|
||||||
bool parse_line(const char *) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// location of mouse
|
// stores square of threshold so we can compute faster
|
||||||
int screen_num, ix, iy;
|
float threshold_squared;
|
||||||
|
|
||||||
// current location
|
// stores previous gesture so we don't repeat action
|
||||||
float x, y, threshold_squared;
|
|
||||||
int previous_gesture;
|
int previous_gesture;
|
||||||
|
|
||||||
|
// stores all command strings for xdo to execute
|
||||||
const char ** commands;
|
const char ** commands;
|
||||||
|
|
||||||
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
|
||||||
bool flag_swiping;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// static constants
|
// static enums we will use for gesture matching
|
||||||
|
static const int FRESH;
|
||||||
static const int MSK_THREE_FINGERS;
|
static const int MSK_THREE_FINGERS;
|
||||||
static const int MSK_FOUR_FINGERS;
|
static const int MSK_FOUR_FINGERS;
|
||||||
static const int MSK_NEGATIVE;
|
static const int MSK_NEGATIVE;
|
||||||
static const int MSK_POSITIVE;
|
static const int MSK_POSITIVE;
|
||||||
static const int MSK_HORIZONTAL;
|
static const int MSK_HORIZONTAL;
|
||||||
static const int MSK_VERTICAL;
|
static const int MSK_VERTICAL;
|
||||||
static const int FRESH;
|
|
||||||
static const char * const command_map[8];
|
static const char * const command_map[8];
|
||||||
// regex patterns
|
|
||||||
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
|
||||||
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
|
||||||
static const char* GESTURE_END_REGEX_PATTERN;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,4 +81,4 @@ namespace comfortable_swipe::gesture
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */
|
#endif /* __COMFORTABLE_SWIPE__gesture_keyboard_swipe_gesture_h__ */
|
||||||
@@ -0,0 +1,222 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <cstdio> // std::sscanf
|
||||||
|
#include <cstring> // strncmp
|
||||||
|
#include "mouse_hold_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
enum {
|
||||||
|
MOUSE_NONE = -1,
|
||||||
|
MOUSE_MOVE = 0,
|
||||||
|
MOUSE_LEFT_CLICK = 1,
|
||||||
|
MOUSE_MIDDLE_CLICK = 2,
|
||||||
|
MOUSE_RIGHT_CLICK = 3,
|
||||||
|
MOUSE_WHEEL_UP = 4,
|
||||||
|
MOUSE_WHEEL_DOWN = 5,
|
||||||
|
MOUSE_SCROLL = 6,
|
||||||
|
MOUSE_SCROLL_REVERSE = 7
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
|
||||||
|
*/
|
||||||
|
mouse_hold_gesture::mouse_hold_gesture
|
||||||
|
(
|
||||||
|
const char* hold3,
|
||||||
|
const char* hold4
|
||||||
|
):
|
||||||
|
comfortable_swipe::gesture::swipe_gesture(),
|
||||||
|
button(MOUSE_NONE),
|
||||||
|
hold3(hold3),
|
||||||
|
hold4(hold4),
|
||||||
|
flag_mousedown(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
mouse_hold_gesture::~mouse_hold_gesture()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run mousedown command on hold input.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::do_mousedown(const char * mouseinput)
|
||||||
|
{
|
||||||
|
const int button = this->button = this->parse_mouse_button(mouseinput);
|
||||||
|
if (button != MOUSE_NONE)
|
||||||
|
{
|
||||||
|
// eg. MOUSE DOWN hold3 mouse1
|
||||||
|
std::printf("MOUSE DOWN hold%d %s\n", this->fingers, mouseinput);
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK)
|
||||||
|
{
|
||||||
|
// send mouse down on associated button
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
this->flag_mousedown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run mouseup command on hold output.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::do_mouseup(const char * mouseinput)
|
||||||
|
{
|
||||||
|
const int button = this->button = this->parse_mouse_button(mouseinput);
|
||||||
|
if (button != MOUSE_NONE)
|
||||||
|
{
|
||||||
|
std::printf("MOUSE UP hold%d %s\n", this->fingers, mouseinput);
|
||||||
|
if (MOUSE_LEFT_CLICK <= button && button <= MOUSE_RIGHT_CLICK)
|
||||||
|
{
|
||||||
|
// send mouse up on associated button
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, button);
|
||||||
|
}
|
||||||
|
this->flag_mousedown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to parse mouse number from input.
|
||||||
|
* Returns -1 on failure.
|
||||||
|
*/
|
||||||
|
int mouse_hold_gesture::parse_mouse_button(const char * input) const
|
||||||
|
{
|
||||||
|
// just move without holding button down
|
||||||
|
if (std::strcmp(input, "move") == 0)
|
||||||
|
return MOUSE_MOVE;
|
||||||
|
|
||||||
|
if (std::strcmp(input, "scroll") == 0)
|
||||||
|
return MOUSE_SCROLL;
|
||||||
|
|
||||||
|
if (std::strcmp(input, "scroll_reverse") == 0)
|
||||||
|
return MOUSE_SCROLL_REVERSE;
|
||||||
|
|
||||||
|
// get button number
|
||||||
|
int button;
|
||||||
|
if (std::sscanf(input, "button%d", &button) == 1)
|
||||||
|
{
|
||||||
|
if (1 <= button && button <= 6)
|
||||||
|
{
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MOUSE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::begin()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::begin();
|
||||||
|
// dispatch mouse down event
|
||||||
|
if (this->fingers == 3)
|
||||||
|
{
|
||||||
|
this->do_mousedown(this->hold3);
|
||||||
|
}
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
{
|
||||||
|
this->do_mousedown(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::update()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::update();
|
||||||
|
if (this->is_mousedown())
|
||||||
|
{
|
||||||
|
if (0 <= this->button && this->button <= 3)
|
||||||
|
{
|
||||||
|
// drag mouse with pointer during update
|
||||||
|
xdo_move_mouse_relative(
|
||||||
|
this->xdo,
|
||||||
|
this->udx,
|
||||||
|
this->udy
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (this->button == MOUSE_SCROLL || this->button == MOUSE_SCROLL_REVERSE)
|
||||||
|
{
|
||||||
|
// perform naive scroll depending on vertical direction
|
||||||
|
int wheel = MOUSE_WHEEL_DOWN;
|
||||||
|
if ((this->udy > 0) == (this->button == MOUSE_SCROLL))
|
||||||
|
wheel = MOUSE_WHEEL_UP;
|
||||||
|
|
||||||
|
// click wheel on update (note: this is not precise)
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, wheel);
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, wheel);
|
||||||
|
}
|
||||||
|
else if (this->button == MOUSE_WHEEL_UP || this->button == MOUSE_WHEEL_DOWN)
|
||||||
|
{
|
||||||
|
// click wheel button on 4 or 5
|
||||||
|
xdo_mouse_down(this->xdo, CURRENTWINDOW, this->button);
|
||||||
|
xdo_mouse_up(this->xdo, CURRENTWINDOW, this->button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_hold_gesture::end()
|
||||||
|
{
|
||||||
|
if (this->is_mousedown())
|
||||||
|
{
|
||||||
|
if (this->fingers == 3)
|
||||||
|
{
|
||||||
|
this->do_mouseup(this->hold3);
|
||||||
|
}
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
{
|
||||||
|
this->do_mouseup(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to check if mouse is current held.
|
||||||
|
*/
|
||||||
|
bool mouse_hold_gesture::is_mousedown() const
|
||||||
|
{
|
||||||
|
return this->flag_mousedown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture__ */
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class mouse_hold_gesture : public swipe_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
mouse_hold_gesture(
|
||||||
|
const char* hold3, // 3 finger mouse down
|
||||||
|
const char* hold4 // 4 finger mouse down
|
||||||
|
);
|
||||||
|
|
||||||
|
// the button being clicked
|
||||||
|
int button;
|
||||||
|
|
||||||
|
virtual ~mouse_hold_gesture();
|
||||||
|
|
||||||
|
// override begin and end for mousedown
|
||||||
|
virtual void begin() override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
|
||||||
|
// provide our own mouse functions
|
||||||
|
virtual void do_mousedown(const char*);
|
||||||
|
virtual void do_mouseup(const char*);
|
||||||
|
virtual bool is_mousedown() const;
|
||||||
|
|
||||||
|
// utility method to parse mouse input given config characters
|
||||||
|
virtual int parse_mouse_button(const char*) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// command holders
|
||||||
|
const char * hold3;
|
||||||
|
const char * hold4;
|
||||||
|
|
||||||
|
// flag we can use to check if mouse is down
|
||||||
|
bool flag_mousedown;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_hold_gesture_h__ */
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <string> // std::stoi, std::stof
|
||||||
|
#include <regex> // std::regex, std::regex_match, std::cmatch
|
||||||
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a new fresh swipe gesture container.
|
||||||
|
*/
|
||||||
|
swipe_gesture::swipe_gesture
|
||||||
|
():
|
||||||
|
// construct our superclass
|
||||||
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
|
flag_swiping(false)
|
||||||
|
{
|
||||||
|
// improve responsiveness of first gesture by pre-empting xdotool
|
||||||
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy,
|
||||||
|
&this->screen_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this swipe gesture.
|
||||||
|
*/
|
||||||
|
swipe_gesture::~swipe_gesture()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void swipe_gesture::begin()
|
||||||
|
{
|
||||||
|
// save current screen location for gestured mouse movement
|
||||||
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy,
|
||||||
|
&this->screen_num);
|
||||||
|
this->x = 0;
|
||||||
|
this->y = 0;
|
||||||
|
this->ux = 0;
|
||||||
|
this->uy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void swipe_gesture::update()
|
||||||
|
{
|
||||||
|
this->x += this->dx;
|
||||||
|
this->y += this->dy;
|
||||||
|
this->ux += this->udx;
|
||||||
|
this->uy += this->udy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture (you can override this).
|
||||||
|
*/
|
||||||
|
void swipe_gesture::end()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches begin/update/end depending on the regex pattern provided by this class.
|
||||||
|
*
|
||||||
|
* @param line the line from libinput debug-events to parse
|
||||||
|
* @return true if begin/update/end was dispatched
|
||||||
|
*/
|
||||||
|
bool swipe_gesture::parse_line(const char * line)
|
||||||
|
{
|
||||||
|
|
||||||
|
// prepare regex matchers statically (will only load at most once)
|
||||||
|
static const std::regex
|
||||||
|
gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN),
|
||||||
|
gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN),
|
||||||
|
gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
|
|
||||||
|
// prepare holder for regex matches
|
||||||
|
static std::cmatch matches;
|
||||||
|
|
||||||
|
if (this->flag_swiping)
|
||||||
|
{
|
||||||
|
// currently swiping
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_update) != 0)
|
||||||
|
{
|
||||||
|
// assign necessary variables for swipe update
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->dx = std::stof(matches[2]);
|
||||||
|
this->dy = std::stof(matches[3]);
|
||||||
|
this->udx = std::stof(matches[4]);
|
||||||
|
this->udy = std::stof(matches[5]);
|
||||||
|
// dispatch update
|
||||||
|
this->update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (std::regex_match(line, matches, gesture_swipe_end) != 0)
|
||||||
|
{
|
||||||
|
// assign necessary variables for swipe end
|
||||||
|
this->flag_swiping = false;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
// dispatch end
|
||||||
|
this->end();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// not swiping, check if swipe will begin
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_begin) != 0
|
||||||
|
|| std::regex_match(line, matches, gesture_swipe_update) != 0)
|
||||||
|
{
|
||||||
|
// assign necessary variables for swipe begin
|
||||||
|
this->flag_swiping = true;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
// dispatch begin
|
||||||
|
this->begin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class swipe_gesture : public xdo_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
swipe_gesture();
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
virtual ~swipe_gesture();
|
||||||
|
|
||||||
|
// fields for xdo
|
||||||
|
int fingers;
|
||||||
|
|
||||||
|
// normal values (for touchpad mapping)
|
||||||
|
float x, y, dx, dy;
|
||||||
|
|
||||||
|
// unaccelerated values (for screen mapping)
|
||||||
|
float ux, uy, udx, udy;
|
||||||
|
|
||||||
|
// hooks that we can override (mark as virtual)
|
||||||
|
virtual void begin();
|
||||||
|
virtual void update();
|
||||||
|
virtual void end();
|
||||||
|
virtual bool parse_line(const char *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// location of mouse
|
||||||
|
int screen_num, ix, iy;
|
||||||
|
|
||||||
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
|
bool flag_swiping;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// regex patterns
|
||||||
|
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_END_REGEX_PATTERN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture_h__ */
|
||||||
File renamed without changes.
File renamed without changes.
@@ -39,13 +39,7 @@ namespace comfortable_swipe
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
xdo_gesture();
|
xdo_gesture();
|
||||||
~xdo_gesture();
|
virtual ~xdo_gesture();
|
||||||
|
|
||||||
// hooks
|
|
||||||
virtual void begin() = 0;
|
|
||||||
virtual void update() = 0;
|
|
||||||
virtual void end() = 0;
|
|
||||||
virtual bool parse_line(const char *) = 0;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,15 +19,17 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "index.hpp"
|
#include "all_headers.hpp"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure to include all implementation (.cpp) files below to be ready for export.
|
* Add all cpp files below to be ready for export.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gesture/xdo_gesture.cpp"
|
#include "gesture/xdo_gesture.cpp"
|
||||||
#include "gesture/swipe_gesture.cpp"
|
#include "gesture/swipe_gesture.cpp"
|
||||||
#include "gesture/swipe_gesture.regex.cpp"
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
|
#include "gesture/keyboard_swipe_gesture.cpp"
|
||||||
|
#include "gesture/mouse_hold_gesture.cpp"
|
||||||
#include "service/autostart.cpp"
|
#include "service/autostart.cpp"
|
||||||
#include "service/buffer.cpp"
|
#include "service/buffer.cpp"
|
||||||
#include "service/config.cpp"
|
#include "service/config.cpp"
|
||||||
@@ -40,5 +42,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "util/autostart_filename.cpp"
|
#include "util/autostart_filename.cpp"
|
||||||
#include "util/conf_filename.cpp"
|
#include "util/conf_filename.cpp"
|
||||||
#include "util/read_config_file.cpp"
|
#include "util/read_config_file.cpp"
|
||||||
|
#include "driver.cpp"
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__ */
|
#endif /* __COMFORTABLE_SWIPE__ */
|
||||||
@@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <cstdio> // std::remove
|
#include <cstdio> // std::remove
|
||||||
#include <cstdlib> // std::system
|
#include <cstdlib> // std::system
|
||||||
#include "../index.hpp"
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ namespace comfortable_swipe::service
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
else
|
else
|
||||||
std::cout << "Autostart switched off" << std::endl;
|
std::cout << "Autostart switched off" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// file not found, create it
|
// file not found, create it
|
||||||
int result = std::system(("mkdir -p $(dirname " + path + ")").data());
|
int result = std::system(("mkdir -p $(dirname " + path + ")").data());
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__service_buffer__
|
||||||
|
#define __COMFORTABLE_SWIPE__service_buffer__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstdlib> // std::exit
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
*/
|
||||||
|
namespace comfortable_swipe::service
|
||||||
|
{
|
||||||
|
void buffer()
|
||||||
|
{
|
||||||
|
std::exit(comfortable_swipe::driver());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__service_buffer__ */
|
||||||
@@ -19,8 +19,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../index.hpp"
|
|
||||||
#include <cstdio> // std::puts
|
#include <cstdio> // std::puts
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
File renamed without changes.
@@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdio> // std::puts, std::printf
|
#include <cstdio> // std::puts, std::printf
|
||||||
#include "../index.hpp"
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ namespace comfortable_swipe::service
|
|||||||
void help()
|
void help()
|
||||||
{
|
{
|
||||||
using comfortable_swipe::util::conf_filename;
|
using comfortable_swipe::util::conf_filename;
|
||||||
std::puts("comfortable-swipe [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
std::puts("comfortable-swipe " COMFORTABLE_SWIPE_VERSION " [start|stop|restart|autostart|buffer|help|config|debug|status]");
|
||||||
std::puts("");
|
std::puts("");
|
||||||
std::puts("start - starts 3/4-finger gesture service");
|
std::puts("start - starts 3/4-finger gesture service");
|
||||||
std::puts("stop - stops 3/4-finger gesture service");
|
std::puts("stop - stops 3/4-finger gesture service");
|
||||||
@@ -19,7 +19,9 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../index.hpp"
|
|
||||||
|
#include <cstdio> // freopen, stdout
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -28,7 +30,12 @@ namespace comfortable_swipe::service
|
|||||||
*/
|
*/
|
||||||
void restart()
|
void restart()
|
||||||
{
|
{
|
||||||
|
// dont show stdout on stop
|
||||||
|
freopen("/dev/null", "a", stdout);
|
||||||
comfortable_swipe::service::stop();
|
comfortable_swipe::service::stop();
|
||||||
|
|
||||||
|
// show back on start
|
||||||
|
freopen ("/dev/tty", "a", stdout);
|
||||||
comfortable_swipe::service::start();
|
comfortable_swipe::service::start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,8 +19,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../index.hpp"
|
|
||||||
#include <cstdlib> // std::system
|
#include <cstdlib> // std::system
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../index.hpp"
|
|
||||||
#include <stdexcept> // std::runtime_error
|
#include <stdexcept> // std::runtime_error
|
||||||
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
#include <unistd.h> // popen, pclose, getpid, access, F_OK
|
||||||
#include <memory> // std::unique_ptr
|
#include <memory> // std::unique_ptr
|
||||||
@@ -27,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <cstdlib> // std::atoi
|
#include <cstdlib> // std::atoi
|
||||||
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
#include <cstdio> // FILE, std::feof, std::fgets, std::printf
|
||||||
#include <regex> // std::cmatch, std::regex, std::regex_match
|
#include <regex> // std::cmatch, std::regex, std::regex_match
|
||||||
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -79,7 +73,7 @@ namespace comfortable_swipe::service
|
|||||||
std::printf(" %9s is OFF\n", "threshold");
|
std::printf(" %9s is OFF\n", "threshold");
|
||||||
|
|
||||||
// print swipe commands
|
// print swipe commands
|
||||||
for (auto &command : comfortable_swipe::gesture::swipe_gesture::command_map)
|
for (auto &command : comfortable_swipe::gesture::keyboard_swipe_gesture::command_map)
|
||||||
{
|
{
|
||||||
if (config.count(command) > 0)
|
if (config.count(command) > 0)
|
||||||
std::printf(" %9s is OK (%s)\n", command, config[command].data());
|
std::printf(" %9s is OK (%s)\n", command, config[command].data());
|
||||||
@@ -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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__service_stop__
|
#ifndef __COMFORTABLE_SWIPE__service_stop__
|
||||||
#define __COMFORTABLE_SWIPE__service_stop__
|
#define __COMFORTABLE_SWIPE__service_stop__
|
||||||
|
|
||||||
#include <cstdio> // std::FILE, std::feof, std::fgets
|
|
||||||
#include <cstdlib> // std::atoi, std::system
|
|
||||||
#include <string> // std::string, std::to_string
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
by Rico Tiongson
|
by Rico Tiongson
|
||||||
@@ -26,8 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <unistd.h> // popen, pclose, getpid
|
#include <unistd.h> // popen, pclose, getpid
|
||||||
#include <memory> // std::unique_ptr
|
#include <memory> // std::unique_ptr
|
||||||
#include <array> // std::array
|
#include <array> // std::array
|
||||||
#include <cstdlib> // std::atoi
|
#include <cstdio> // std::FILE, std::feof, std::fgets
|
||||||
#include <cstdio> // FILE, std::feof, std::fgets
|
#include <cstdlib> // std::atoi, std::system
|
||||||
|
#include <string> // std::string, std::to_string
|
||||||
|
|
||||||
namespace comfortable_swipe::service
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
@@ -39,14 +37,14 @@ namespace comfortable_swipe::service
|
|||||||
|
|
||||||
// read all service names from process (pgrep)
|
// read all service names from process (pgrep)
|
||||||
std::array<char, 128> buffer;
|
std::array<char, 128> buffer;
|
||||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose);
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f \"$(which comfortable-swipe)\"", "r"), pclose);
|
||||||
|
|
||||||
// make sure pipe exists
|
// make sure pipe exists
|
||||||
if (!pipe)
|
if (!pipe)
|
||||||
throw std::runtime_error("stop command failed");
|
throw std::runtime_error("stop command failed");
|
||||||
|
|
||||||
// buffer what to kill
|
// buffer what to kill
|
||||||
std::string kill = "kill";
|
std::string kill = "";
|
||||||
|
|
||||||
// read until end of line
|
// read until end of line
|
||||||
while (!std::feof(pipe.get()))
|
while (!std::feof(pipe.get()))
|
||||||
@@ -63,7 +61,15 @@ namespace comfortable_swipe::service
|
|||||||
}
|
}
|
||||||
|
|
||||||
// run "kill {pid1} {pid2}..."
|
// run "kill {pid1} {pid2}..."
|
||||||
(void) std::system(kill.data());
|
if (kill.length())
|
||||||
|
{
|
||||||
|
std::printf("Stopped%s\n", kill.c_str());
|
||||||
|
(void) std::system(("kill" + kill).c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::printf("No program to stop\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File renamed without changes.
@@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../index.hpp"
|
#include "../all_headers.hpp"
|
||||||
|
|
||||||
namespace comfortable_swipe::util
|
namespace comfortable_swipe::util
|
||||||
{
|
{
|
||||||
File renamed without changes.
@@ -19,9 +19,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include <ios> // std::ios
|
#include <ios> // std::ios
|
||||||
#include <iostream> // std::cin, std::cout, std::cerr
|
#include <iostream> // std::cin, std::cout, std::cerr
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include "lib/comfortable_swipe"
|
#include "comfortable_swipe/lib"
|
||||||
|
|
||||||
/* MAIN DRIVER FUNCTION */
|
/* Command-line function. */
|
||||||
|
|
||||||
int main(int argc, char** args)
|
int main(int argc, char** args)
|
||||||
{
|
{
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
dir="$(dirname $0)"
|
||||||
|
version="$(cat "$dir/VERSION" | tr -d '[:space:]')"
|
||||||
|
|
||||||
|
exec g++ $@ \
|
||||||
|
-std=c++11 \
|
||||||
|
-O2 -lxdo -Wno-unused-result \
|
||||||
|
-DCOMFORTABLE_SWIPE_VERSION="\"$version\""
|
||||||
+29
-13
@@ -6,19 +6,6 @@
|
|||||||
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a list of
|
# Refer to https://www.linux.org/threads/xdotool-keyboard.10528/ for a list of
|
||||||
# keycodes you can use.
|
# keycodes you can use.
|
||||||
|
|
||||||
#################
|
|
||||||
# MISCELLANEOUS #
|
|
||||||
#################
|
|
||||||
|
|
||||||
# Threshold
|
|
||||||
# Tweak this value depending on the sensitivity of your mousepad to perform
|
|
||||||
# gestures. A higher value means less sensitive.
|
|
||||||
#
|
|
||||||
# (Note: Sky is the limit! Can be as large as 1000.0)
|
|
||||||
#
|
|
||||||
# Default: threshold = 0.0
|
|
||||||
threshold = 0.0
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# THREE / FOUR FINGER SWIPE #
|
# THREE / FOUR FINGER SWIPE #
|
||||||
#############################
|
#############################
|
||||||
@@ -62,3 +49,32 @@ down3 = ctrl+alt+Up
|
|||||||
# The default shortcut is moving current window to the above workspace.
|
# The default shortcut is moving current window to the above workspace.
|
||||||
# Default: ctrl+alt+shift+Up
|
# Default: ctrl+alt+shift+Up
|
||||||
down4 = ctrl+alt+shift+Up
|
down4 = ctrl+alt+shift+Up
|
||||||
|
|
||||||
|
#################
|
||||||
|
# MISCELLANEOUS #
|
||||||
|
#################
|
||||||
|
|
||||||
|
# Threshold
|
||||||
|
# Tweak this value depending on the sensitivity of your mousepad to perform
|
||||||
|
# gestures. A higher value means less sensitive (Sky is the limit! Can be as
|
||||||
|
# large as 1000.0).
|
||||||
|
# Default: threshold = 0.0
|
||||||
|
threshold = 0.0
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# Experimental: MOUSE HOLD #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
# (1: left click, 2: middle click, 3: right click, 4: wheel up, 5: wheel down)
|
||||||
|
|
||||||
|
# You can set mouse buttons to hold
|
||||||
|
# hold3 = button1
|
||||||
|
# hold3 = button2
|
||||||
|
# hold3 = button3
|
||||||
|
|
||||||
|
# Or you can just let the mouse move with the cursor
|
||||||
|
# hold3 = move
|
||||||
|
|
||||||
|
# Use wheel scroll (experimental)
|
||||||
|
# hold4 = scroll
|
||||||
|
# hold4 = scroll_reverse
|
||||||
@@ -1,82 +1,96 @@
|
|||||||
#!/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
|
set -e
|
||||||
# stop any running comfortable-swipe if it exists
|
|
||||||
$PROGRAM stop
|
|
||||||
fi
|
|
||||||
|
|
||||||
#copy config file
|
function install {
|
||||||
abort () {
|
# prefer running as root
|
||||||
exec echo "Installation aborted"
|
local dir="$(dirname "$0")"
|
||||||
}
|
local program=comfortable-swipe
|
||||||
sudo mkdir -p $(dirname $CONF_PATH) || abort
|
local program_exe=/usr/local/bin/$program
|
||||||
|
local compile_command="$dir/cpp.compile.sh"
|
||||||
|
local compile_target="$dir/command_line.cpp"
|
||||||
|
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"
|
||||||
|
|
||||||
# check if "-y" or "--yes" is passed as an argument
|
if [ -x "$(command -v $program_exe)" ]; then
|
||||||
YES=false
|
# stop any running $program if it exists
|
||||||
while test $# -gt 0
|
$program_exe stop
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
-y) YES=true
|
|
||||||
;;
|
|
||||||
--yes) YES=true
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
sudo chown $USER $(dirname $CONF_PATH)
|
|
||||||
if [ ! -f $CONF_PATH ]; then
|
|
||||||
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
|
fi
|
||||||
else
|
|
||||||
# config file found, ask user if overwrite
|
#copy config file
|
||||||
echo "Old conf file found in $CONF_PATH"
|
abort () {
|
||||||
if [ $YES == false ]; then
|
exec echo "Installation aborted"
|
||||||
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
}
|
||||||
response=${response,,} # tolower
|
sudo mkdir -p "$(dirname $conf_path)" || abort
|
||||||
if [[ "$response" =~ ^(no|n)$ ]]; then
|
|
||||||
read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response
|
# check if "-y" or "--yes" is passed as an argument
|
||||||
response=${response,,}
|
YES=false
|
||||||
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
while test $# -gt 0
|
||||||
cat $DCONF_PATH > $CONF_PATH || abort
|
do
|
||||||
else
|
case "$1" in
|
||||||
abort
|
-y) YES=true
|
||||||
|
;;
|
||||||
|
--yes) YES=true
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
sudo chown $USER "$(dirname $conf_path)"
|
||||||
|
if [ ! -f "$conf_path" ]; then
|
||||||
|
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"
|
||||||
|
if [ "$YES" == false ]; then
|
||||||
|
read -r -p "Keep the old conf file? (default: yes) [Y/n] " response
|
||||||
|
response="${response,,}" # tolower
|
||||||
|
if [[ "$response" =~ ^(no|n)$ ]]; then
|
||||||
|
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" || abort
|
||||||
|
else
|
||||||
|
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" "$compile_target" -o "$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
|
||||||
@@ -1,214 +0,0 @@
|
|||||||
#ifndef __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
|
||||||
#define __COMFORTABLE_SWIPE__gesture_swipe_gesture__
|
|
||||||
|
|
||||||
/*
|
|
||||||
Comfortable Swipe
|
|
||||||
by Rico Tiongson
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <iostream> // std::cout, std::endl
|
|
||||||
#include <string> // std::stoi, std::stof
|
|
||||||
#include <regex> // std::regex, std::regex_match, std::cmatch
|
|
||||||
#include "swipe_gesture.h"
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
|
||||||
// xdo_get_mouse_location
|
|
||||||
// CURRENT_WINDOW
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace comfortable_swipe::gesture
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructs a new swipe gesture, given configurations for certain swipe events.
|
|
||||||
*/
|
|
||||||
swipe_gesture::swipe_gesture
|
|
||||||
(
|
|
||||||
const float threshold,
|
|
||||||
const char* left3 /* 000 */,
|
|
||||||
const char* left4 /* 001 */,
|
|
||||||
const char* right3 /* 010 */,
|
|
||||||
const char* right4 /* 011 */,
|
|
||||||
const char* up3 /* 100 */,
|
|
||||||
const char* up4 /* 101 */,
|
|
||||||
const char* down3 /* 110 */,
|
|
||||||
const char* down4 /* 111 */
|
|
||||||
):
|
|
||||||
comfortable_swipe::gesture::xdo_gesture(),
|
|
||||||
threshold_squared(threshold*threshold),
|
|
||||||
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}),
|
|
||||||
flag_swiping(false)
|
|
||||||
{
|
|
||||||
// improve responsiveness of first gesture by pre-empting xdotool runtime
|
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructs this swipe gesture.
|
|
||||||
*/
|
|
||||||
swipe_gesture::~swipe_gesture()
|
|
||||||
{
|
|
||||||
delete[] commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on begin of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::begin()
|
|
||||||
{
|
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
|
|
||||||
this->previous_gesture = swipe_gesture::FRESH;
|
|
||||||
this->x = 0;
|
|
||||||
this->y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on update of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::update()
|
|
||||||
{
|
|
||||||
this->x += this->dx;
|
|
||||||
this->y += this->dy;
|
|
||||||
// scale threshold to 1/10 when gesture is not fresh
|
|
||||||
float scale = this->previous_gesture == swipe_gesture::FRESH
|
|
||||||
? 1.00f
|
|
||||||
: 0.01f; // square root of 1/10
|
|
||||||
static const float EPSILON = 1e-6f;
|
|
||||||
if (this->x * this->x + this->y * this->y
|
|
||||||
> this->threshold_squared * scale + EPSILON)
|
|
||||||
{
|
|
||||||
int mask = 0;
|
|
||||||
if (this->fingers == 3) mask |= swipe_gesture::MSK_THREE_FINGERS;
|
|
||||||
else if (this->fingers == 4) mask |= swipe_gesture::MSK_FOUR_FINGERS;
|
|
||||||
|
|
||||||
const float absx = x >= 0 ? x : -x;
|
|
||||||
const float absy = y >= 0 ? y : -y;
|
|
||||||
if (absx > absy)
|
|
||||||
{ // horizontal
|
|
||||||
mask |= swipe_gesture::MSK_HORIZONTAL;
|
|
||||||
if (x < 0)
|
|
||||||
mask |= swipe_gesture::MSK_NEGATIVE;
|
|
||||||
else
|
|
||||||
mask |= swipe_gesture::MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
else /* std::abs(x) <= std::abs(y) */
|
|
||||||
{ // vertical
|
|
||||||
mask |= swipe_gesture::MSK_VERTICAL;
|
|
||||||
if (y < 0)
|
|
||||||
mask |= swipe_gesture::MSK_NEGATIVE;
|
|
||||||
else
|
|
||||||
mask |= swipe_gesture::MSK_POSITIVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send command on fresh OR opposite gesture
|
|
||||||
if (this->previous_gesture == swipe_gesture::FRESH
|
|
||||||
|| this->previous_gesture == (mask ^ swipe_gesture::MSK_POSITIVE))
|
|
||||||
{
|
|
||||||
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, swipe_gesture::commands[mask], 0);
|
|
||||||
this->x = this->y = 0;
|
|
||||||
this->previous_gesture = mask;
|
|
||||||
std::cout << "SWIPE " << swipe_gesture::command_map[mask] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook on end of swipe gesture.
|
|
||||||
*/
|
|
||||||
void swipe_gesture::end()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dispatches begin/update/end depending on the regex pattern provided by this class.
|
|
||||||
*
|
|
||||||
* @param line the line from libinput debug-events to parse
|
|
||||||
* @return true if begin/update/end was dispatched
|
|
||||||
*/
|
|
||||||
bool swipe_gesture::parse_line(const char * line)
|
|
||||||
{
|
|
||||||
|
|
||||||
// prepare regex matchers (will only load at most once)
|
|
||||||
static const std::regex gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN);
|
|
||||||
|
|
||||||
// prepare holder for regex matches
|
|
||||||
static std::cmatch matches;
|
|
||||||
|
|
||||||
if (this->flag_swiping)
|
|
||||||
{
|
|
||||||
// currently swiping
|
|
||||||
if (std::regex_match(line, matches, gesture_swipe_update) != 0)
|
|
||||||
{
|
|
||||||
// assign necessary variables for swipe update
|
|
||||||
this->fingers = std::stoi(matches[1]);
|
|
||||||
this->dx = std::stof(matches[2]);
|
|
||||||
this->dy = std::stof(matches[3]);
|
|
||||||
this->udx = std::stof(matches[4]);
|
|
||||||
this->udy = std::stof(matches[5]);
|
|
||||||
// dispatch update
|
|
||||||
this->update();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (std::regex_match(line, matches, gesture_swipe_end) != 0)
|
|
||||||
{
|
|
||||||
// assign necessary variables for swipe end
|
|
||||||
this->flag_swiping = false;
|
|
||||||
this->fingers = std::stoi(matches[1]);
|
|
||||||
// dispatch end
|
|
||||||
this->end();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// not swiping, check if swipe will begin
|
|
||||||
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
|
|
||||||
{
|
|
||||||
// assign necessary variables for swipe begin
|
|
||||||
this->flag_swiping = true;
|
|
||||||
this->fingers = std::stoi(matches[1]);
|
|
||||||
// dispatch begin
|
|
||||||
this->begin();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* STATICS DEFINITIONS */
|
|
||||||
const int swipe_gesture::MSK_THREE_FINGERS = 0;
|
|
||||||
const int swipe_gesture::MSK_FOUR_FINGERS = 1;
|
|
||||||
const int swipe_gesture::MSK_NEGATIVE = 0;
|
|
||||||
const int swipe_gesture::MSK_POSITIVE = 2;
|
|
||||||
const int swipe_gesture::MSK_HORIZONTAL = 0;
|
|
||||||
const int swipe_gesture::MSK_VERTICAL = 4;
|
|
||||||
const int swipe_gesture::FRESH = -1;
|
|
||||||
const char * const swipe_gesture::command_map[8] = {
|
|
||||||
"left3",
|
|
||||||
"left4",
|
|
||||||
"right3",
|
|
||||||
"right4",
|
|
||||||
"up3",
|
|
||||||
"up4",
|
|
||||||
"down3",
|
|
||||||
"down4"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */
|
|
||||||
+23
-5
@@ -1,6 +1,24 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
DIR=$(dirname $0)
|
set -e
|
||||||
g++ -std=c++11 -O2 $DIR/test_regex.cpp -lxdo -o test.out || exec "Test aborted"
|
|
||||||
./test.out || rm test.out
|
DIR="$(dirname "$0")"
|
||||||
rm test.out
|
|
||||||
|
# just call abort on error
|
||||||
|
tempout="$(mktemp)"
|
||||||
|
abort () {
|
||||||
|
rm "$tempout"
|
||||||
|
echo "Test aborted"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# run all shell files in this directory
|
||||||
|
for sh in "$DIR/test_"*.sh; do
|
||||||
|
/bin/bash "$sh" || abort
|
||||||
|
done
|
||||||
|
|
||||||
|
# run all cpp files in this directory
|
||||||
|
for cpp in "$DIR/test_"*.cpp; do
|
||||||
|
g++ -std=c++11 -O2 "$cpp" -lxdo -o "$tempout" || abort
|
||||||
|
"$tempout" || abort
|
||||||
|
done
|
||||||
Executable
+32
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
DIR="$(dirname "$0")"
|
||||||
|
root="$(dirname "$DIR")"
|
||||||
|
compiler="$root/cpp.compile.sh"
|
||||||
|
command_line="$root/command_line.cpp"
|
||||||
|
module="$root/comfortable_swipe"
|
||||||
|
|
||||||
|
# just call abort on error
|
||||||
|
tempout="$(mktemp)"
|
||||||
|
abort () {
|
||||||
|
rm "$tempout"
|
||||||
|
echo "Test aborted"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# try to compile every cpp/hpp file in module
|
||||||
|
# header files first
|
||||||
|
# then compile cpp files
|
||||||
|
# finally, compile command line
|
||||||
|
shopt -s nullglob
|
||||||
|
for cpp in \
|
||||||
|
"$module"/**/*.h \
|
||||||
|
"$module"/**/*.hpp \
|
||||||
|
"$module"/**/*.cpp \
|
||||||
|
"$module"/lib \
|
||||||
|
"$command_line"
|
||||||
|
do
|
||||||
|
"$compiler" -c "$cpp" -o "$tempout" || abort
|
||||||
|
done
|
||||||
Regular → Executable
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "../lib/gesture/swipe_gesture.h"
|
#include "../comfortable_swipe/gesture/swipe_gesture.h"
|
||||||
#include "../lib/gesture/swipe_gesture.regex.cpp"
|
#include "../comfortable_swipe/gesture/swipe_gesture.regex.cpp"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Comfortable Swipe
|
Comfortable Swipe
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo "Uninstalling..."
|
echo "Uninstalling..."
|
||||||
rm ${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop 2> /dev/null
|
rm "${XDG_CONFIG_HOME:-$HOME/.config}/autostart/comfortable-swipe.desktop" 2> /dev/null
|
||||||
comfortable-swipe stop 2> /dev/null
|
comfortable-swipe stop 2> /dev/null
|
||||||
rm $HOME/.local/bin/comfortable-swipe 2> /dev/null # compat
|
rm "$HOME/.local/bin/comfortable-swipe" 2> /dev/null # compat
|
||||||
sudo rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
sudo rm /usr/local/bin/comfortable-swipe 2> /dev/null
|
||||||
echo "Successfully uninstalled comfortable-swipe"
|
echo "Successfully uninstalled comfortable-swipe"
|
||||||
Reference in new issue
Block a user