Skip to content

Commit

Permalink
don't send empty begin/end pairs when polling ParamGestures
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Sep 3, 2024
1 parent 5072bd1 commit c9fc6b6
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/sync/param_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,32 @@ impl<'a, 'b> Iterator for Poll<'a, 'b> {

fn next(&mut self) -> Option<Self::Item> {
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 {
Expand Down Expand Up @@ -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,
}]
);

Expand Down

0 comments on commit c9fc6b6

Please sign in to comment.