From c9fc6b6d93c150a0e7a83cba6cd04b0b97909c64 Mon Sep 17 00:00:00 2001 From: Micah Johnston Date: Mon, 2 Sep 2024 19:41:30 -0500 Subject: [PATCH] don't send empty begin/end pairs when polling ParamGestures --- src/sync/param_gestures.rs | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/sync/param_gestures.rs b/src/sync/param_gestures.rs index d635c9d..cde6a69 100644 --- a/src/sync/param_gestures.rs +++ b/src/sync/param_gestures.rs @@ -81,26 +81,32 @@ impl<'a, 'b> Iterator for Poll<'a, 'b> { fn next(&mut self) -> Option { if let Some(index) = self.iter.next() { - let current_state = self.current_gestures.get(index); - let new_state = self.gesture_states.get(index, Ordering::Relaxed); - self.current_gestures.set(index, new_state); + let mut update = GestureUpdate { + index, + begin_gesture: false, + set_value: None, + end_gesture: false, + }; - let begin_gesture = !current_state; + let mut current_state = self.current_gestures.get(index); - let set_value = if self.values_dirty.swap(index, false, Ordering::Acquire) { - Some(self.values[index].load(Ordering::Relaxed)) - } else { - None - }; + if self.values_dirty.swap(index, false, Ordering::Acquire) { + if !current_state { + update.begin_gesture = true; + current_state = true; + } - let end_gesture = !new_state; + update.set_value = Some(self.values[index].load(Ordering::Relaxed)); + } - let update = GestureUpdate { - index, - begin_gesture, - set_value, - end_gesture, - }; + let next_state = self.gesture_states.get(index, Ordering::Relaxed); + if !current_state && next_state { + update.begin_gesture = true; + } else if current_state && !next_state { + update.end_gesture = true; + } + + self.current_gestures.set(index, next_state); Some(update) } else { @@ -168,9 +174,9 @@ mod tests { updates, &[GestureUpdate { index: 0, - begin_gesture: true, + begin_gesture: false, set_value: None, - end_gesture: true, + end_gesture: false, }] );