[swipe-back] Allow swipe back on opposite gesture without lifting finger
This commit is contained in:
parent
2d8a885814
commit
48b4e6aa99
6
install
6
install
@ -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
|
||||||
|
|||||||
@ -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,10 +167,15 @@ 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;
|
||||||
}
|
}
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if (previous_gesture == FRESH or previous_gesture == OPPOSITE) {
|
||||||
|
x = y = 0;
|
||||||
|
previous_gesture = mask;
|
||||||
cout << "SWIPE " << command_map[mask] << endl;
|
cout << "SWIPE " << command_map[mask] << endl;
|
||||||
key(commands[mask]);
|
key(commands[mask]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void on_end() override {
|
void on_end() override {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user