From 33c737177a67b216eaa29b304eb9af6fb5478239 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Sun, 27 Oct 2019 19:14:50 +0200 Subject: [PATCH 01/24] - Added pinch gestures Basic implementation enables one shot pinch gesture. That is the command from config file will run only once as soon as fingers move 50% from the initial fingers position. - Added a configurable distance variable to pinch gesture. I felt that pinch gesture is kinda tricky to execute on touchpad, so I changed a way of calculation when to trigger the command and added the distance for fingers travel to configuration. Basically a `0.5` distance feels quite ok to me, but it becomes really snappy at `0.1`. --- README.md | 20 ++++++++++++- src/config/config.cpp | 10 +++++-- src/config/config.h | 10 +++++-- src/io/input.cpp | 70 +++++++++++++++++++++++++++++++++++++------ src/io/input.h | 23 ++++++++++++-- 5 files changed, 114 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index bb51f9e..741395f 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,17 @@ right_down = "" down = "" left = "" right = "" + +[commands.pinch] +in = "" +out = "" +distance="" ``` +* `distance` variable in `commands.pinch` sets the distance between fingers where it shold trigger. + Defaults to `0.5` which means fingers should travel exactly half way from their initial position. + + ### Repository versions ![](https://img.shields.io/aur/version/gebaar.svg?style=flat) @@ -77,6 +86,7 @@ down = "bspc node -f south" left = "bspc node -f west" right = "bspc node -f east" + [commands.swipe.four] left_up = "" right_up = "" @@ -86,6 +96,11 @@ right_down = "" down = "" left = "bspc desktop -f prev" right = "bspc desktop -f next" + +[commands.pinch] +in = "xdotool key Control_L+equal" +out = "xdotool key Control_L+minus" +ditance="0.1" ``` Add `gebaard -b` to `~/.config/bspwm/bspwmrc` @@ -93,9 +108,12 @@ Add `gebaard -b` to `~/.config/bspwm/bspwmrc` ### State of the project - [x] Receiving swipe events from libinput -- [ ] Receiving pinch/zoom events from libinput +- [x] Receiving pinch/zoom events from libinput + - [ ] Support continous pinch + - [ ] Support pinch-and-rotate gestures - [ ] Receiving rotation events from libinput - [x] Converting libinput events to motions - [x] Running commands based on motions - [x] Refactor code to be up to Release standards, instead of testing-hell + diff --git a/src/config/config.cpp b/src/config/config.cpp index bafa3c6..d13dcef 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -1,17 +1,17 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ @@ -61,6 +61,10 @@ void gebaar::config::Config::load_config() swipe_four_commands[8] = *config->get_qualified_as("commands.swipe.four.down"); swipe_four_commands[9] = *config->get_qualified_as("commands.swipe.four.right_down"); + pinch_commands[PINCH_IN] = *config->get_qualified_as("commands.pinch.out"); + pinch_commands[PINCH_OUT] = *config->get_qualified_as("commands.pinch.in"); + pinch_commands[DISTANCE] = *config->get_qualified_as("commands.pinch.distance"); + loaded = true; } } diff --git a/src/config/config.h b/src/config/config.h index 499eb51..45e7642 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -1,17 +1,17 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ @@ -33,8 +33,12 @@ namespace gebaar::config { void load_config(); + + enum pinches {PINCH_IN, PINCH_OUT, DISTANCE}; + std::string swipe_three_commands[10]; std::string swipe_four_commands[10]; + std::string pinch_commands[10]; private: bool config_file_exists(); diff --git a/src/io/input.cpp b/src/io/input.cpp index 943dc96..22f1409 100644 --- a/src/io/input.cpp +++ b/src/io/input.cpp @@ -1,17 +1,17 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ @@ -28,6 +28,7 @@ gebaar::io::Input::Input(std::shared_ptr const& config_p { config = config_ptr; gesture_swipe_event = {}; + gesture_pinch_event = {}; } /** @@ -42,6 +43,54 @@ bool gebaar::io::Input::initialize_context() return libinput_udev_assign_seat(libinput, "seat0")==0; } + + +/** + * Pinch Gesture + * Currently supporting only "one shot" pinch-in and pinch-out gestures. + * @param gev Gesture Event + * @param begin Boolean to denote begin or continuation of gesture. + **/ +void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool begin) +{ + if (begin) { + gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); + // Get pinch distance + try { + gesture_pinch_event.distance = std::stod(config->pinch_commands[config->DISTANCE]); + } + catch (const std::invalid_argument &ia) { + // Set default distance + gesture_pinch_event.distance = DEFAULT_DISTANCE; + } + // Reset pinch data + gesture_pinch_event.scale = DEFAULT_SCALE; + gesture_pinch_event.executed = false; + } + else { + // Ignore input after command execution + if (gesture_pinch_event.executed) return; + double new_scale = libinput_event_gesture_get_scale(gev); + if (new_scale > gesture_pinch_event.scale) { + // Scale up + // Add 1 to required distance to get 2 > x > 1 + if (new_scale > 1 + gesture_pinch_event.distance) { + std::system(config->pinch_commands[config->PINCH_IN].c_str()); + gesture_pinch_event.executed = true; + } + } + else { + // Scale Down + // Substract from 1 to have inverted value for pinch in gesture + if (gesture_pinch_event.scale < 1 - gesture_pinch_event.distance) { + std::system(config->pinch_commands[config->PINCH_OUT].c_str()); + gesture_pinch_event.executed = true; + } + } + gesture_pinch_event.scale = new_scale; + } +} + /** * This event has no coordinates, so it's an event that gives us a begin or end signal. * If it begins, we get the amount of fingers used. @@ -169,6 +218,15 @@ void gebaar::io::Input::handle_event() case LIBINPUT_EVENT_GESTURE_SWIPE_END: handle_swipe_event_without_coords(libinput_event_get_gesture_event(libinput_event), false); break; + case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), true); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), false); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_END: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), false); + break; case LIBINPUT_EVENT_NONE: break; case LIBINPUT_EVENT_DEVICE_ADDED: @@ -209,12 +267,6 @@ void gebaar::io::Input::handle_event() break; case LIBINPUT_EVENT_TABLET_PAD_STRIP: break; - case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: - break; - case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: - break; - case LIBINPUT_EVENT_GESTURE_PINCH_END: - break; case LIBINPUT_EVENT_SWITCH_TOGGLE: break; } diff --git a/src/io/input.h b/src/io/input.h index b40d61f..af52637 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -1,17 +1,17 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ @@ -24,6 +24,10 @@ #include #include "../config/config.h" +#define DEFAULT_SCALE 1.0 +#define DEFAULT_DISTANCE 0.5 + + namespace gebaar::io { struct gesture_swipe_event { int fingers; @@ -31,6 +35,15 @@ namespace gebaar::io { double y; }; + struct gesture_pinch_event { + int fingers; + double scale; + double angle; + + double distance; + bool executed; + }; + class Input { public: Input(std::shared_ptr const& config_ptr); @@ -48,6 +61,7 @@ namespace gebaar::io { struct libinput_event* libinput_event; struct udev* udev; struct gesture_swipe_event gesture_swipe_event; + struct gesture_pinch_event gesture_pinch_event; bool initialize_context(); @@ -74,6 +88,9 @@ namespace gebaar::io { void handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin); void handle_swipe_event_with_coords(libinput_event_gesture* gev); + + void handle_pinch_event(libinput_event_gesture* gev, bool begin); + }; } From 42b068f463fa6434d87b3790d65d47dff39d2079 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Thu, 31 Oct 2019 13:31:45 +0200 Subject: [PATCH 02/24] Added swipe gestures threshold * Reorganized code a little bit - Previously swipe gesture was triggered only when fingers leaving touchpad thus threshold was useless. Moved trigger function outside of event handling. - Created reset functions for gestures to reset struct holding event data to default values. * Added swipe threshold. - Added new config keys * `settings.pinch.distance` - now instead of `pinch.commands.distance` holds the value required for fingers to travel before executing pinch gesture. * `settings.swipe.threshold` - new key to set how long should be swipe to execute command. --- src/config/config.cpp | 4 +- src/config/config.h | 4 +- src/io/input.cpp | 122 +++++++++++++++++++++++++++--------------- src/io/input.h | 16 +++++- 4 files changed, 98 insertions(+), 48 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index d13dcef..6292580 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -63,7 +63,9 @@ void gebaar::config::Config::load_config() pinch_commands[PINCH_IN] = *config->get_qualified_as("commands.pinch.out"); pinch_commands[PINCH_OUT] = *config->get_qualified_as("commands.pinch.in"); - pinch_commands[DISTANCE] = *config->get_qualified_as("commands.pinch.distance"); + + settings[DISTANCE] = *config->get_qualified_as("settings.pinch.distance"); + settings[THRESHOLD] = *config->get_qualified_as("settings.swipe.threshold"); loaded = true; } diff --git a/src/config/config.h b/src/config/config.h index 45e7642..1841e49 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -34,11 +34,13 @@ namespace gebaar::config { void load_config(); - enum pinches {PINCH_IN, PINCH_OUT, DISTANCE}; + enum pinch {PINCH_IN, PINCH_OUT}; + enum settings {THRESHOLD, DISTANCE}; std::string swipe_three_commands[10]; std::string swipe_four_commands[10]; std::string pinch_commands[10]; + std::string settings[10]; private: bool config_file_exists(); diff --git a/src/io/input.cpp b/src/io/input.cpp index 22f1409..380c374 100644 --- a/src/io/input.cpp +++ b/src/io/input.cpp @@ -43,21 +43,26 @@ bool gebaar::io::Input::initialize_context() return libinput_udev_assign_seat(libinput, "seat0")==0; } - +/** + * Reset swipe event struct to defaults + */ +void gebaar::io::Input::reset_swipe_event() { + gesture_swipe_event = {}; + try { + gesture_swipe_event.threshold = std::stoi(config->settings[config->THRESHOLD]); + } + catch (const std::invalid_argument& ia){ + gesture_swipe_event.threshold = DEFAULT_THRESHOLD; + } +} /** - * Pinch Gesture - * Currently supporting only "one shot" pinch-in and pinch-out gestures. - * @param gev Gesture Event - * @param begin Boolean to denote begin or continuation of gesture. - **/ -void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool begin) -{ - if (begin) { - gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); + * Reset pinch event struct to defaults + */ +void gebaar::io::Input::reset_pinch_event() { // Get pinch distance try { - gesture_pinch_event.distance = std::stod(config->pinch_commands[config->DISTANCE]); + gesture_pinch_event.distance = std::stod(config->settings[config->DISTANCE]); } catch (const std::invalid_argument &ia) { // Set default distance @@ -66,8 +71,24 @@ void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool beg // Reset pinch data gesture_pinch_event.scale = DEFAULT_SCALE; gesture_pinch_event.executed = false; +} + + +/** + * Pinch Gesture + * Currently supporting only "one shot" pinch-in and pinch-out gestures. + * @param gev Gesture Event + * @param begin Boolean to denote begin or continuation of gesture. + **/ +void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool begin) +{ + if (begin) { + reset_pinch_event(); + gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); } else { + if (gesture_swipe_event.executed) return; + // Ignore input after command execution if (gesture_pinch_event.executed) return; double new_scale = libinput_event_gesture_get_scale(gev); @@ -104,41 +125,12 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture if (begin) { gesture_swipe_event.fingers = libinput_event_gesture_get_finger_count(gev); } + // This executed when fingers left the touchpad else { - double x = gesture_swipe_event.x; - double y = gesture_swipe_event.y; - int swipe_type = 5; // middle = no swipe - // 1 = left_up, 2 = up, 3 = right_up... - // 1 2 3 - // 4 5 6 - // 7 8 9 - const double OBLIQUE_RATIO = 0.414; // =~ tan(22.5); - - if (abs(x) > abs(y)) { - // left or right swipe - swipe_type += x < 0 ? -1 : 1; - - // check for oblique swipe - if (abs(y) / abs(x) > OBLIQUE_RATIO) { - swipe_type += y < 0 ? -3 : 3; - } - } else { - // up of down swipe - swipe_type += y < 0 ? -3 : 3; - - // check for oblique swipe - if (abs(x) / abs(y) > OBLIQUE_RATIO) { - swipe_type += x < 0 ? -1 : 1; - } + if (!gesture_swipe_event.executed) { + trigger_swipe_command(); } - - if (gesture_swipe_event.fingers == 3) { - std::system(config->swipe_three_commands[swipe_type].c_str()); - } else if (gesture_swipe_event.fingers == 4) { - std::system(config->swipe_four_commands[swipe_type].c_str()); - } - - gesture_swipe_event = {}; + reset_swipe_event(); } } @@ -148,8 +140,50 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture */ void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* gev) { + if (gesture_swipe_event.executed) return; + int threshold = std::stoi(config->settings[config->THRESHOLD]); gesture_swipe_event.x += libinput_event_gesture_get_dx(gev); gesture_swipe_event.y += libinput_event_gesture_get_dy(gev); + if (abs(gesture_swipe_event.x) > threshold || abs(gesture_swipe_event.y) > threshold) { + trigger_swipe_command(); + gesture_swipe_event.executed = true; + } +} + +void gebaar::io::Input::trigger_swipe_command() { + double x = gesture_swipe_event.x; + double y = gesture_swipe_event.y; + int swipe_type = 5; // middle = no swipe + // 1 = left_up, 2 = up, 3 = right_up... + // 1 2 3 + // 4 5 6 + // 7 8 9 + const double OBLIQUE_RATIO = 0.414; // =~ tan(22.5); + + if (abs(x) > abs(y)) { + // left or right swipe + swipe_type += x < 0 ? -1 : 1; + + // check for oblique swipe + if (abs(y) / abs(x) > OBLIQUE_RATIO) { + swipe_type += y < 0 ? -3 : 3; + } + } else { + // up of down swipe + swipe_type += y < 0 ? -3 : 3; + + // check for oblique swipe + if (abs(x) / abs(y) > OBLIQUE_RATIO) { + swipe_type += x < 0 ? -1 : 1; + } + } + + if (gesture_swipe_event.fingers == 3) { + std::system(config->swipe_three_commands[swipe_type].c_str()); + } else if (gesture_swipe_event.fingers == 4) { + std::system(config->swipe_four_commands[swipe_type].c_str()); + } + } /** diff --git a/src/io/input.h b/src/io/input.h index af52637..e391c0f 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -24,8 +24,9 @@ #include #include "../config/config.h" -#define DEFAULT_SCALE 1.0 -#define DEFAULT_DISTANCE 0.5 +#define DEFAULT_SCALE 1.0 +#define DEFAULT_DISTANCE 0.5 +#define DEFAULT_THRESHOLD 100 namespace gebaar::io { @@ -33,6 +34,9 @@ namespace gebaar::io { int fingers; double x; double y; + + int threshold; + bool executed; }; struct gesture_pinch_event { @@ -85,10 +89,18 @@ namespace gebaar::io { void handle_event(); + /* Swipe event */ + void reset_swipe_event(); + void handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin); void handle_swipe_event_with_coords(libinput_event_gesture* gev); + void trigger_swipe_command(); + + /* Pinch event */ + void reset_pinch_event(); + void handle_pinch_event(libinput_event_gesture* gev, bool begin); }; From 2d57aabd06a612f9df7e825b8758a94d07018ef9 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Thu, 31 Oct 2019 15:58:00 +0200 Subject: [PATCH 03/24] Updated README.md with settings examples --- README.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 741395f..833868f 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,15 @@ right = "" [commands.pinch] in = "" out = "" -distance="" + +[settings] +pinch.distance = "" +swipe.threshold = "" ``` -* `distance` variable in `commands.pinch` sets the distance between fingers where it shold trigger. +* `settings.pinch.distance` key sets the distance between fingers where it shold trigger. Defaults to `0.5` which means fingers should travel exactly half way from their initial position. - +* `settings.swipe.threshold` sets the limit when swipe gesture should be executed. Defaults to 100. ### Repository versions @@ -100,7 +103,10 @@ right = "bspc desktop -f next" [commands.pinch] in = "xdotool key Control_L+equal" out = "xdotool key Control_L+minus" -ditance="0.1" + +[settings] +pinch.ditance="0.5" +swipe.threshold = "100" ``` Add `gebaard -b` to `~/.config/bspwm/bspwmrc` From 3047c04ac36f5836709a795647430db191c22bec Mon Sep 17 00:00:00 2001 From: Alex Kir Date: Thu, 31 Oct 2019 18:05:46 +0200 Subject: [PATCH 04/24] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 833868f..b37208f 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,7 @@ Add `gebaard -b` to `~/.config/bspwm/bspwmrc` ### State of the project - [x] Receiving swipe events from libinput +- [x] Swipe gesture have trigger treshold - [x] Receiving pinch/zoom events from libinput - [ ] Support continous pinch - [ ] Support pinch-and-rotate gestures From 3178dc84a01ee15077e92eda8353d88a4711a137 Mon Sep 17 00:00:00 2001 From: Alex Kir Date: Thu, 31 Oct 2019 18:06:53 +0200 Subject: [PATCH 05/24] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b37208f..b98047a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Gebaar ========= +Forked from Coffee2CodeNL/gebaar-libinput since original repo unmaintained for half a year. WM Independent Touchpad Gesture Daemon for libinput From 5771f0139e8a384823e9dba33439321d774e34ad Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 1 Nov 2019 00:29:13 +0200 Subject: [PATCH 06/24] Unified setting names --- src/config/config.cpp | 4 ++-- src/config/config.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 6292580..0355f58 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -64,8 +64,8 @@ void gebaar::config::Config::load_config() pinch_commands[PINCH_IN] = *config->get_qualified_as("commands.pinch.out"); pinch_commands[PINCH_OUT] = *config->get_qualified_as("commands.pinch.in"); - settings[DISTANCE] = *config->get_qualified_as("settings.pinch.distance"); - settings[THRESHOLD] = *config->get_qualified_as("settings.swipe.threshold"); + settings[PINCH_THRESHOLD] = *config->get_qualified_as("settings.pinch.threshold"); + settings[SWIPE_THRESHOLD] = *config->get_qualified_as("settings.swipe.threshold"); loaded = true; } diff --git a/src/config/config.h b/src/config/config.h index 1841e49..273d05a 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -35,7 +35,7 @@ namespace gebaar::config { enum pinch {PINCH_IN, PINCH_OUT}; - enum settings {THRESHOLD, DISTANCE}; + enum settings {SWIPE_THRESHOLD, PINCH_THRESHOLD}; std::string swipe_three_commands[10]; std::string swipe_four_commands[10]; From 07b0ca898cc99ec9dbcc954fd80d2338a82531b3 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Sun, 3 Nov 2019 14:48:20 +0200 Subject: [PATCH 07/24] Continous pinch and swipe gestres This commit introduces breaking changes due to changes in config file format. Hopefully that's the last time. * Config keys changed format, see readme for examples. * Both swipe and pinch gestures now have `settings.threshold` key which can be values 0.0 - 1.0. Defaults: Swipe: 1.0 Pinch: 0.25 * Both swipe and pinch now have `settings.one_shot` which, if set, allows only one execution of command per gesture. Defaults: Swipe: true Pinch: false * Swipe gesture now has `settings.trigger_on_release` defaulting to false. If set to true the command for swipe will be triggered when fingers are moved from touchpad UNLESS it is also one_shot gesture and gesture was already triggered. --- README.md | 21 +++++---- src/config/config.cpp | 54 ++++++++++++---------- src/config/config.h | 16 +++++-- src/io/input.cpp | 103 +++++++++++++++++++++++++----------------- src/io/input.h | 28 +++++++++--- src/main.cpp | 1 + 6 files changed, 141 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index b98047a..8f5a73a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ swipe.threshold = "" _~/.config/gebaar/gebaard.toml_ ```toml -[commands.swipe.three] +[swipe.commands.three] left_up = "" right_up = "" up = "bspc node -f north" @@ -91,7 +91,7 @@ left = "bspc node -f west" right = "bspc node -f east" -[commands.swipe.four] +[swipe.commands.four] left_up = "" right_up = "" up = "rofi -show combi" @@ -101,13 +101,18 @@ down = "" left = "bspc desktop -f prev" right = "bspc desktop -f next" -[commands.pinch] +[pinch.commands.two] in = "xdotool key Control_L+equal" out = "xdotool key Control_L+minus" -[settings] -pinch.ditance="0.5" -swipe.threshold = "100" +[pinch.settings] +threshold=0.25 +one_shot=false + +[swipe.settings] +threshold = 0.5 +one_shot = true +trigger_on_release = true ``` Add `gebaard -b` to `~/.config/bspwm/bspwmrc` @@ -117,8 +122,8 @@ Add `gebaard -b` to `~/.config/bspwm/bspwmrc` - [x] Receiving swipe events from libinput - [x] Swipe gesture have trigger treshold - [x] Receiving pinch/zoom events from libinput - - [ ] Support continous pinch - - [ ] Support pinch-and-rotate gestures +- [x] Support continous pinch +- [ ] Support pinch-and-rotate gestures - [ ] Receiving rotation events from libinput - [x] Converting libinput events to motions - [x] Running commands based on motions diff --git a/src/config/config.cpp b/src/config/config.cpp index 0355f58..0bbd0cc 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -43,29 +43,37 @@ void gebaar::config::Config::load_config() std::cerr << e.what() << std::endl; exit(EXIT_FAILURE); } - swipe_three_commands[1] = *config->get_qualified_as("commands.swipe.three.left_up"); - swipe_three_commands[2] = *config->get_qualified_as("commands.swipe.three.up"); - swipe_three_commands[3] = *config->get_qualified_as("commands.swipe.three.right_up"); - swipe_three_commands[4] = *config->get_qualified_as("commands.swipe.three.left"); - swipe_three_commands[6] = *config->get_qualified_as("commands.swipe.three.right"); - swipe_three_commands[7] = *config->get_qualified_as("commands.swipe.three.left_down"); - swipe_three_commands[8] = *config->get_qualified_as("commands.swipe.three.down"); - swipe_three_commands[9] = *config->get_qualified_as("commands.swipe.three.right_down"); - - swipe_four_commands[1] = *config->get_qualified_as("commands.swipe.four.left_up"); - swipe_four_commands[2] = *config->get_qualified_as("commands.swipe.four.up"); - swipe_four_commands[3] = *config->get_qualified_as("commands.swipe.four.right_up"); - swipe_four_commands[4] = *config->get_qualified_as("commands.swipe.four.left"); - swipe_four_commands[6] = *config->get_qualified_as("commands.swipe.four.right"); - swipe_four_commands[7] = *config->get_qualified_as("commands.swipe.four.left_down"); - swipe_four_commands[8] = *config->get_qualified_as("commands.swipe.four.down"); - swipe_four_commands[9] = *config->get_qualified_as("commands.swipe.four.right_down"); - - pinch_commands[PINCH_IN] = *config->get_qualified_as("commands.pinch.out"); - pinch_commands[PINCH_OUT] = *config->get_qualified_as("commands.pinch.in"); - - settings[PINCH_THRESHOLD] = *config->get_qualified_as("settings.pinch.threshold"); - settings[SWIPE_THRESHOLD] = *config->get_qualified_as("settings.swipe.threshold"); + + /* Swipe Settings */ + swipe_three_commands[1] = *config->get_qualified_as("swipe.commands.three.left_up"); + swipe_three_commands[2] = *config->get_qualified_as("swipe.commands.three.up"); + swipe_three_commands[3] = *config->get_qualified_as("swipe.commands.three.right_up"); + swipe_three_commands[4] = *config->get_qualified_as("swipe.commands.three.left"); + swipe_three_commands[6] = *config->get_qualified_as("swipe.commands.three.right"); + swipe_three_commands[7] = *config->get_qualified_as("swipe.commands.three.left_down"); + swipe_three_commands[8] = *config->get_qualified_as("swipe.commands.three.down"); + swipe_three_commands[9] = *config->get_qualified_as("swipe.commands.three.right_down"); + + swipe_four_commands[1] = *config->get_qualified_as("swipe.commands.four.left_up"); + swipe_four_commands[2] = *config->get_qualified_as("swipe.commands.four.up"); + swipe_four_commands[3] = *config->get_qualified_as("swipe.commands.four.right_up"); + swipe_four_commands[4] = *config->get_qualified_as("swipe.commands.four.left"); + swipe_four_commands[6] = *config->get_qualified_as("swipe.commands.four.right"); + swipe_four_commands[7] = *config->get_qualified_as("swipe.commands.four.left_down"); + swipe_four_commands[8] = *config->get_qualified_as("swipe.commands.four.down"); + swipe_four_commands[9] = *config->get_qualified_as("swipe.commands.four.right_down"); + + settings.swipe_threshold = config->get_qualified_as("swipe.settings.threshold").value_or(0.5); + settings.swipe_one_shot = config->get_qualified_as("swipe.settings.one_shot").value_or(true); + settings.swipe_trigger_on_release = config->get_qualified_as("swipe.settings.trigger_on_release").value_or(true); + + /* Pinch settings */ + pinch_commands[PINCH_IN] = *config->get_qualified_as("pinch.commands.two.out"); + pinch_commands[PINCH_OUT] = *config->get_qualified_as("pinch.commands.two.in"); + + settings.pinch_threshold = config->get_qualified_as("pinch.settings.threshold").value_or(0.25); + settings.pinch_one_shot = config->get_qualified_as("pinch.settings.one_shot").value_or(false); + loaded = true; } diff --git a/src/config/config.h b/src/config/config.h index 273d05a..34d7a42 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -34,21 +34,31 @@ namespace gebaar::config { void load_config(); - enum pinch {PINCH_IN, PINCH_OUT}; - enum settings {SWIPE_THRESHOLD, PINCH_THRESHOLD}; + struct settings { + bool pinch_one_shot; + double pinch_threshold; + + bool swipe_one_shot; + double swipe_threshold; + bool swipe_trigger_on_release; + } settings; + enum pinch {PINCH_IN, PINCH_OUT}; std::string swipe_three_commands[10]; std::string swipe_four_commands[10]; std::string pinch_commands[10]; - std::string settings[10]; private: + bool config_file_exists(); bool find_config_file(); + std::string config_file_path; std::shared_ptr config; + + }; } #endif //GEBAAR_CONFIG_H diff --git a/src/io/input.cpp b/src/io/input.cpp index 380c374..4c95cf4 100644 --- a/src/io/input.cpp +++ b/src/io/input.cpp @@ -28,7 +28,9 @@ gebaar::io::Input::Input(std::shared_ptr const& config_p { config = config_ptr; gesture_swipe_event = {}; + gesture_pinch_event = {}; + gesture_pinch_event.scale = DEFAULT_SCALE; } /** @@ -48,31 +50,60 @@ bool gebaar::io::Input::initialize_context() */ void gebaar::io::Input::reset_swipe_event() { gesture_swipe_event = {}; - try { - gesture_swipe_event.threshold = std::stoi(config->settings[config->THRESHOLD]); - } - catch (const std::invalid_argument& ia){ - gesture_swipe_event.threshold = DEFAULT_THRESHOLD; - } + gesture_swipe_event.executed = false; } /** * Reset pinch event struct to defaults */ void gebaar::io::Input::reset_pinch_event() { - // Get pinch distance - try { - gesture_pinch_event.distance = std::stod(config->settings[config->DISTANCE]); + gesture_pinch_event = {}; + gesture_pinch_event.scale = DEFAULT_SCALE; + gesture_pinch_event.executed = false; +} + +/** + * Pinch one_shot gesture handle + * @param new_scale last reported scale between the fingers + */ +void gebaar::io::Input::handle_one_shot_pinch(double new_scale) { + if (new_scale > gesture_pinch_event.scale) { // Scale up + // Add 1 to required distance to get 2 > x > 1 + if (new_scale > 1 + config->settings.pinch_threshold) { + std::system(config->pinch_commands[config->PINCH_IN].c_str()); + gesture_pinch_event.executed = true; } - catch (const std::invalid_argument &ia) { - // Set default distance - gesture_pinch_event.distance = DEFAULT_DISTANCE; + } + else { // Scale Down + // Substract from 1 to have inverted value for pinch in gesture + if (gesture_pinch_event.scale < 1 - config->settings.pinch_threshold) { + std::system(config->pinch_commands[config->PINCH_OUT].c_str()); + gesture_pinch_event.executed = true; } - // Reset pinch data - gesture_pinch_event.scale = DEFAULT_SCALE; - gesture_pinch_event.executed = false; + } } +/** + * Pinch continous gesture handle + * Calculates the trigger value according to current step + * @param new_scale last reported scale between the fingers + */ +void gebaar::io::Input::handle_continouos_pinch(double new_scale) { + int step = gesture_pinch_event.step == 0 ? gesture_pinch_event.step + 1 : gesture_pinch_event.step; + double trigger = 1 + (config->settings.pinch_threshold * step); + + if (new_scale > gesture_pinch_event.scale) { // Scale up + if (new_scale >= trigger){ + std::system(config->pinch_commands[config->PINCH_IN].c_str()); + inc_step(gesture_pinch_event.step); + } + } else { // Scale down + if (new_scale <= trigger){ + std::system(config->pinch_commands[config->PINCH_OUT].c_str()); + dec_step(gesture_pinch_event.step); + } + } +} /** * Pinch Gesture @@ -83,31 +114,13 @@ void gebaar::io::Input::reset_pinch_event() { void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool begin) { if (begin) { - reset_pinch_event(); - gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); + reset_pinch_event(); + gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); } else { - if (gesture_swipe_event.executed) return; - - // Ignore input after command execution - if (gesture_pinch_event.executed) return; double new_scale = libinput_event_gesture_get_scale(gev); - if (new_scale > gesture_pinch_event.scale) { - // Scale up - // Add 1 to required distance to get 2 > x > 1 - if (new_scale > 1 + gesture_pinch_event.distance) { - std::system(config->pinch_commands[config->PINCH_IN].c_str()); - gesture_pinch_event.executed = true; - } - } - else { - // Scale Down - // Substract from 1 to have inverted value for pinch in gesture - if (gesture_pinch_event.scale < 1 - gesture_pinch_event.distance) { - std::system(config->pinch_commands[config->PINCH_OUT].c_str()); - gesture_pinch_event.executed = true; - } - } + if (config->settings.pinch_one_shot && !gesture_pinch_event.executed) handle_one_shot_pinch(new_scale); + if (!config->settings.pinch_one_shot) handle_continouos_pinch(new_scale); gesture_pinch_event.scale = new_scale; } } @@ -127,7 +140,7 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture } // This executed when fingers left the touchpad else { - if (!gesture_swipe_event.executed) { + if (!gesture_swipe_event.executed && config->settings.swipe_trigger_on_release) { trigger_swipe_command(); } reset_swipe_event(); @@ -140,8 +153,10 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture */ void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* gev) { - if (gesture_swipe_event.executed) return; - int threshold = std::stoi(config->settings[config->THRESHOLD]); + if (config->settings.swipe_one_shot && gesture_swipe_event.executed) return; + + // Since swipe gesture counts in dpi we have to convert + int threshold = config->settings.swipe_threshold * 100; gesture_swipe_event.x += libinput_event_gesture_get_dx(gev); gesture_swipe_event.y += libinput_event_gesture_get_dy(gev); if (abs(gesture_swipe_event.x) > threshold || abs(gesture_swipe_event.y) > threshold) { @@ -150,6 +165,11 @@ void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* g } } + +/** + * Making calculation for swipe direction and triggering + * command accordingly + */ void gebaar::io::Input::trigger_swipe_command() { double x = gesture_swipe_event.x; double y = gesture_swipe_event.y; @@ -223,7 +243,8 @@ gebaar::io::Input::~Input() bool gebaar::io::Input::gesture_device_exists() { bool device_found = false; - while ((libinput_event = libinput_get_event(libinput))!=nullptr) { + + while ((libinput_event = libinput_get_event(libinput)) != nullptr) { auto device = libinput_event_get_device(libinput_event); if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) { device_found = true; diff --git a/src/io/input.h b/src/io/input.h index e391c0f..17eacd1 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -24,10 +24,7 @@ #include #include "../config/config.h" -#define DEFAULT_SCALE 1.0 -#define DEFAULT_DISTANCE 0.5 -#define DEFAULT_THRESHOLD 100 - +#define DEFAULT_SCALE 1.0 namespace gebaar::io { struct gesture_swipe_event { @@ -35,8 +32,8 @@ namespace gebaar::io { double x; double y; - int threshold; bool executed; + int step; }; struct gesture_pinch_event { @@ -44,8 +41,8 @@ namespace gebaar::io { double scale; double angle; - double distance; bool executed; + int step; }; class Input { @@ -64,6 +61,7 @@ namespace gebaar::io { struct libinput* libinput; struct libinput_event* libinput_event; struct udev* udev; + struct gesture_swipe_event gesture_swipe_event; struct gesture_pinch_event gesture_pinch_event; @@ -74,7 +72,7 @@ namespace gebaar::io { static int open_restricted(const char* path, int flags, void* user_data) { int fd = open(path, flags); - return fd<0 ? -errno : fd; + return fd < 0 ? -errno : fd; } static void close_restricted(int fd, void* user_data) @@ -87,6 +85,18 @@ namespace gebaar::io { .close_restricted = close_restricted, }; + /* + * Decrements step of current trigger. Just to skip 0 + * @param cur current step + */ + inline void dec_step(int &cur) { --cur == 0 ? --cur : cur; } + + /* + * Increase step of current trigger. Just to pass -1 + * @param cur current step + */ + inline void inc_step(int &cur) { ++cur == 0 ? ++cur : cur; } + void handle_event(); /* Swipe event */ @@ -101,6 +111,10 @@ namespace gebaar::io { /* Pinch event */ void reset_pinch_event(); + void handle_one_shot_pinch(double new_scale); + + void handle_continouos_pinch(double new_scale); + void handle_pinch_event(libinput_event_gesture* gev, bool begin); }; diff --git a/src/main.cpp b/src/main.cpp index 9a61700..982ce3d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,6 +48,7 @@ int main(int argc, char* argv[]) } std::shared_ptr config = std::make_shared(); input = new gebaar::io::Input(config); + if (input->initialize()) { input->start_loop(); } From 78f5881eb7f41ab9521f50bebfa707f6a869b051 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 12:07:30 +0200 Subject: [PATCH 08/24] added ccls-cache, kdev4 and clangd to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index fda7434..a747486 100644 --- a/.gitignore +++ b/.gitignore @@ -195,3 +195,7 @@ fabric.properties # Editor-based Rest Client .idea/httpRequests +# LSP stuff +.ccls* +.clangd + From d8d48535e4b0a5be2a2107157289d7af3a387a72 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 12:08:51 +0200 Subject: [PATCH 09/24] Added archlinux PKGBUILD --- PKGBUILD | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..d768f39 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,42 @@ +# Maintainer: Will Vauclain +# Maintainer: Alex Zaslavsky +pkgname=gebaar-libinput-git +pkgver=r47.07b0ca8 +pkgrel=1 +pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput. Forked version with new features' +arch=('x86_64') +url="https://github.com/Osleg/gebaar-libinput" +license=('GPL3') +depends=('libinput') +makedepends=('cmake' 'git') +conflicts=('gebaar') +provides=('gebaar') +source=('git+https://github.com/Osleg/gebaar-libinput') +md5sums=('SKIP') + + +pkgver() { + cd "$srcdir/gebaar-libinput" + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +prepare() { + cd $srcdir/gebaar-libinput + git submodule init + git submodule update + mkdir -p build && cd build + cmake -DCMAKE_INSTALL_PREFIX="/usr" .. +} + +build() { + cd $srcdir/gebaar-libinput/build + make -j$(nproc) +} + +package() { + cd $srcdir/gebaar-libinput/build + make DESTDIR="$pkgdir" install/strip + cd .. + install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" + install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md" +} From b5c05d6dc4c8dbb77c5f6738c3e60e4c564ab3e0 Mon Sep 17 00:00:00 2001 From: Alex Kir Date: Wed, 6 Nov 2019 12:38:17 +0200 Subject: [PATCH 10/24] Travis CI + SystemD (#3) * Travis CI * Add systemd unit --- .travis.yml | 21 +++++++++++++++++++ .../gebaar-libinput.desktop | 0 assets/gebaard.service | 10 +++++++++ build.Dockerfile | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 .travis.yml rename gebaar-libinput.desktop => assets/gebaar-libinput.desktop (100%) create mode 100644 assets/gebaard.service create mode 100644 build.Dockerfile diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..216d636 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: c +compiler: gcc +os: linux +dist: xenial + +before_install: + - docker build -t builder -f build.Dockerfile . + +script: + - docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir -w /workdir -it builder cmake . + - docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir -w /workdir -it builder make + +deploy: + provider: releases + file: "gebaard" + skip_cleanup: true + on: + repo: Coffee2CodeNL/gebaar-libinput + tags: true + api_key: + secure: "" diff --git a/gebaar-libinput.desktop b/assets/gebaar-libinput.desktop similarity index 100% rename from gebaar-libinput.desktop rename to assets/gebaar-libinput.desktop diff --git a/assets/gebaard.service b/assets/gebaard.service new file mode 100644 index 0000000..b953f29 --- /dev/null +++ b/assets/gebaard.service @@ -0,0 +1,10 @@ +[Unit] +Description=Gebaar Daemon +Documentation=https://github.com/Coffee2CodeNL/gebaar-libinput + +[Service] +ExecStart=/usr/local/bin/gebaard +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/build.Dockerfile b/build.Dockerfile new file mode 100644 index 0000000..84a1a27 --- /dev/null +++ b/build.Dockerfile @@ -0,0 +1,7 @@ +FROM debian:stretch + +RUN set -ex; \ + echo 'deb http://http.us.debian.org/debian/ testing non-free contrib main' > /etc/apt/sources.list.d/debian-testing.list; \ + apt-get update -q; \ + apt-get install -y git gcc-8 curl make cmake build-essential libinput-dev zlib1g-dev libinput-tools libsystemd-dev + From 14f3e72e609218ddf283ef967ba03d2022172587 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 12:42:13 +0200 Subject: [PATCH 11/24] Changed repo target for travis --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 216d636..b6b4e0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,5 @@ deploy: file: "gebaard" skip_cleanup: true on: - repo: Coffee2CodeNL/gebaar-libinput + repo: Osleg/gebaar-libinput tags: true - api_key: - secure: "" From b86877013028c5e40f4faaaeef93bc3f05757737 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 12:46:34 +0200 Subject: [PATCH 12/24] fixed travis repo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b6b4e0a..bb4e1fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,5 +15,5 @@ deploy: file: "gebaard" skip_cleanup: true on: - repo: Osleg/gebaar-libinput + repo: osleg/gebaar-libinput tags: true From 945d3c9c41fd76495641de5fab639af27918e3da Mon Sep 17 00:00:00 2001 From: Alex Kir Date: Wed, 6 Nov 2019 13:06:13 +0200 Subject: [PATCH 13/24] Update README.md Added travis CI Badge --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f5a73a..44b9284 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ + +[![Build Status](https://travis-ci.org/osleg/gebaar-libinput.svg?branch=master)](https://travis-ci.org/osleg/gebaar-libinput) + Gebaar ========= -Forked from Coffee2CodeNL/gebaar-libinput since original repo unmaintained for half a year. +Forked from Coffee2CodeNL/gebaar-libinput since original repo unmaintained for half a year, yet this is NOT OFFICIAL repo! WM Independent Touchpad Gesture Daemon for libinput From 9bbccfff971aea893f1664fa81911d49c0a61ec7 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 13:08:43 +0200 Subject: [PATCH 14/24] Added deploy release to travis --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb4e1fc..537d248 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,18 +2,18 @@ language: c compiler: gcc os: linux dist: xenial - before_install: - - docker build -t builder -f build.Dockerfile . - +- docker build -t builder -f build.Dockerfile . script: - - docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir -w /workdir -it builder cmake . - - docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir -w /workdir -it builder make - +- docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir + -w /workdir -it builder cmake . +- docker run --rm --device /dev/input -v /run/udev/data:/run/udev/data -v $(pwd):/workdir + -w /workdir -it builder make deploy: provider: releases - file: "gebaard" - skip_cleanup: true + api_key: + secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= + file: gebaard on: repo: osleg/gebaar-libinput tags: true From e59c0e89a44d7bdc73c6f20d2af4d4ce876deeaa Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 6 Nov 2019 13:43:41 +0200 Subject: [PATCH 15/24] Trying to fix travis --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 537d248..e56aa06 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,10 @@ script: -w /workdir -it builder make deploy: provider: releases - api_key: - secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= - file: gebaard + file: "gebaard" + skip_cleanup: true on: repo: osleg/gebaar-libinput tags: true + api_key: + secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= From 8020ee4a03c531cec31c7452ebc0214101e24f02 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Thu, 7 Nov 2019 19:41:28 +0200 Subject: [PATCH 16/24] Updated README.md with correct config keys Config keys changed from original upstream. Updated README showing correct keys and correct default values --- README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 44b9284..dc07fe7 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Click to join: [![Discord](https://img.shields.io/discord/548978799136473106.svg 14. Reboot and see the magic ```toml -[commands.swipe.three] +[swipe.commands.three] left_up = "" right_up = "" up = "" @@ -50,7 +50,7 @@ down = "" left = "" right = "" -[commands.swipe.four] +[swipe.commands.four] left_up = "" right_up = "" up = "" @@ -60,18 +60,24 @@ down = "" left = "" right = "" -[commands.pinch] +[pinch.commands] in = "" out = "" -[settings] -pinch.distance = "" -swipe.threshold = "" +[pinch.settings] +threshold = 0.25 +one_shot = false + + +[swipe.settings] +threshold = 0.5 +one_shot = true +trigger_on_release = false ``` -* `settings.pinch.distance` key sets the distance between fingers where it shold trigger. - Defaults to `0.5` which means fingers should travel exactly half way from their initial position. -* `settings.swipe.threshold` sets the limit when swipe gesture should be executed. Defaults to 100. +* `pinch.settings.threshold` key sets the distance between fingers where it shold trigger. + Defaults to `0.25` which means fingers should travel exactly 25% distance from their initial position. +* `swipe.settings.threshold` sets the limit when swipe gesture should be executed. Defaults to 0.5. ### Repository versions @@ -115,7 +121,7 @@ one_shot=false [swipe.settings] threshold = 0.5 one_shot = true -trigger_on_release = true +trigger_on_release = false ``` Add `gebaard -b` to `~/.config/bspwm/bspwmrc` From 068a4c0ff9bccca3120580d535720cf513603862 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Mon, 25 Nov 2019 14:19:53 +0200 Subject: [PATCH 17/24] Fixing continous swipe bug In continous swipe implementation triggering threshold was calculated incorrectly leading to triggering execution of the command indefinetly as soo as it triggered once. This should close #5 --- src/io/input.cpp | 409 ++++++++++++++++++++++++----------------------- src/io/input.h | 2 + 2 files changed, 208 insertions(+), 203 deletions(-) diff --git a/src/io/input.cpp b/src/io/input.cpp index 4c95cf4..415fdab 100644 --- a/src/io/input.cpp +++ b/src/io/input.cpp @@ -16,21 +16,22 @@ along with this program. If not, see . */ -#include #include "input.h" +#include /** - * Input system constructor, we pass our Configuration object via a shared pointer + * Input system constructor, we pass our Configuration object via a shared + * pointer * * @param config_ptr shared pointer to configuration object */ -gebaar::io::Input::Input(std::shared_ptr const& config_ptr) -{ - config = config_ptr; - gesture_swipe_event = {}; +gebaar::io::Input::Input( + std::shared_ptr const &config_ptr) { + config = config_ptr; + gesture_swipe_event = {}; - gesture_pinch_event = {}; - gesture_pinch_event.scale = DEFAULT_SCALE; + gesture_pinch_event = {}; + gesture_pinch_event.scale = DEFAULT_SCALE; } /** @@ -38,28 +39,27 @@ gebaar::io::Input::Input(std::shared_ptr const& config_p * * @return bool */ -bool gebaar::io::Input::initialize_context() -{ - udev = udev_new(); - libinput = libinput_udev_create_context(&libinput_interface, nullptr, udev); - return libinput_udev_assign_seat(libinput, "seat0")==0; +bool gebaar::io::Input::initialize_context() { + udev = udev_new(); + libinput = libinput_udev_create_context(&libinput_interface, nullptr, udev); + return libinput_udev_assign_seat(libinput, "seat0") == 0; } /** * Reset swipe event struct to defaults */ void gebaar::io::Input::reset_swipe_event() { - gesture_swipe_event = {}; - gesture_swipe_event.executed = false; + gesture_swipe_event = {}; + gesture_swipe_event.executed = false; } /** * Reset pinch event struct to defaults */ void gebaar::io::Input::reset_pinch_event() { - gesture_pinch_event = {}; - gesture_pinch_event.scale = DEFAULT_SCALE; - gesture_pinch_event.executed = false; + gesture_pinch_event = {}; + gesture_pinch_event.scale = DEFAULT_SCALE; + gesture_pinch_event.executed = false; } /** @@ -67,20 +67,19 @@ void gebaar::io::Input::reset_pinch_event() { * @param new_scale last reported scale between the fingers */ void gebaar::io::Input::handle_one_shot_pinch(double new_scale) { - if (new_scale > gesture_pinch_event.scale) { // Scale up - // Add 1 to required distance to get 2 > x > 1 - if (new_scale > 1 + config->settings.pinch_threshold) { - std::system(config->pinch_commands[config->PINCH_IN].c_str()); - gesture_pinch_event.executed = true; - } + if (new_scale > gesture_pinch_event.scale) { // Scale up + // Add 1 to required distance to get 2 > x > 1 + if (new_scale > 1 + config->settings.pinch_threshold) { + std::system(config->pinch_commands[config->PINCH_IN].c_str()); + gesture_pinch_event.executed = true; } - else { // Scale Down - // Substract from 1 to have inverted value for pinch in gesture - if (gesture_pinch_event.scale < 1 - config->settings.pinch_threshold) { - std::system(config->pinch_commands[config->PINCH_OUT].c_str()); - gesture_pinch_event.executed = true; - } + } else { // Scale Down + // Substract from 1 to have inverted value for pinch in gesture + if (gesture_pinch_event.scale < 1 - config->settings.pinch_threshold) { + std::system(config->pinch_commands[config->PINCH_OUT].c_str()); + gesture_pinch_event.executed = true; } + } } /** @@ -89,20 +88,21 @@ void gebaar::io::Input::handle_one_shot_pinch(double new_scale) { * @param new_scale last reported scale between the fingers */ void gebaar::io::Input::handle_continouos_pinch(double new_scale) { - int step = gesture_pinch_event.step == 0 ? gesture_pinch_event.step + 1 : gesture_pinch_event.step; - double trigger = 1 + (config->settings.pinch_threshold * step); - - if (new_scale > gesture_pinch_event.scale) { // Scale up - if (new_scale >= trigger){ - std::system(config->pinch_commands[config->PINCH_IN].c_str()); - inc_step(gesture_pinch_event.step); - } - } else { // Scale down - if (new_scale <= trigger){ - std::system(config->pinch_commands[config->PINCH_OUT].c_str()); - dec_step(gesture_pinch_event.step); - } + int step = gesture_pinch_event.step == 0 ? gesture_pinch_event.step + 1 + : gesture_pinch_event.step; + double trigger = 1 + (config->settings.pinch_threshold * step); + + if (new_scale > gesture_pinch_event.scale) { // Scale up + if (new_scale >= trigger) { + std::system(config->pinch_commands[config->PINCH_IN].c_str()); + inc_step(gesture_pinch_event.step); + } + } else { // Scale down + if (new_scale <= trigger) { + std::system(config->pinch_commands[config->PINCH_OUT].c_str()); + dec_step(gesture_pinch_event.step); } + } } /** @@ -111,61 +111,68 @@ void gebaar::io::Input::handle_continouos_pinch(double new_scale) { * @param gev Gesture Event * @param begin Boolean to denote begin or continuation of gesture. **/ -void gebaar::io::Input::handle_pinch_event(libinput_event_gesture* gev, bool begin) -{ - if (begin) { - reset_pinch_event(); - gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); - } - else { - double new_scale = libinput_event_gesture_get_scale(gev); - if (config->settings.pinch_one_shot && !gesture_pinch_event.executed) handle_one_shot_pinch(new_scale); - if (!config->settings.pinch_one_shot) handle_continouos_pinch(new_scale); - gesture_pinch_event.scale = new_scale; - } +void gebaar::io::Input::handle_pinch_event(libinput_event_gesture *gev, + bool begin) { + if (begin) { + reset_pinch_event(); + gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count(gev); + } else { + double new_scale = libinput_event_gesture_get_scale(gev); + if (config->settings.pinch_one_shot && !gesture_pinch_event.executed) + handle_one_shot_pinch(new_scale); + if (!config->settings.pinch_one_shot) + handle_continouos_pinch(new_scale); + gesture_pinch_event.scale = new_scale; + } } /** - * This event has no coordinates, so it's an event that gives us a begin or end signal. - * If it begins, we get the amount of fingers used. - * If it ends, we check what kind of gesture we received. + * This event has no coordinates, so it's an event that gives us a begin or end + * signal. If it begins, we get the amount of fingers used. If it ends, we check + * what kind of gesture we received. * * @param gev Gesture Event * @param begin Boolean to denote begin or end of gesture */ -void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin) -{ - if (begin) { - gesture_swipe_event.fingers = libinput_event_gesture_get_finger_count(gev); - } - // This executed when fingers left the touchpad - else { - if (!gesture_swipe_event.executed && config->settings.swipe_trigger_on_release) { - trigger_swipe_command(); - } - reset_swipe_event(); +void gebaar::io::Input::handle_swipe_event_without_coords( + libinput_event_gesture *gev, bool begin) { + if (begin) { + gesture_swipe_event.fingers = libinput_event_gesture_get_finger_count(gev); + } + // This executed when fingers left the touchpad + else { + if (!gesture_swipe_event.executed && + config->settings.swipe_trigger_on_release) { + trigger_swipe_command(); } + reset_swipe_event(); + } } /** * Swipe events with coordinates, add it to the current tally * @param gev Gesture Event */ -void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* gev) -{ - if (config->settings.swipe_one_shot && gesture_swipe_event.executed) return; - - // Since swipe gesture counts in dpi we have to convert - int threshold = config->settings.swipe_threshold * 100; - gesture_swipe_event.x += libinput_event_gesture_get_dx(gev); - gesture_swipe_event.y += libinput_event_gesture_get_dy(gev); - if (abs(gesture_swipe_event.x) > threshold || abs(gesture_swipe_event.y) > threshold) { - trigger_swipe_command(); - gesture_swipe_event.executed = true; - } +void gebaar::io::Input::handle_swipe_event_with_coords( + libinput_event_gesture *gev) { + if (config->settings.swipe_one_shot && gesture_swipe_event.executed) + return; + + // Since swipe gesture counts in dpi we have to convert + int threshold_x = config->settings.swipe_threshold * SWIPE_X_THRESHOLD * + gesture_swipe_event.step; + int threshold_y = config->settings.swipe_threshold * SWIPE_Y_THRESHOLD * + gesture_swipe_event.step; + gesture_swipe_event.x += libinput_event_gesture_get_dx_unaccelerated(gev); + gesture_swipe_event.y += libinput_event_gesture_get_dy_unaccelerated(gev); + if (abs(gesture_swipe_event.x) > threshold_x || + abs(gesture_swipe_event.y) > threshold_y) { + trigger_swipe_command(); + gesture_swipe_event.executed = true; + inc_step(gesture_swipe_event.step); + } } - /** * Making calculation for swipe direction and triggering * command accordingly @@ -173,162 +180,158 @@ void gebaar::io::Input::handle_swipe_event_with_coords(libinput_event_gesture* g void gebaar::io::Input::trigger_swipe_command() { double x = gesture_swipe_event.x; double y = gesture_swipe_event.y; - int swipe_type = 5; // middle = no swipe - // 1 = left_up, 2 = up, 3 = right_up... - // 1 2 3 - // 4 5 6 - // 7 8 9 + int swipe_type = 5; // middle = no swipe + // 1 = left_up, 2 = up, 3 = right_up... + // 1 2 3 + // 4 5 6 + // 7 8 9 const double OBLIQUE_RATIO = 0.414; // =~ tan(22.5); if (abs(x) > abs(y)) { - // left or right swipe - swipe_type += x < 0 ? -1 : 1; + // left or right swipe + swipe_type += x < 0 ? -1 : 1; - // check for oblique swipe - if (abs(y) / abs(x) > OBLIQUE_RATIO) { - swipe_type += y < 0 ? -3 : 3; - } - } else { - // up of down swipe + // check for oblique swipe + if (abs(y) / abs(x) > OBLIQUE_RATIO) { swipe_type += y < 0 ? -3 : 3; + } + } else { + // up of down swipe + swipe_type += y < 0 ? -3 : 3; - // check for oblique swipe - if (abs(x) / abs(y) > OBLIQUE_RATIO) { - swipe_type += x < 0 ? -1 : 1; - } + // check for oblique swipe + if (abs(x) / abs(y) > OBLIQUE_RATIO) { + swipe_type += x < 0 ? -1 : 1; + } } if (gesture_swipe_event.fingers == 3) { - std::system(config->swipe_three_commands[swipe_type].c_str()); + std::system(config->swipe_three_commands[swipe_type].c_str()); } else if (gesture_swipe_event.fingers == 4) { - std::system(config->swipe_four_commands[swipe_type].c_str()); + std::system(config->swipe_four_commands[swipe_type].c_str()); } - } /** * Initialize the input system * @return bool */ -bool gebaar::io::Input::initialize() -{ - initialize_context(); - return gesture_device_exists(); +bool gebaar::io::Input::initialize() { + initialize_context(); + return gesture_device_exists(); } /** * Run a poll loop on the file descriptor that libinput gives us */ -void gebaar::io::Input::start_loop() -{ - struct pollfd fds{}; - fds.fd = libinput_get_fd(libinput); - fds.events = POLLIN; - fds.revents = 0; - - while (poll(&fds, 1, -1)>-1) { - handle_event(); - } +void gebaar::io::Input::start_loop() { + struct pollfd fds {}; + fds.fd = libinput_get_fd(libinput); + fds.events = POLLIN; + fds.revents = 0; + + while (poll(&fds, 1, -1) > -1) { + handle_event(); + } } -gebaar::io::Input::~Input() -{ - libinput_unref(libinput); -} +gebaar::io::Input::~Input() { libinput_unref(libinput); } /** * Check if there's a device that supports gestures on this system * @return */ -bool gebaar::io::Input::gesture_device_exists() -{ - bool device_found = false; +bool gebaar::io::Input::gesture_device_exists() { + bool device_found = false; - while ((libinput_event = libinput_get_event(libinput)) != nullptr) { - auto device = libinput_event_get_device(libinput_event); - if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) { - device_found = true; - } - - libinput_event_destroy(libinput_event); - libinput_dispatch(libinput); + while ((libinput_event = libinput_get_event(libinput)) != nullptr) { + auto device = libinput_event_get_device(libinput_event); + if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE)) { + device_found = true; } - return device_found; + + libinput_event_destroy(libinput_event); + libinput_dispatch(libinput); + } + return device_found; } /** * Handle an event from libinput and run the appropriate action per event type */ -void gebaar::io::Input::handle_event() -{ - libinput_dispatch(libinput); - while ((libinput_event = libinput_get_event(libinput))) { - switch (libinput_event_get_type(libinput_event)) { - case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: - handle_swipe_event_without_coords(libinput_event_get_gesture_event(libinput_event), true); - break; - case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: - handle_swipe_event_with_coords(libinput_event_get_gesture_event(libinput_event)); - break; - case LIBINPUT_EVENT_GESTURE_SWIPE_END: - handle_swipe_event_without_coords(libinput_event_get_gesture_event(libinput_event), false); - break; - case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: - handle_pinch_event(libinput_event_get_gesture_event(libinput_event), true); - break; - case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: - handle_pinch_event(libinput_event_get_gesture_event(libinput_event), false); - break; - case LIBINPUT_EVENT_GESTURE_PINCH_END: - handle_pinch_event(libinput_event_get_gesture_event(libinput_event), false); - break; - case LIBINPUT_EVENT_NONE: - break; - case LIBINPUT_EVENT_DEVICE_ADDED: - break; - case LIBINPUT_EVENT_DEVICE_REMOVED: - break; - case LIBINPUT_EVENT_KEYBOARD_KEY: - break; - case LIBINPUT_EVENT_POINTER_MOTION: - break; - case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: - break; - case LIBINPUT_EVENT_POINTER_BUTTON: - break; - case LIBINPUT_EVENT_POINTER_AXIS: - break; - case LIBINPUT_EVENT_TOUCH_DOWN: - break; - case LIBINPUT_EVENT_TOUCH_UP: - break; - case LIBINPUT_EVENT_TOUCH_MOTION: - break; - case LIBINPUT_EVENT_TOUCH_CANCEL: - break; - case LIBINPUT_EVENT_TOUCH_FRAME: - break; - case LIBINPUT_EVENT_TABLET_TOOL_AXIS: - break; - case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: - break; - case LIBINPUT_EVENT_TABLET_TOOL_TIP: - break; - case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: - break; - case LIBINPUT_EVENT_TABLET_PAD_BUTTON: - break; - case LIBINPUT_EVENT_TABLET_PAD_RING: - break; - case LIBINPUT_EVENT_TABLET_PAD_STRIP: - break; - case LIBINPUT_EVENT_SWITCH_TOGGLE: - break; - } - - libinput_event_destroy(libinput_event); - libinput_dispatch(libinput); +void gebaar::io::Input::handle_event() { + libinput_dispatch(libinput); + while ((libinput_event = libinput_get_event(libinput))) { + switch (libinput_event_get_type(libinput_event)) { + case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN: + handle_swipe_event_without_coords( + libinput_event_get_gesture_event(libinput_event), true); + break; + case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE: + handle_swipe_event_with_coords( + libinput_event_get_gesture_event(libinput_event)); + break; + case LIBINPUT_EVENT_GESTURE_SWIPE_END: + handle_swipe_event_without_coords( + libinput_event_get_gesture_event(libinput_event), false); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_BEGIN: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), + true); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), + false); + break; + case LIBINPUT_EVENT_GESTURE_PINCH_END: + handle_pinch_event(libinput_event_get_gesture_event(libinput_event), + false); + break; + case LIBINPUT_EVENT_NONE: + break; + case LIBINPUT_EVENT_DEVICE_ADDED: + break; + case LIBINPUT_EVENT_DEVICE_REMOVED: + break; + case LIBINPUT_EVENT_KEYBOARD_KEY: + break; + case LIBINPUT_EVENT_POINTER_MOTION: + break; + case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: + break; + case LIBINPUT_EVENT_POINTER_BUTTON: + break; + case LIBINPUT_EVENT_POINTER_AXIS: + break; + case LIBINPUT_EVENT_TOUCH_DOWN: + break; + case LIBINPUT_EVENT_TOUCH_UP: + break; + case LIBINPUT_EVENT_TOUCH_MOTION: + break; + case LIBINPUT_EVENT_TOUCH_CANCEL: + break; + case LIBINPUT_EVENT_TOUCH_FRAME: + break; + case LIBINPUT_EVENT_TABLET_TOOL_AXIS: + break; + case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY: + break; + case LIBINPUT_EVENT_TABLET_TOOL_TIP: + break; + case LIBINPUT_EVENT_TABLET_TOOL_BUTTON: + break; + case LIBINPUT_EVENT_TABLET_PAD_BUTTON: + break; + case LIBINPUT_EVENT_TABLET_PAD_RING: + break; + case LIBINPUT_EVENT_TABLET_PAD_STRIP: + break; + case LIBINPUT_EVENT_SWITCH_TOGGLE: + break; } -} - + libinput_event_destroy(libinput_event); + libinput_dispatch(libinput); + } +} diff --git a/src/io/input.h b/src/io/input.h index 17eacd1..2f62a29 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -25,6 +25,8 @@ #include "../config/config.h" #define DEFAULT_SCALE 1.0 +#define SWIPE_X_THRESHOLD 1000 +#define SWIPE_Y_THRESHOLD 500 namespace gebaar::io { struct gesture_swipe_event { From 68a57ed917b68af6b79dfce1ae2395b5fa101722 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Wed, 27 Nov 2019 21:26:00 +0200 Subject: [PATCH 18/24] updated travis with correct repo name Changed repo name to make it explicit that this project is fork. Updated travis.yml to include that change else travis won't build release --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e56aa06..8ad1957 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ deploy: file: "gebaard" skip_cleanup: true on: - repo: osleg/gebaar-libinput + repo: osleg/gebaar-libinput-fork tags: true api_key: secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= From 8c3f67db473896fd8d369d7f8492a8c8e83b44a1 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 29 Nov 2019 01:12:56 +0200 Subject: [PATCH 19/24] Release and git PKGBUILDs * Added release PKGBUILD * Renamed git version PKGBUILD to `PKGBUILD.git` * Moved both PKGBUILDs to assets directory --- assets/PKGBUILD | 25 +++++++++++++++++++++++++ PKGBUILD => assets/PKGBUILD.git | 16 ++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 assets/PKGBUILD rename PKGBUILD => assets/PKGBUILD.git (70%) diff --git a/assets/PKGBUILD b/assets/PKGBUILD new file mode 100644 index 0000000..e32dfd2 --- /dev/null +++ b/assets/PKGBUILD @@ -0,0 +1,25 @@ +# Maintainer: Alex Zaslavsky + +pkgname=gebaar-libinput-fork +pkgver=0.1.4 +pkgrel=1 +pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput. Forked version with new features' +arch=('x86_64') +url="https://github.com/Osleg/$pkgname" +license=('GPL3') +depends=('libinput') +conflicts=('gebaar') +provides=('gebaar') +source=('https://github.com/osleg/gebaar-libinput-fork/releases/download/v0.1.4/gebaard' + 'https://raw.githubusercontent.com/osleg/gebaar-libinput-fork/master/LICENSE' + 'https://raw.githubusercontent.com/osleg/gebaar-libinput-fork/master/README.md') +md5sums=('74efb11da5bb1714e114e6305d999186' + 'SKIP' + 'SKIP') + + +package() { + install -Dm755 gebaard "$pkgdir/usr/bin/gebaard" + install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" + install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md" +} diff --git a/PKGBUILD b/assets/PKGBUILD.git similarity index 70% rename from PKGBUILD rename to assets/PKGBUILD.git index d768f39..79ed500 100644 --- a/PKGBUILD +++ b/assets/PKGBUILD.git @@ -1,27 +1,27 @@ -# Maintainer: Will Vauclain # Maintainer: Alex Zaslavsky -pkgname=gebaar-libinput-git + +pkgname=gebaar-libinput-fork-git pkgver=r47.07b0ca8 pkgrel=1 pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput. Forked version with new features' arch=('x86_64') -url="https://github.com/Osleg/gebaar-libinput" +url="https://github.com/Osleg/gebaar-libinput-fork" license=('GPL3') depends=('libinput') makedepends=('cmake' 'git') conflicts=('gebaar') provides=('gebaar') -source=('git+https://github.com/Osleg/gebaar-libinput') +source=('git+https://github.com/Osleg/gebaar-libinput-fork') md5sums=('SKIP') pkgver() { - cd "$srcdir/gebaar-libinput" + cd "$srcdir/gebaar-libinput-fork" printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" } prepare() { - cd $srcdir/gebaar-libinput + cd $srcdir/gebaar-libinput-fork git submodule init git submodule update mkdir -p build && cd build @@ -29,12 +29,12 @@ prepare() { } build() { - cd $srcdir/gebaar-libinput/build + cd $srcdir/gebaar-libinput-fork/build make -j$(nproc) } package() { - cd $srcdir/gebaar-libinput/build + cd $srcdir/gebaar-libinput-fork/build make DESTDIR="$pkgdir" install/strip cd .. install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" From b4163c2341f7cfd177c3c5ec7b5a006520a7a023 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 29 Nov 2019 01:37:47 +0200 Subject: [PATCH 20/24] Reformatted all sources --- src/config/config.cpp | 166 ++++++++++++++++++++++++------------------ src/config/config.h | 54 +++++++------- src/daemonizer.cpp | 78 ++++++++++---------- src/daemonizer.h | 31 ++++---- src/io/input.h | 140 +++++++++++++++++------------------ src/main.cpp | 55 +++++++------- src/util.cpp | 5 +- src/util.h | 2 +- 8 files changed, 276 insertions(+), 255 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 0bbd0cc..09ddbef 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -16,100 +16,122 @@ along with this program. If not, see . */ - -#include #include "config.h" #include "../util.h" +#include /** * Check if config file exists at current path */ -bool gebaar::config::Config::config_file_exists() -{ - auto true_path = std::filesystem::path(config_file_path); - return std::filesystem::exists(true_path); +bool gebaar::config::Config::config_file_exists() { + auto true_path = std::filesystem::path(config_file_path); + return std::filesystem::exists(true_path); } /** * Load Configuration from TOML file */ -void gebaar::config::Config::load_config() -{ - if (find_config_file()) { - if (config_file_exists()) { - try { - config = cpptoml::parse_file(std::filesystem::path(config_file_path)); - } catch (const cpptoml::parse_exception& e) { - std::cerr << e.what() << std::endl; - exit(EXIT_FAILURE); - } - - /* Swipe Settings */ - swipe_three_commands[1] = *config->get_qualified_as("swipe.commands.three.left_up"); - swipe_three_commands[2] = *config->get_qualified_as("swipe.commands.three.up"); - swipe_three_commands[3] = *config->get_qualified_as("swipe.commands.three.right_up"); - swipe_three_commands[4] = *config->get_qualified_as("swipe.commands.three.left"); - swipe_three_commands[6] = *config->get_qualified_as("swipe.commands.three.right"); - swipe_three_commands[7] = *config->get_qualified_as("swipe.commands.three.left_down"); - swipe_three_commands[8] = *config->get_qualified_as("swipe.commands.three.down"); - swipe_three_commands[9] = *config->get_qualified_as("swipe.commands.three.right_down"); - - swipe_four_commands[1] = *config->get_qualified_as("swipe.commands.four.left_up"); - swipe_four_commands[2] = *config->get_qualified_as("swipe.commands.four.up"); - swipe_four_commands[3] = *config->get_qualified_as("swipe.commands.four.right_up"); - swipe_four_commands[4] = *config->get_qualified_as("swipe.commands.four.left"); - swipe_four_commands[6] = *config->get_qualified_as("swipe.commands.four.right"); - swipe_four_commands[7] = *config->get_qualified_as("swipe.commands.four.left_down"); - swipe_four_commands[8] = *config->get_qualified_as("swipe.commands.four.down"); - swipe_four_commands[9] = *config->get_qualified_as("swipe.commands.four.right_down"); - - settings.swipe_threshold = config->get_qualified_as("swipe.settings.threshold").value_or(0.5); - settings.swipe_one_shot = config->get_qualified_as("swipe.settings.one_shot").value_or(true); - settings.swipe_trigger_on_release = config->get_qualified_as("swipe.settings.trigger_on_release").value_or(true); - - /* Pinch settings */ - pinch_commands[PINCH_IN] = *config->get_qualified_as("pinch.commands.two.out"); - pinch_commands[PINCH_OUT] = *config->get_qualified_as("pinch.commands.two.in"); - - settings.pinch_threshold = config->get_qualified_as("pinch.settings.threshold").value_or(0.25); - settings.pinch_one_shot = config->get_qualified_as("pinch.settings.one_shot").value_or(false); - - - loaded = true; - } +void gebaar::config::Config::load_config() { + if (find_config_file()) { + if (config_file_exists()) { + try { + config = cpptoml::parse_file(std::filesystem::path(config_file_path)); + } catch (const cpptoml::parse_exception &e) { + std::cerr << e.what() << std::endl; + exit(EXIT_FAILURE); + } + + /* Swipe Settings */ + swipe_three_commands[1] = *config->get_qualified_as( + "swipe.commands.three.left_up"); + swipe_three_commands[2] = + *config->get_qualified_as("swipe.commands.three.up"); + swipe_three_commands[3] = *config->get_qualified_as( + "swipe.commands.three.right_up"); + swipe_three_commands[4] = + *config->get_qualified_as("swipe.commands.three.left"); + swipe_three_commands[6] = + *config->get_qualified_as("swipe.commands.three.right"); + swipe_three_commands[7] = *config->get_qualified_as( + "swipe.commands.three.left_down"); + swipe_three_commands[8] = + *config->get_qualified_as("swipe.commands.three.down"); + swipe_three_commands[9] = *config->get_qualified_as( + "swipe.commands.three.right_down"); + + swipe_four_commands[1] = + *config->get_qualified_as("swipe.commands.four.left_up"); + swipe_four_commands[2] = + *config->get_qualified_as("swipe.commands.four.up"); + swipe_four_commands[3] = *config->get_qualified_as( + "swipe.commands.four.right_up"); + swipe_four_commands[4] = + *config->get_qualified_as("swipe.commands.four.left"); + swipe_four_commands[6] = + *config->get_qualified_as("swipe.commands.four.right"); + swipe_four_commands[7] = *config->get_qualified_as( + "swipe.commands.four.left_down"); + swipe_four_commands[8] = + *config->get_qualified_as("swipe.commands.four.down"); + swipe_four_commands[9] = *config->get_qualified_as( + "swipe.commands.four.right_down"); + + settings.swipe_threshold = + config->get_qualified_as("swipe.settings.threshold") + .value_or(0.5); + settings.swipe_one_shot = + config->get_qualified_as("swipe.settings.one_shot") + .value_or(true); + settings.swipe_trigger_on_release = + config->get_qualified_as("swipe.settings.trigger_on_release") + .value_or(true); + + /* Pinch settings */ + pinch_commands[PINCH_IN] = + *config->get_qualified_as("pinch.commands.two.out"); + pinch_commands[PINCH_OUT] = + *config->get_qualified_as("pinch.commands.two.in"); + + settings.pinch_threshold = + config->get_qualified_as("pinch.settings.threshold") + .value_or(0.25); + settings.pinch_one_shot = + config->get_qualified_as("pinch.settings.one_shot") + .value_or(false); + + loaded = true; } - + } } /** * Find the configuration file according to XDG spec * @return bool */ -bool gebaar::config::Config::find_config_file() -{ - std::string temp_path = gebaar::util::stringFromCharArray(getenv("XDG_CONFIG_HOME")); +bool gebaar::config::Config::find_config_file() { + std::string temp_path = + gebaar::util::stringFromCharArray(getenv("XDG_CONFIG_HOME")); + if (temp_path.empty()) { + // first get the path to HOME + temp_path = gebaar::util::stringFromCharArray(getenv("HOME")); if (temp_path.empty()) { - // first get the path to HOME - temp_path = gebaar::util::stringFromCharArray(getenv("HOME")); - if (temp_path.empty()) { - temp_path = getpwuid(getuid())->pw_dir; - } - // then append .config - if (!temp_path.empty()) { - temp_path.append("/.config"); - } + temp_path = getpwuid(getuid())->pw_dir; } + // then append .config if (!temp_path.empty()) { - config_file_path = temp_path; - config_file_path.append("/gebaar/gebaard.toml"); - return true; + temp_path.append("/.config"); } - return false; + } + if (!temp_path.empty()) { + config_file_path = temp_path; + config_file_path.append("/gebaar/gebaard.toml"); + return true; + } + return false; } -gebaar::config::Config::Config() -{ - if (!loaded) { - load_config(); - } +gebaar::config::Config::Config() { + if (!loaded) { + load_config(); + } } diff --git a/src/config/config.h b/src/config/config.h index 34d7a42..cde96c9 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -21,44 +21,40 @@ #include #include -#include #include +#include namespace gebaar::config { - class Config { - public: - Config(); - - bool loaded = false; - - void load_config(); - - - struct settings { - bool pinch_one_shot; - double pinch_threshold; +class Config { +public: + Config(); - bool swipe_one_shot; - double swipe_threshold; - bool swipe_trigger_on_release; - } settings; + bool loaded = false; - enum pinch {PINCH_IN, PINCH_OUT}; - std::string swipe_three_commands[10]; - std::string swipe_four_commands[10]; - std::string pinch_commands[10]; + void load_config(); - private: + struct settings { + bool pinch_one_shot; + double pinch_threshold; - bool config_file_exists(); + bool swipe_one_shot; + double swipe_threshold; + bool swipe_trigger_on_release; + } settings; - bool find_config_file(); + enum pinch { PINCH_IN, PINCH_OUT }; + std::string swipe_three_commands[10]; + std::string swipe_four_commands[10]; + std::string pinch_commands[10]; +private: + bool config_file_exists(); - std::string config_file_path; - std::shared_ptr config; + bool find_config_file(); + std::string config_file_path; + std::shared_ptr config; +}; +} // namespace gebaar::config - }; -} -#endif //GEBAAR_CONFIG_H +#endif // GEBAAR_CONFIG_H diff --git a/src/daemonizer.cpp b/src/daemonizer.cpp index 3c0e383..639c818 100644 --- a/src/daemonizer.cpp +++ b/src/daemonizer.cpp @@ -1,22 +1,21 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ - #include "daemonizer.h" /** @@ -24,40 +23,45 @@ * * @return bool that denotes fork success */ -bool gebaar::daemonizer::Daemonizer::daemonize() -{ - pid_t pid = 0; - pid = fork(); - if (pid<0) { - exit(EXIT_FAILURE); - } - if (pid>0) { - exit(EXIT_SUCCESS); - } - if (setsid()<0) { - // Boo. - } - signal(SIGCHLD, SIG_IGN); - signal(SIGTRAP, SIG_IGN); - pid = fork(); - if (pid<0) { - exit(EXIT_FAILURE); - } - if (pid>0) { - exit(EXIT_SUCCESS); - } - umask(0); - if ((chdir("/"))<0) { - return false; - } - close(STDOUT_FILENO); - close(STDIN_FILENO); - close(STDERR_FILENO); - if (getpid()!=getsid(getpid())) { - // - } - return true; +bool gebaar::daemonizer::Daemonizer::daemonize() { + pid_t pid = 0; + pid = fork(); + if (pid < 0) { + exit(EXIT_FAILURE); + } + + if (pid > 0) { + exit(EXIT_SUCCESS); + } + + if (setsid() < 0) { + // Boo. + } + + signal(SIGCHLD, SIG_IGN); + signal(SIGTRAP, SIG_IGN); + + pid = fork(); + if (pid < 0) { + exit(EXIT_FAILURE); + } + + if (pid > 0) { + exit(EXIT_SUCCESS); + } + umask(0); + if ((chdir("/")) < 0) { + return false; + } + + close(STDOUT_FILENO); + close(STDIN_FILENO); + close(STDERR_FILENO); + if (getpid() != getsid(getpid())) { + // + } + return true; } gebaar::daemonizer::Daemonizer::Daemonizer() = default; diff --git a/src/daemonizer.h b/src/daemonizer.h index ca60a15..debce01 100644 --- a/src/daemonizer.h +++ b/src/daemonizer.h @@ -1,33 +1,36 @@ /* gebaar Copyright (C) 2019 coffee2code - + 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 . */ + +#ifndef GEBAAR_DAEMONIZER_H +#define GEBAAR_DAEMONIZER_H + #include -#include #include #include +#include -#ifndef GEBAAR_DAEMONIZER_H -#define GEBAAR_DAEMONIZER_H namespace gebaar::daemonizer { - class Daemonizer { - public: - Daemonizer(); - ~Daemonizer(); - bool daemonize(); - }; -} -#endif //GEBAAR_DAEMONIZER_H +class Daemonizer { +public: + Daemonizer(); + ~Daemonizer(); + bool daemonize(); +}; +} // namespace gebaar::daemonizer + +#endif // GEBAAR_DAEMONIZER_H diff --git a/src/io/input.h b/src/io/input.h index 2f62a29..6c29ba3 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -19,107 +19,103 @@ #ifndef GEBAAR_INPUT_HPP #define GEBAAR_INPUT_HPP -#include +#include "../config/config.h" #include +#include #include -#include "../config/config.h" -#define DEFAULT_SCALE 1.0 -#define SWIPE_X_THRESHOLD 1000 -#define SWIPE_Y_THRESHOLD 500 +#define DEFAULT_SCALE 1.0 +#define SWIPE_X_THRESHOLD 1000 +#define SWIPE_Y_THRESHOLD 500 namespace gebaar::io { - struct gesture_swipe_event { - int fingers; - double x; - double y; - - bool executed; - int step; - }; +struct gesture_swipe_event { + int fingers; + double x; + double y; - struct gesture_pinch_event { - int fingers; - double scale; - double angle; + bool executed; + int step; +}; - bool executed; - int step; - }; +struct gesture_pinch_event { + int fingers; + double scale; + double angle; - class Input { - public: - Input(std::shared_ptr const& config_ptr); + bool executed; + int step; +}; - ~Input(); +class Input { +public: + Input(std::shared_ptr const &config_ptr); - bool initialize(); + ~Input(); - void start_loop(); + bool initialize(); - private: - std::shared_ptr config; + void start_loop(); - struct libinput* libinput; - struct libinput_event* libinput_event; - struct udev* udev; +private: + std::shared_ptr config; - struct gesture_swipe_event gesture_swipe_event; - struct gesture_pinch_event gesture_pinch_event; + struct libinput *libinput; + struct libinput_event *libinput_event; + struct udev *udev; - bool initialize_context(); + struct gesture_swipe_event gesture_swipe_event; + struct gesture_pinch_event gesture_pinch_event; - bool gesture_device_exists(); + bool initialize_context(); - static int open_restricted(const char* path, int flags, void* user_data) - { - int fd = open(path, flags); - return fd < 0 ? -errno : fd; - } + bool gesture_device_exists(); - static void close_restricted(int fd, void* user_data) - { - close(fd); - } + static int open_restricted(const char *path, int flags, void *user_data) { + int fd = open(path, flags); + return fd < 0 ? -errno : fd; + } - constexpr static struct libinput_interface libinput_interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, - }; + static void close_restricted(int fd, void *user_data) { close(fd); } - /* - * Decrements step of current trigger. Just to skip 0 - * @param cur current step - */ - inline void dec_step(int &cur) { --cur == 0 ? --cur : cur; } + constexpr static struct libinput_interface libinput_interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, + }; - /* - * Increase step of current trigger. Just to pass -1 - * @param cur current step - */ - inline void inc_step(int &cur) { ++cur == 0 ? ++cur : cur; } + /* + * Decrements step of current trigger. Just to skip 0 + * @param cur current step + */ + inline void dec_step(int &cur) { --cur == 0 ? --cur : cur; } - void handle_event(); + /* + * Increase step of current trigger. Just to pass -1 + * @param cur current step + */ + inline void inc_step(int &cur) { ++cur == 0 ? ++cur : cur; } - /* Swipe event */ - void reset_swipe_event(); + void handle_event(); - void handle_swipe_event_without_coords(libinput_event_gesture* gev, bool begin); + /* Swipe event */ + void reset_swipe_event(); - void handle_swipe_event_with_coords(libinput_event_gesture* gev); + void handle_swipe_event_without_coords(libinput_event_gesture *gev, + bool begin); - void trigger_swipe_command(); + void handle_swipe_event_with_coords(libinput_event_gesture *gev); - /* Pinch event */ - void reset_pinch_event(); + void trigger_swipe_command(); - void handle_one_shot_pinch(double new_scale); + /* Pinch event */ + void reset_pinch_event(); - void handle_continouos_pinch(double new_scale); + void handle_one_shot_pinch(double new_scale); - void handle_pinch_event(libinput_event_gesture* gev, bool begin); + void handle_continouos_pinch(double new_scale); - }; -} + void handle_pinch_event(libinput_event_gesture *gev, bool begin); +}; +} // namespace gebaar::io -#endif //GEBAAR_INPUT_HPP +#endif // GEBAAR_INPUT_HPP diff --git a/src/main.cpp b/src/main.cpp index 982ce3d..e43a41d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,42 +16,43 @@ along with this program. If not, see . */ - -#include -#include #include "config/config.h" -#include "io/input.h" #include "daemonizer.h" +#include "io/input.h" +#include +#include + +gebaar::io::Input *input; + +int main(int argc, char *argv[]) { + cxxopts::Options options(argv[0], "Gebaard Gestures Daemon"); -gebaar::io::Input* input; + bool should_daemonize = false; -int main(int argc, char* argv[]) -{ - cxxopts::Options options(argv[0], "Gebaard Gestures Daemon"); + options.add_options() + ("b,background", "Daemonize", cxxopts::value(should_daemonize)) + ("h,help", "Prints this help text"); - bool should_daemonize = false; + auto result = options.parse(argc, argv); - options.add_options() - ("b,background", "Daemonize", cxxopts::value(should_daemonize)) - ("h,help", "Prints this help text"); + if (result.count("help")) { + std::cout << options.help() << std::endl; + exit(EXIT_SUCCESS); + } - auto result = options.parse(argc, argv); + if (should_daemonize) { + auto *daemonizer = new gebaar::daemonizer::Daemonizer(); + daemonizer->daemonize(); + } - if (result.count("help")) { - std::cout << options.help() << std::endl; - exit(EXIT_SUCCESS); - } + std::shared_ptr config = + std::make_shared(); - if (should_daemonize) { - auto *daemonizer = new gebaar::daemonizer::Daemonizer(); - daemonizer->daemonize(); - } - std::shared_ptr config = std::make_shared(); - input = new gebaar::io::Input(config); + input = new gebaar::io::Input(config); - if (input->initialize()) { - input->start_loop(); - } + if (input->initialize()) { + input->start_loop(); + } - return 0; + return 0; } diff --git a/src/util.cpp b/src/util.cpp index a56dfe6..947a4a6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -23,7 +23,6 @@ * @param charArr The char array to convert * @return charArr or an empty string, if charArr is a nullptr */ -std::string gebaar::util::stringFromCharArray(char* charArr) -{ - return charArr == nullptr ? "" : charArr; +std::string gebaar::util::stringFromCharArray(char *charArr) { + return charArr == nullptr ? "" : charArr; } diff --git a/src/util.h b/src/util.h index eafec82..5c0791e 100644 --- a/src/util.h +++ b/src/util.h @@ -22,7 +22,7 @@ #include namespace gebaar::util { - std::string stringFromCharArray(char* charArr); +std::string stringFromCharArray(char *charArr); } #endif // UTIL_H From ecbcabaaf8dc297b75f808176909a9d90367bc41 Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 13 Mar 2020 15:20:02 +0200 Subject: [PATCH 21/24] updated README for upstream --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index dc07fe7..1b95c30 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,5 @@ - -[![Build Status](https://travis-ci.org/osleg/gebaar-libinput.svg?branch=master)](https://travis-ci.org/osleg/gebaar-libinput) - Gebaar ========= -Forked from Coffee2CodeNL/gebaar-libinput since original repo unmaintained for half a year, yet this is NOT OFFICIAL repo! WM Independent Touchpad Gesture Daemon for libinput From ccbe92ca2b982650944f057d6f45d2e5c4b9125c Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 13 Mar 2020 15:32:54 +0200 Subject: [PATCH 22/24] Updated travis and PKGBUILD --- .travis.yml | 2 +- assets/PKGBUILD | 12 ++++++------ assets/PKGBUILD.git | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ad1957..d1830f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ deploy: file: "gebaard" skip_cleanup: true on: - repo: osleg/gebaar-libinput-fork + repo: Coffee2CodeNL/gebaar-libinput-fork tags: true api_key: secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= diff --git a/assets/PKGBUILD b/assets/PKGBUILD index e32dfd2..4d40549 100644 --- a/assets/PKGBUILD +++ b/assets/PKGBUILD @@ -1,18 +1,18 @@ # Maintainer: Alex Zaslavsky -pkgname=gebaar-libinput-fork +pkgname=gebaar-libinput pkgver=0.1.4 pkgrel=1 -pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput. Forked version with new features' +pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput.' arch=('x86_64') -url="https://github.com/Osleg/$pkgname" +url="https://github.com/Coffee2CodeNL/$pkgname" license=('GPL3') depends=('libinput') conflicts=('gebaar') provides=('gebaar') -source=('https://github.com/osleg/gebaar-libinput-fork/releases/download/v0.1.4/gebaard' - 'https://raw.githubusercontent.com/osleg/gebaar-libinput-fork/master/LICENSE' - 'https://raw.githubusercontent.com/osleg/gebaar-libinput-fork/master/README.md') +source=('https://github.com/Coffee2CodeNL/gebaar-libinput/releases/download/v0.1.4/gebaard' + 'https://raw.githubusercontent.com/Coffee2CodeNL/gebaar-libinput/master/LICENSE' + 'https://raw.githubusercontent.com/Coffee2CodeNL/gebaar-libinput/master/README.md') md5sums=('74efb11da5bb1714e114e6305d999186' 'SKIP' 'SKIP') diff --git a/assets/PKGBUILD.git b/assets/PKGBUILD.git index 79ed500..1136d70 100644 --- a/assets/PKGBUILD.git +++ b/assets/PKGBUILD.git @@ -1,27 +1,27 @@ # Maintainer: Alex Zaslavsky -pkgname=gebaar-libinput-fork-git +pkgname=gebaar-libinput-git pkgver=r47.07b0ca8 pkgrel=1 -pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput. Forked version with new features' +pkgdesc='A Super Simple WM Independent Touchpad Gesture Daemon for libinput.' arch=('x86_64') -url="https://github.com/Osleg/gebaar-libinput-fork" +url="https://github.com/Coffee2CodeNL/gebaar-libinput" license=('GPL3') depends=('libinput') makedepends=('cmake' 'git') conflicts=('gebaar') provides=('gebaar') -source=('git+https://github.com/Osleg/gebaar-libinput-fork') +source=('git+https://github.com/Coffee2CodeNL/gebaar-libinput') md5sums=('SKIP') pkgver() { - cd "$srcdir/gebaar-libinput-fork" + cd "$srcdir/gebaar-libinput" printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" } prepare() { - cd $srcdir/gebaar-libinput-fork + cd $srcdir/gebaar-libinput git submodule init git submodule update mkdir -p build && cd build @@ -29,12 +29,12 @@ prepare() { } build() { - cd $srcdir/gebaar-libinput-fork/build + cd $srcdir/gebaar-libinput/build make -j$(nproc) } package() { - cd $srcdir/gebaar-libinput-fork/build + cd $srcdir/gebaar-libinput/build make DESTDIR="$pkgdir" install/strip cd .. install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" From 0efe66dff8adaca7ce98bb95c4eae098f2d3297e Mon Sep 17 00:00:00 2001 From: Alex Zaslavsky Date: Fri, 13 Mar 2020 15:36:09 +0200 Subject: [PATCH 23/24] repo name fix --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d1830f0..a35a27f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ deploy: file: "gebaard" skip_cleanup: true on: - repo: Coffee2CodeNL/gebaar-libinput-fork + repo: Coffee2CodeNL/gebaar-libinput tags: true api_key: secure: cocUFpTCvgEjAZzj5EC9iglQ4j1zx71a+U4aPLVUgNQNsFCZusSU//4ZEEwh1uYkJnnoxfhooRhAdgyMaWJs9Uvj7lgxk3dmHkc5f/p6iTFVH1lhPz06BT1tZkWzMkxLFilX8o53xl18qIiGBhgWGvqc5jFCFPrMALphql3qNrI0L/ZZRgU6FP7sXMU4LIomcIUsXKhDUZdRnrDZ3TIYaCrHSZEvLHPPlbYEVHncdmWFoZBjLMQ/M+i0cOgTHybxA6vlyLzA7zoMSGBgM7jDPDE6UN275PJenHT04gn6b9E3Ye6KLqhO/NZWseWfMZkQAnR1HJ6SswpF45nqLoMpjhEjQ5stJKe2dEIbsoeTEjfJgY5usOzh9UBawp+5SyuXYTMGHyaYpJM5w55KQv4bkecQm0yLVg4GBD852lEN2YuWkoteRH+3NYRR2l+Y/xsGKLAxJS4LoO+Jocf6ZUDjhrAyec2bxztQE7VGko2ndwC7nWPO6W8YfWfvgc08lqux5cYJjPE6Jj4fwrxMFhQ03eREcK8iYGHXs4kRTEv8Fj+Q0APFWIXVm6D2s9vPKPmzY84Q/Hq6B1gZKWwbsMOLUerRzsm6LtAxgg+vUQ3EIlknL2ciOkjHtWItkM6kl3txfalrf8TDl+mSTKnLpj2ZO5NxfdXC0aC7AZFGNhn+zSM= From 84ff26a3d758aa5535c5ff7c449014a581049c89 Mon Sep 17 00:00:00 2001 From: Thiago Sueto Date: Sat, 3 Oct 2020 14:52:27 -0300 Subject: [PATCH 24/24] Add Plasma instructions --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 1b95c30..79e6332 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,30 @@ trigger_on_release = false Add `gebaard -b` to `~/.config/bspwm/bspwmrc` +**KDE Plasma 5** + +Any multiword value (like in some qdbus commands) must have escaped double quotes to work (`\"`). + +Additionally, in some distros (like openSUSE), the `qdbus` command might be named `qdbus-qt5`. +Some navigation-related qdbus commands are provided directly by KWin and can be seen via `qdbus org.kde.KWin /KWin`, +but most shortcuts can be checked with `qdbus org.kde.kglobalaccel /component/kwin org.kde.kglobalaccel.Component.shortcutNames`. + +For Wayland users, a tool similar to `xdotool` in functionality is [ydotool](https://github.com/ReimuNotMoe/ydotool). + +```toml +[swipe.commands.three] +up = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Switch One Desktop Up\"" +down = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Switch One Desktop Down\"" +left = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Switch One Desktop to the Left\"" +right = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Switch One Desktop to the Right\"" + +[swipe.commands.four] +up = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Window Maximize\"" +down = "qdbus org.kde.kglobalaccel /component/kwin invokeShortcut \"Window Minimize\"" +left = "xdotool key alt+Left" +right = "xdotool key alt+Right" +``` + ### State of the project - [x] Receiving swipe events from libinput