@@ -28,7 +28,9 @@ gebaar::io::Input::Input(std::shared_ptr<gebaar::config::Config> const& config_p
2828{
2929 config = config_ptr;
3030 gesture_swipe_event = {};
31+
3132 gesture_pinch_event = {};
33+ gesture_pinch_event.scale = DEFAULT_SCALE;
3234}
3335
3436/* *
@@ -48,31 +50,60 @@ bool gebaar::io::Input::initialize_context()
4850 */
4951void gebaar::io::Input::reset_swipe_event () {
5052 gesture_swipe_event = {};
51- try {
52- gesture_swipe_event.threshold = std::stoi (config->settings [config->THRESHOLD ]);
53- }
54- catch (const std::invalid_argument& ia){
55- gesture_swipe_event.threshold = DEFAULT_THRESHOLD;
56- }
53+ gesture_swipe_event.executed = false ;
5754}
5855
5956/* *
6057 * Reset pinch event struct to defaults
6158 */
6259void gebaar::io::Input::reset_pinch_event () {
63- // Get pinch distance
64- try {
65- gesture_pinch_event.distance = std::stod (config->settings [config->DISTANCE ]);
60+ gesture_pinch_event = {};
61+ gesture_pinch_event.scale = DEFAULT_SCALE;
62+ gesture_pinch_event.executed = false ;
63+ }
64+
65+ /* *
66+ * Pinch one_shot gesture handle
67+ * @param new_scale last reported scale between the fingers
68+ */
69+ void gebaar::io::Input::handle_one_shot_pinch (double new_scale) {
70+ if (new_scale > gesture_pinch_event.scale ) { // Scale up
71+ // Add 1 to required distance to get 2 > x > 1
72+ if (new_scale > 1 + config->settings .pinch_threshold ) {
73+ std::system (config->pinch_commands [config->PINCH_IN ].c_str ());
74+ gesture_pinch_event.executed = true ;
6675 }
67- catch (const std::invalid_argument &ia) {
68- // Set default distance
69- gesture_pinch_event.distance = DEFAULT_DISTANCE;
76+ }
77+ else { // Scale Down
78+ // Substract from 1 to have inverted value for pinch in gesture
79+ if (gesture_pinch_event.scale < 1 - config->settings .pinch_threshold ) {
80+ std::system (config->pinch_commands [config->PINCH_OUT ].c_str ());
81+ gesture_pinch_event.executed = true ;
7082 }
71- // Reset pinch data
72- gesture_pinch_event.scale = DEFAULT_SCALE;
73- gesture_pinch_event.executed = false ;
83+ }
7484}
7585
86+ /* *
87+ * Pinch continous gesture handle
88+ * Calculates the trigger value according to current step
89+ * @param new_scale last reported scale between the fingers
90+ */
91+ void gebaar::io::Input::handle_continouos_pinch (double new_scale) {
92+ int step = gesture_pinch_event.step == 0 ? gesture_pinch_event.step + 1 : gesture_pinch_event.step ;
93+ double trigger = 1 + (config->settings .pinch_threshold * step);
94+
95+ if (new_scale > gesture_pinch_event.scale ) { // Scale up
96+ if (new_scale >= trigger){
97+ std::system (config->pinch_commands [config->PINCH_IN ].c_str ());
98+ inc_step (gesture_pinch_event.step );
99+ }
100+ } else { // Scale down
101+ if (new_scale <= trigger){
102+ std::system (config->pinch_commands [config->PINCH_OUT ].c_str ());
103+ dec_step (gesture_pinch_event.step );
104+ }
105+ }
106+ }
76107
77108/* *
78109 * Pinch Gesture
@@ -83,31 +114,13 @@ void gebaar::io::Input::reset_pinch_event() {
83114void gebaar::io::Input::handle_pinch_event (libinput_event_gesture* gev, bool begin)
84115{
85116 if (begin) {
86- reset_pinch_event ();
87- gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count (gev);
117+ reset_pinch_event ();
118+ gesture_pinch_event.fingers = libinput_event_gesture_get_finger_count (gev);
88119 }
89120 else {
90- if (gesture_swipe_event.executed ) return ;
91-
92- // Ignore input after command execution
93- if (gesture_pinch_event.executed ) return ;
94121 double new_scale = libinput_event_gesture_get_scale (gev);
95- if (new_scale > gesture_pinch_event.scale ) {
96- // Scale up
97- // Add 1 to required distance to get 2 > x > 1
98- if (new_scale > 1 + gesture_pinch_event.distance ) {
99- std::system (config->pinch_commands [config->PINCH_IN ].c_str ());
100- gesture_pinch_event.executed = true ;
101- }
102- }
103- else {
104- // Scale Down
105- // Substract from 1 to have inverted value for pinch in gesture
106- if (gesture_pinch_event.scale < 1 - gesture_pinch_event.distance ) {
107- std::system (config->pinch_commands [config->PINCH_OUT ].c_str ());
108- gesture_pinch_event.executed = true ;
109- }
110- }
122+ if (config->settings .pinch_one_shot && !gesture_pinch_event.executed ) handle_one_shot_pinch (new_scale);
123+ if (!config->settings .pinch_one_shot ) handle_continouos_pinch (new_scale);
111124 gesture_pinch_event.scale = new_scale;
112125 }
113126}
@@ -127,7 +140,7 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture
127140 }
128141 // This executed when fingers left the touchpad
129142 else {
130- if (!gesture_swipe_event.executed ) {
143+ if (!gesture_swipe_event.executed && config-> settings . swipe_trigger_on_release ) {
131144 trigger_swipe_command ();
132145 }
133146 reset_swipe_event ();
@@ -140,8 +153,10 @@ void gebaar::io::Input::handle_swipe_event_without_coords(libinput_event_gesture
140153 */
141154void gebaar::io::Input::handle_swipe_event_with_coords (libinput_event_gesture* gev)
142155{
143- if (gesture_swipe_event.executed ) return ;
144- int threshold = std::stoi (config->settings [config->THRESHOLD ]);
156+ if (config->settings .swipe_one_shot && gesture_swipe_event.executed ) return ;
157+
158+ // Since swipe gesture counts in dpi we have to convert
159+ int threshold = config->settings .swipe_threshold * 100 ;
145160 gesture_swipe_event.x += libinput_event_gesture_get_dx (gev);
146161 gesture_swipe_event.y += libinput_event_gesture_get_dy (gev);
147162 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
150165 }
151166}
152167
168+
169+ /* *
170+ * Making calculation for swipe direction and triggering
171+ * command accordingly
172+ */
153173void gebaar::io::Input::trigger_swipe_command () {
154174 double x = gesture_swipe_event.x ;
155175 double y = gesture_swipe_event.y ;
@@ -223,7 +243,8 @@ gebaar::io::Input::~Input()
223243bool gebaar::io::Input::gesture_device_exists ()
224244{
225245 bool device_found = false ;
226- while ((libinput_event = libinput_get_event (libinput))!=nullptr ) {
246+
247+ while ((libinput_event = libinput_get_event (libinput)) != nullptr ) {
227248 auto device = libinput_event_get_device (libinput_event);
228249 if (libinput_device_has_capability (device, LIBINPUT_DEVICE_CAP_GESTURE)) {
229250 device_found = true ;
0 commit comments