(
range: &mut std::ops::Range<usize>,
event_buf: &[input_event],
mut handle_event: impl FnMut(InputEvent),
)
| 622 | /// Err(true) means the device should sync the state with ioctl |
| 623 | #[inline] |
| 624 | fn sync_events( |
| 625 | range: &mut std::ops::Range<usize>, |
| 626 | event_buf: &[input_event], |
| 627 | mut handle_event: impl FnMut(InputEvent), |
| 628 | ) -> (Result<input_event, bool>, Option<usize>) { |
| 629 | let mut consumed_to = None; |
| 630 | let res = 'outer: loop { |
| 631 | if let Some(idx) = range.next() { |
| 632 | // we're going through and emitting the events of a block that we checked |
| 633 | break Ok(event_buf[idx]); |
| 634 | } |
| 635 | // find the range of this new block: look for a SYN_REPORT |
| 636 | let block_start = range.end; |
| 637 | let mut block_dropped = false; |
| 638 | for (i, ev) in event_buf.iter().enumerate().skip(block_start) { |
| 639 | let ev = InputEvent::from(*ev); |
| 640 | match ev.destructure() { |
| 641 | EventSummary::Synchronization(_, SynchronizationCode::SYN_DROPPED, _) => { |
| 642 | block_dropped = true; |
| 643 | } |
| 644 | EventSummary::Synchronization(_, SynchronizationCode::SYN_REPORT, _) => { |
| 645 | consumed_to = Some(i + 1); |
| 646 | if block_dropped { |
| 647 | *range = event_buf.len()..event_buf.len(); |
| 648 | break 'outer Err(true); |
| 649 | } else { |
| 650 | *range = block_start..i + 1; |
| 651 | continue 'outer; |
| 652 | } |
| 653 | } |
| 654 | _ => handle_event(ev), |
| 655 | } |
| 656 | } |
| 657 | break Err(false); |
| 658 | }; |
| 659 | (res, consumed_to) |
| 660 | } |
| 661 | |
| 662 | impl fmt::Display for Device { |
| 663 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
searching dependent graphs…