Merge pull request #10 from Hikari9/swipe-back-feature

[swipe-back] Allow swipe back on opposite gesture without lifting finger
This commit is contained in:
Rico Tiongson 2017-11-03 23:50:18 +08:00 committed by GitHub
commit 3f53a19f93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 10 deletions

View File

@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
DIR=$(dirname $0) DIR=$(dirname $0)
if [ -x "$(command -v git)" ]; then
# stop any running comfortable-swipe if it exists
comfortable-swipe stop
fi
#copy config file #copy config file
mkdir -p ~/.config mkdir -p ~/.config
DCONF_PATH=$DIR/src/defaults.conf DCONF_PATH=$DIR/src/defaults.conf

View File

@ -47,6 +47,9 @@ extern "C" {
#define MSK_HORIZONTAL 0 #define MSK_HORIZONTAL 0
#define MSK_VERTICAL 4 #define MSK_VERTICAL 4
/* GESTURE MNEMONYMS */
#define FRESH -1
#define OPPOSITE (mask ^ MSK_POSITIVE)
/* FORWARD DECLARATIONS */ /* FORWARD DECLARATIONS */
@ -108,8 +111,8 @@ const char* const command_map[] = {
struct swipe_gesture_impl : swipe_gesture { struct swipe_gesture_impl : swipe_gesture {
int screen_num, ix, iy, threshold; int screen_num, ix, iy, threshold;
double x, y; float x, y;
bool gesture_done; int previous_gesture;
const char** commands; const char** commands;
swipe_gesture_impl( swipe_gesture_impl(
const int threshold, const int threshold,
@ -140,16 +143,18 @@ struct swipe_gesture_impl : swipe_gesture {
} }
void on_begin() override { void on_begin() override {
xdo_get_mouse_location(xdo, &ix, &iy, &screen_num); xdo_get_mouse_location(xdo, &ix, &iy, &screen_num);
gesture_done = false; previous_gesture = FRESH;
x = 0; x = 0;
y = 0; y = 0;
} }
void on_update() override { void on_update() override {
if (gesture_done) return; x += stof(dx);
x += stod(dx); y += stof(dy);
y += stod(dy); // scale threshold to 1/10 when gesture is not fresh
if (x*x + y*y > threshold*threshold) { float scale = previous_gesture == FRESH ?
gesture_done = true; 1.0f :
0.1f;
if (x*x + y*y > threshold*threshold*(scale*scale)) {
int mask = 0; int mask = 0;
if (fingers == "3") mask |= MSK_THREE_FINGERS; else if (fingers == "3") mask |= MSK_THREE_FINGERS; else
if (fingers == "4") mask |= MSK_FOUR_FINGERS; if (fingers == "4") mask |= MSK_FOUR_FINGERS;
@ -162,8 +167,13 @@ struct swipe_gesture_impl : swipe_gesture {
if (y < 0) mask |= MSK_NEGATIVE; if (y < 0) mask |= MSK_NEGATIVE;
else mask |= MSK_POSITIVE; else mask |= MSK_POSITIVE;
} }
cout << "SWIPE " << command_map[mask] << endl; // send command on fresh OR opposite gesture
key(commands[mask]); if (previous_gesture == FRESH or previous_gesture == OPPOSITE) {
x = y = 0;
previous_gesture = mask;
cout << "SWIPE " << command_map[mask] << endl;
key(commands[mask]);
}
} }
} }
void on_end() override { void on_end() override {