mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-18 02:30:54 +03:00
Compare commits
1 Commits
remove-git
...
capture-du
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1f9afdfd4 |
@@ -1,16 +1,28 @@
|
|||||||
|
use std::f64::consts::PI;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{ready, Context, Poll};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
|
use input_event::PointerEvent;
|
||||||
|
use tokio::time::{self, Instant, Interval};
|
||||||
|
|
||||||
use super::{Capture, CaptureError, CaptureEvent, CaptureHandle, Position};
|
use super::{Capture, CaptureError, CaptureEvent, CaptureHandle, Position};
|
||||||
|
|
||||||
pub struct DummyInputCapture {}
|
pub struct DummyInputCapture {
|
||||||
|
start: Option<Instant>,
|
||||||
|
interval: Interval,
|
||||||
|
offset: (i32, i32),
|
||||||
|
}
|
||||||
|
|
||||||
impl DummyInputCapture {
|
impl DummyInputCapture {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {}
|
Self {
|
||||||
|
start: None,
|
||||||
|
interval: time::interval(Duration::from_millis(1)),
|
||||||
|
offset: (0, 0),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,10 +51,36 @@ impl Capture for DummyInputCapture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FREQUENCY_HZ: f64 = 1.0;
|
||||||
|
const RADIUS: f64 = 100.0;
|
||||||
|
|
||||||
impl Stream for DummyInputCapture {
|
impl Stream for DummyInputCapture {
|
||||||
type Item = Result<(CaptureHandle, CaptureEvent), CaptureError>;
|
type Item = Result<(CaptureHandle, CaptureEvent), CaptureError>;
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
Poll::Pending
|
let current = ready!(self.interval.poll_tick(cx));
|
||||||
|
let event = match self.start {
|
||||||
|
None => {
|
||||||
|
self.start.replace(current);
|
||||||
|
CaptureEvent::Begin
|
||||||
|
}
|
||||||
|
Some(start) => {
|
||||||
|
let elapsed = start.elapsed();
|
||||||
|
let elapsed_sec_f64 = elapsed.as_secs_f64();
|
||||||
|
let second_fraction = elapsed_sec_f64 - elapsed_sec_f64 as u64 as f64;
|
||||||
|
let radians = second_fraction * 2. * PI * FREQUENCY_HZ;
|
||||||
|
let offset = (radians.cos() * RADIUS * 2., (radians * 2.).sin() * RADIUS);
|
||||||
|
let offset = (offset.0 as i32, offset.1 as i32);
|
||||||
|
let relative_motion = (offset.0 - self.offset.0, offset.1 - self.offset.1);
|
||||||
|
self.offset = offset;
|
||||||
|
let (dx, dy) = (relative_motion.0 as f64, relative_motion.1 as f64);
|
||||||
|
CaptureEvent::Input(input_event::Event::Pointer(PointerEvent::Motion {
|
||||||
|
time: 0,
|
||||||
|
dx,
|
||||||
|
dy,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Poll::Ready(Some(Ok((0, event))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user