@@ -25,24 +25,24 @@ namespace GestureListeners {
25
25
26
26
// Check if it's the initial gesture
27
27
const bool is_initial_gesture = !config->IsDragging () && args.data ->can_perform_gesture ;
28
- const auto now = std::chrono::high_resolution_clock::now () ;
28
+ const auto time = args. time ;
29
29
30
30
// If it's the initial gesture, set the gesture start time
31
31
if (is_initial_gesture && !config->IsGestureStarted ()) {
32
- gesture_start_ = now;
33
32
config->SetGestureStarted (true );
33
+ gesture_start_ = time;
34
34
}
35
35
36
36
// If there's no previous data, return
37
37
if (args.previous_data .contacts .empty ())
38
38
return ;
39
39
40
40
// Calculate the time elapsed since the initial touchpad contact
41
- std::chrono::duration<float > duration = now - gesture_start_;
41
+ std::chrono::duration<float > duration = time - gesture_start_;
42
42
const float ms_since_start = duration.count () * 1000 .0f ;
43
43
44
44
// Calculate the time elapsed since previous touchpad data was received
45
- duration = now - config->GetLastGesture ();
45
+ duration = time - config->GetLastGesture ();
46
46
const float ms_since_last_gesture = duration.count () * 1000 .0f ;
47
47
48
48
// Prevents initial jumpy movement due to old data comparison
@@ -54,6 +54,9 @@ namespace GestureListeners {
54
54
int valid_touches = 0 ;
55
55
for (int i = 0 ; i < NUM_TOUCH_CONTACTS_REQUIRED; i++)
56
56
{
57
+ if (i > args.previous_data .contacts .size () - 1 )
58
+ continue ;
59
+
57
60
const auto & contact = args.data ->contacts [i];
58
61
const auto & previous_contact = args.previous_data .contacts [i];
59
62
@@ -86,29 +89,20 @@ namespace GestureListeners {
86
89
return ;
87
90
88
91
// Centroid calculation
89
- const double divisor = static_cast <double >(NUM_TOUCH_CONTACTS_REQUIRED);
92
+ const long double divisor = static_cast <long double >(NUM_TOUCH_CONTACTS_REQUIRED);
90
93
91
94
accumulated_delta_x_ /= divisor;
92
95
accumulated_delta_y_ /= divisor;
93
96
94
- // Apply movement acceleration using a logarithmic function
95
- const double gesture_speed = config->GetGestureSpeed ();
96
- const double movement_mag = std::sqrt (accumulated_delta_x_ * accumulated_delta_x_ + accumulated_delta_y_ * accumulated_delta_y_);
97
- const double factor = (std::log2 (movement_mag + 1 )) * (1 + config->GetPrecisionTouchCursorSpeed ());
98
-
99
- double total_delta_x = accumulated_delta_x_;
100
- double total_delta_y = accumulated_delta_y_;
101
-
102
- // Apply the gesture_speed at the end of the calculation
103
- total_delta_x *= (gesture_speed / 100 );
104
- total_delta_y *= (gesture_speed / 100 );
105
-
97
+ // Apply movement acceleration
98
+ const double gesture_speed = config->GetGestureSpeed () / 100.0 ;
99
+ const double total_delta_x = accumulated_delta_x_ * gesture_speed;
100
+ const double total_delta_y = accumulated_delta_y_ * gesture_speed;
106
101
107
102
// Delay initial dragging gesture movement, and ignore invalid movement actions
108
- if (ms_since_start <= GESTURE_START_THRESHOLD_MS || !(args.data ->can_perform_gesture || config->IsDragging ())) {
103
+ if (ms_since_start <= GESTURE_START_THRESHOLD_MS || !(args.data ->can_perform_gesture || config->IsDragging ()))
109
104
return ;
110
- }
111
-
105
+
112
106
config->SetCancellationStarted (false );
113
107
114
108
// Move the mouse pointer based on the calculated vector
@@ -118,7 +112,7 @@ namespace GestureListeners {
118
112
119
113
// Set timestamp for when any cursor movement occurred
120
114
if (change > 0 )
121
- config->SetLastValidMovement (now );
115
+ config->SetLastValidMovement (time );
122
116
123
117
// Start dragging if left mouse is not already down.
124
118
if (!config->IsDragging ()) {
@@ -140,20 +134,23 @@ namespace GestureListeners {
140
134
void OnTouchUp (TouchUpEventArgs args) {
141
135
GlobalConfig* config = GlobalConfig::GetInstance ();
142
136
config->SetGestureStarted (false );
143
- if (config-> IsDragging () && !config-> IsCancellationStarted ()) {
144
- // Calculate the time elapsed since the last valid gesture movement
145
- const auto now = std::chrono::high_resolution_clock::now () ;
146
- const std::chrono::duration< float > duration = now - config-> GetLastValidMovement ();
147
- const float ms_since_last_movement = duration. count () * 1000 . 0f ;
148
-
149
- // If there hasn't been any movement for same amount of time we will delay, then cancel immediately
150
- if ( ms_since_last_movement >= CANCELLATION_TIME_MS) {
151
- CancelGesture ();
152
- return ;
153
- }
154
- config-> SetCancellationStarted ( true );
155
- config-> SetCancellationTime (now) ;
137
+
138
+ if (!config-> IsDragging () || config-> IsCancellationStarted ())
139
+ return ;
140
+
141
+ // Calculate the time elapsed since the last valid gesture movement
142
+ const auto now = std::chrono::high_resolution_clock::now ();
143
+ const std::chrono::duration< float > duration = now - config-> GetLastValidMovement ();
144
+ const float ms_since_last_movement = duration. count () * 1000 . 0f ;
145
+
146
+ // If there hasn't been any movement for same amount of time we will delay, then cancel immediately
147
+ if (ms_since_last_movement >= CANCELLATION_TIME_MS) {
148
+ CancelGesture ( );
149
+ return ;
156
150
}
151
+
152
+ config->SetCancellationStarted (true );
153
+ config->SetCancellationTime (now);
157
154
}
158
155
};
159
156
}
0 commit comments