Add Pinch Gestures
https://github.com/Hikari9/comfortable-swipe-ubuntu/issues/8 2 Finger pinch support can be added by adding a corresponding value to mask
This commit is contained in:
parent
0de8777d87
commit
9c02832981
@ -48,6 +48,8 @@ extern "C" {
|
|||||||
#define MSK_POSITIVE 2
|
#define MSK_POSITIVE 2
|
||||||
#define MSK_HORIZONTAL 0
|
#define MSK_HORIZONTAL 0
|
||||||
#define MSK_VERTICAL 4
|
#define MSK_VERTICAL 4
|
||||||
|
#define MSK_SWIPE 0
|
||||||
|
#define MSK_PINCH 8
|
||||||
|
|
||||||
/* GESTURE MNEMONYMS */
|
/* GESTURE MNEMONYMS */
|
||||||
#define FRESH -1
|
#define FRESH -1
|
||||||
@ -59,6 +61,7 @@ namespace util {
|
|||||||
string join(cstr, string[], int);
|
string join(cstr, string[], int);
|
||||||
string build_gesture_begin();
|
string build_gesture_begin();
|
||||||
string build_gesture_update();
|
string build_gesture_update();
|
||||||
|
string build_gesture_updatedos();
|
||||||
string build_gesture_end();
|
string build_gesture_end();
|
||||||
map<string, string> read_config_file(const char*);
|
map<string, string> read_config_file(const char*);
|
||||||
}
|
}
|
||||||
@ -90,7 +93,7 @@ int main(int argc, char** args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct swipe_gesture {
|
struct swipe_gesture {
|
||||||
string device, stamp, fingers;
|
string device, type, stamp, fingers;
|
||||||
string dx, dy, udx, udy;
|
string dx, dy, udx, udy;
|
||||||
xdo_t* xdo;
|
xdo_t* xdo;
|
||||||
virtual void on_update() = 0;
|
virtual void on_update() = 0;
|
||||||
@ -101,14 +104,22 @@ struct swipe_gesture {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const char* const command_map[] = {
|
const char* const command_map[] = {
|
||||||
"left 3",
|
"swipe left 3",
|
||||||
"left 4",
|
"swipe left 4",
|
||||||
"right 3",
|
"swipe right 3",
|
||||||
"right 4",
|
"swipe right 4",
|
||||||
"up 3",
|
"swipe up 3",
|
||||||
"up 4",
|
"swipe up 4",
|
||||||
"down 3",
|
"swipe down 3",
|
||||||
"down 4"
|
"swipe down 4",
|
||||||
|
"pinch left 3",
|
||||||
|
"pinch left 4",
|
||||||
|
"pinch right 3",
|
||||||
|
"pinch right 4",
|
||||||
|
"pinch up 3",
|
||||||
|
"pinch up 4",
|
||||||
|
"pinch down 3",
|
||||||
|
"pinch down 4"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct swipe_gesture_impl : swipe_gesture {
|
struct swipe_gesture_impl : swipe_gesture {
|
||||||
@ -118,24 +129,40 @@ struct swipe_gesture_impl : swipe_gesture {
|
|||||||
const char** commands;
|
const char** commands;
|
||||||
swipe_gesture_impl(
|
swipe_gesture_impl(
|
||||||
const float threshold,
|
const float threshold,
|
||||||
const char* left3 /* 000 */,
|
const char* swipe_left3 /* 000 */,
|
||||||
const char* left4 /* 001 */,
|
const char* swipe_left4 /* 001 */,
|
||||||
const char* right3 /* 010 */,
|
const char* swipe_right3 /* 010 */,
|
||||||
const char* right4 /* 011 */,
|
const char* swipe_right4 /* 011 */,
|
||||||
const char* up3 /* 100 */,
|
const char* swipe_up3 /* 100 */,
|
||||||
const char* up4 /* 101 */,
|
const char* swipe_up4 /* 101 */,
|
||||||
const char* down3 /* 110 */,
|
const char* swipe_down3 /* 110 */,
|
||||||
const char* down4 /* 111 */
|
const char* swipe_down4 /* 111 */,
|
||||||
|
const char* pinch_left3 /* ??? */,
|
||||||
|
const char* pinch_left4 /* 001 */,
|
||||||
|
const char* pinch_right3 /* 010 */,
|
||||||
|
const char* pinch_right4 /* 011 */,
|
||||||
|
const char* pinch_up3 /* 100 */,
|
||||||
|
const char* pinch_up4 /* 101 */,
|
||||||
|
const char* pinch_down3 /* 110 */,
|
||||||
|
const char* pinch_down4 /* 111 */
|
||||||
): swipe_gesture(), threshold(threshold) {
|
): swipe_gesture(), threshold(threshold) {
|
||||||
commands = new const char*[8];
|
commands = new const char*[16];
|
||||||
commands[0] = left3;
|
commands[0] = swipe_left3;
|
||||||
commands[1] = left4;
|
commands[1] = swipe_left4;
|
||||||
commands[2] = right3;
|
commands[2] = swipe_right3;
|
||||||
commands[3] = right4;
|
commands[3] = swipe_right4;
|
||||||
commands[4] = up3;
|
commands[4] = swipe_up3;
|
||||||
commands[5] = up4;
|
commands[5] = swipe_up4;
|
||||||
commands[6] = down3;
|
commands[6] = swipe_down3;
|
||||||
commands[7] = down4;
|
commands[7] = swipe_down4;
|
||||||
|
commands[8] = pinch_left3;
|
||||||
|
commands[9] = pinch_left4;
|
||||||
|
commands[10] = pinch_right3;
|
||||||
|
commands[11] = pinch_right4;
|
||||||
|
commands[12] = pinch_up3;
|
||||||
|
commands[13] = pinch_up4;
|
||||||
|
commands[14] = pinch_down3;
|
||||||
|
commands[15] = pinch_down4;
|
||||||
}
|
}
|
||||||
~swipe_gesture_impl() {
|
~swipe_gesture_impl() {
|
||||||
delete[] commands;
|
delete[] commands;
|
||||||
@ -158,8 +185,8 @@ struct swipe_gesture_impl : swipe_gesture {
|
|||||||
0.1f;
|
0.1f;
|
||||||
if (x*x + y*y > threshold*threshold*(scale*scale)) {
|
if (x*x + y*y > threshold*threshold*(scale*scale)) {
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
if (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
if (type == "SWIPE") mask |= MSK_SWIPE; else
|
||||||
if (fingers == "4") mask |= MSK_FOUR_FINGERS;
|
if (type == "PINCH") mask |= MSK_PINCH;
|
||||||
if (abs(x) > abs(y)) {
|
if (abs(x) > abs(y)) {
|
||||||
mask |= MSK_HORIZONTAL;
|
mask |= MSK_HORIZONTAL;
|
||||||
if (x < 0) mask |= MSK_NEGATIVE;
|
if (x < 0) mask |= MSK_NEGATIVE;
|
||||||
@ -169,11 +196,14 @@ 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 (fingers == "3") mask |= MSK_THREE_FINGERS; else
|
||||||
if (previous_gesture == FRESH or previous_gesture == OPPOSITE) {
|
if (fingers == "4") mask |= MSK_FOUR_FINGERS; else
|
||||||
|
mask = FRESH;
|
||||||
|
// send command on fresh OR opposite gesture
|
||||||
|
if ((previous_gesture == FRESH or previous_gesture == OPPOSITE) && mask != FRESH) {
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
previous_gesture = mask;
|
previous_gesture = mask;
|
||||||
cout << "SWIPE " << command_map[mask] << endl;
|
cout << "Action: " << command_map[mask] << endl;
|
||||||
key(commands[mask]);
|
key(commands[mask]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,6 +244,7 @@ namespace service {
|
|||||||
cin.tie(0); cout.tie(0);
|
cin.tie(0); cout.tie(0);
|
||||||
const regex gesture_begin(util::build_gesture_begin());
|
const regex gesture_begin(util::build_gesture_begin());
|
||||||
const regex gesture_update(util::build_gesture_update());
|
const regex gesture_update(util::build_gesture_update());
|
||||||
|
const regex gesture_updatedos(util::build_gesture_updatedos());
|
||||||
const regex gesture_end(util::build_gesture_end());
|
const regex gesture_end(util::build_gesture_end());
|
||||||
string sentence;
|
string sentence;
|
||||||
// read config file
|
// read config file
|
||||||
@ -228,31 +259,53 @@ namespace service {
|
|||||||
config["up3"].c_str(),
|
config["up3"].c_str(),
|
||||||
config["up4"].c_str(),
|
config["up4"].c_str(),
|
||||||
config["down3"].c_str(),
|
config["down3"].c_str(),
|
||||||
config["down4"].c_str()
|
config["down4"].c_str(),
|
||||||
|
config["pinch_left3"].c_str(),
|
||||||
|
config["pinch_left4"].c_str(),
|
||||||
|
config["pinch_right3"].c_str(),
|
||||||
|
config["pinch_right4"].c_str(),
|
||||||
|
config["pinch_up3"].c_str(),
|
||||||
|
config["pinch_up4"].c_str(),
|
||||||
|
config["pinch_down3"].c_str(),
|
||||||
|
config["pinch_down4"].c_str()
|
||||||
);
|
);
|
||||||
while (getline(cin, sentence)) {
|
while (getline(cin, sentence)) {
|
||||||
auto data = sentence.data();
|
auto data = sentence.data();
|
||||||
cmatch matches;
|
cmatch matches;
|
||||||
if (regex_match(data, matches, gesture_begin)) {
|
if (regex_match(data, matches, gesture_begin)) {
|
||||||
swipe.device = matches[1];
|
swipe.device = matches[1];
|
||||||
swipe.stamp = matches[2];
|
swipe.type = matches[2];
|
||||||
swipe.fingers = matches[3];
|
swipe.stamp = matches[3];
|
||||||
|
swipe.fingers = matches[4];
|
||||||
swipe.on_begin();
|
swipe.on_begin();
|
||||||
}
|
}
|
||||||
else if (regex_match(data, matches, gesture_end)) {
|
else if (regex_match(data, matches, gesture_end)) {
|
||||||
swipe.device = matches[1];
|
swipe.device = matches[1];
|
||||||
swipe.stamp = matches[2];
|
swipe.type = matches[2];
|
||||||
swipe.fingers = matches[3];
|
swipe.stamp = matches[3];
|
||||||
|
swipe.fingers = matches[4];
|
||||||
swipe.on_end();
|
swipe.on_end();
|
||||||
}
|
}
|
||||||
else if (regex_match(data, matches, gesture_update)) {
|
else if (regex_match(data, matches, gesture_update)) {
|
||||||
swipe.device = matches[1];
|
swipe.device = matches[1];
|
||||||
swipe.stamp = matches[2];
|
swipe.type = matches[2];
|
||||||
swipe.fingers = matches[3];
|
swipe.stamp = matches[3];
|
||||||
swipe.dx = matches[4];
|
swipe.fingers = matches[4];
|
||||||
swipe.dy = matches[5];
|
swipe.dx = matches[5];
|
||||||
swipe.udx = matches[6];
|
swipe.dy = matches[6];
|
||||||
swipe.udy = matches[7];
|
swipe.udx = matches[7];
|
||||||
|
swipe.udy = matches[8];
|
||||||
|
swipe.on_update();
|
||||||
|
}
|
||||||
|
else if (regex_match(data, matches, gesture_updatedos)) {
|
||||||
|
swipe.device = matches[1];
|
||||||
|
swipe.type = matches[2];
|
||||||
|
swipe.stamp = matches[3];
|
||||||
|
swipe.fingers = matches[4];
|
||||||
|
swipe.dx = matches[5];
|
||||||
|
swipe.dy = matches[6];
|
||||||
|
swipe.udx = matches[7];
|
||||||
|
swipe.udy = matches[8];
|
||||||
swipe.on_update();
|
swipe.on_update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +405,7 @@ namespace util {
|
|||||||
|
|
||||||
string build_gesture_begin() {
|
string build_gesture_begin() {
|
||||||
string device = "\\s*(\\S+)\\s*";
|
string device = "\\s*(\\S+)\\s*";
|
||||||
string gesture = "\\s*GESTURE_SWIPE_BEGIN\\s*";
|
string gesture = "\\s*GESTURE_(\\S+)_BEGIN\\s*";
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
string seconds = "\\s*(\\S+)\\s*";
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
string fingers = "\\s*(\\d+)\\s*";
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
string arr[] = {device, gesture, seconds, fingers};
|
||||||
@ -361,7 +414,7 @@ namespace util {
|
|||||||
|
|
||||||
string build_gesture_update() {
|
string build_gesture_update() {
|
||||||
string device = "\\s*(\\S+)\\s*";
|
string device = "\\s*(\\S+)\\s*";
|
||||||
string gesture = "\\s*GESTURE_SWIPE_UPDATE\\s*";
|
string gesture = "\\s*GESTURE_(\\S+)_UPDATE\\s*";
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
string seconds = "\\s*(\\S+)\\s*";
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
string fingers = "\\s*(\\d+)\\s*";
|
||||||
string num_1 = "\\s*(" + number_regex() + ")\\s*";
|
string num_1 = "\\s*(" + number_regex() + ")\\s*";
|
||||||
@ -372,9 +425,23 @@ namespace util {
|
|||||||
return join("\\s+", arr, 6);
|
return join("\\s+", arr, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string build_gesture_updatedos() {
|
||||||
|
string device = "\\s*(\\S+)\\s*";
|
||||||
|
string gesture = "\\s*GESTURE_(\\S+)_UPDATE\\s*";
|
||||||
|
string seconds = "\\s*(\\S+)\\s*";
|
||||||
|
string fingers = "\\s*(\\d+)\\s*";
|
||||||
|
string num_1 = "\\s*(" + number_regex() + ")\\s*";
|
||||||
|
string num_2 = num_1;
|
||||||
|
string num_div = num_1 + "/" + num_2;
|
||||||
|
string num_accel = "\\s*\\(\\s*" + num_div + "\\s*unaccelerated\\s*\\)\\s*";
|
||||||
|
string num_div2 = num_1 + "@" + num_2;
|
||||||
|
string arr[] = {device, gesture, seconds, fingers, num_div, num_accel, num_div2};
|
||||||
|
return join("\\s+", arr, 7);
|
||||||
|
}
|
||||||
|
|
||||||
string build_gesture_end() {
|
string build_gesture_end() {
|
||||||
string device = "\\s*(\\S+)\\s*";
|
string device = "\\s*(\\S+)\\s*";
|
||||||
string gesture = "\\s*GESTURE_SWIPE_END\\s*";
|
string gesture = "\\s*GESTURE_(\\S+)_END\\s*";
|
||||||
string seconds = "\\s*(\\S+)\\s*";
|
string seconds = "\\s*(\\S+)\\s*";
|
||||||
string fingers = "\\s*(\\d+)\\s*";
|
string fingers = "\\s*(\\d+)\\s*";
|
||||||
string arr[] = {device, gesture, seconds, fingers};
|
string arr[] = {device, gesture, seconds, fingers};
|
||||||
|
|||||||
@ -27,7 +27,7 @@ left3 = ctrl+alt+Right
|
|||||||
|
|
||||||
# 4-finger swipe left
|
# 4-finger swipe left
|
||||||
# The default shortcut is moving current window to the right workspace.
|
# The default shortcut is moving current window to the right workspace.
|
||||||
# Default: left4=ctrl+alt+shift+Right
|
# Default: left4 = ctrl+alt+shift+Right
|
||||||
left4 = ctrl+alt+shift+Right
|
left4 = ctrl+alt+shift+Right
|
||||||
|
|
||||||
# 3-finger swipe right
|
# 3-finger swipe right
|
||||||
@ -37,7 +37,7 @@ right3 = ctrl+alt+Left
|
|||||||
|
|
||||||
# 4-finger swipe right
|
# 4-finger swipe right
|
||||||
# The default shortcut is moving current window to the left workspace.
|
# The default shortcut is moving current window to the left workspace.
|
||||||
# Default: right4=ctrl+alt+shift+Left
|
# Default: right4 = ctrl+alt+shift+Left
|
||||||
right4 = ctrl+alt+shift+Left
|
right4 = ctrl+alt+shift+Left
|
||||||
|
|
||||||
# 3-finger swipe up
|
# 3-finger swipe up
|
||||||
@ -47,7 +47,7 @@ up3 = ctrl+alt+Down
|
|||||||
|
|
||||||
# 4-finger swipe up
|
# 4-finger swipe up
|
||||||
# The default shortcut is moving current window to the bottom workspace.
|
# The default shortcut is moving current window to the bottom workspace.
|
||||||
# Default: ctrl+alt+shift+Down
|
# Default: up4 = ctrl+alt+shift+Down
|
||||||
up4 = ctrl+alt+shift+Down
|
up4 = ctrl+alt+shift+Down
|
||||||
|
|
||||||
# 3-finger swipe down
|
# 3-finger swipe down
|
||||||
@ -57,5 +57,49 @@ down3 = ctrl+alt+Up
|
|||||||
|
|
||||||
# 4-finger swipe down
|
# 4-finger swipe down
|
||||||
# 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: down 4 = ctrl+alt+shift+Up
|
||||||
down4 = ctrl+alt+shift+Up
|
down4 = ctrl+alt+shift+Up
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# THREE / FOUR FINGER pinch #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
# 3-finger pinch left
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_left3 = super+W
|
||||||
|
pinch_left3 = super+W
|
||||||
|
|
||||||
|
# 4-finger pinch left
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_left4 = super+W
|
||||||
|
pinch_left4 = super+W
|
||||||
|
|
||||||
|
# 3-finger pinch right
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_right3 = super+W
|
||||||
|
pinch_right3 = super+W
|
||||||
|
|
||||||
|
# 4-finger pinch right
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_right4 = super+W
|
||||||
|
pinch_right4 = super+W
|
||||||
|
|
||||||
|
# 3-finger pinch up
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_up3 = ctrl+alt+Down
|
||||||
|
pinch_up3 = super+W
|
||||||
|
|
||||||
|
# 4-finger pinch up
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_up4 = super+W
|
||||||
|
pinch_up4 = super+W
|
||||||
|
|
||||||
|
# 3-finger pinch down
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_down3 = super+W
|
||||||
|
pinch_down3 = super+W
|
||||||
|
|
||||||
|
# 4-finger pinch down
|
||||||
|
# The default shortcut is spreading windows.
|
||||||
|
# Default: pinch_down4 = super+W
|
||||||
|
pinch_down4 = super+W
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user