mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-24 05:30:55 +03:00
its getting cleaner
This commit is contained in:
@@ -20,26 +20,49 @@ pub fn run() -> Result<()> {
|
||||
async fn input_capture_test(config: Config) -> Result<()> {
|
||||
log::info!("creating input capture");
|
||||
let backend = config.capture_backend.map(|b| b.into());
|
||||
let mut input_capture = input_capture::create(backend).await?;
|
||||
log::info!("creating clients");
|
||||
input_capture.create(0, Position::Left)?;
|
||||
input_capture.create(1, Position::Right)?;
|
||||
input_capture.create(2, Position::Top)?;
|
||||
input_capture.create(3, Position::Bottom)?;
|
||||
loop {
|
||||
let (client, event) = input_capture
|
||||
.next()
|
||||
.await
|
||||
.ok_or(anyhow!("capture stream closed"))??;
|
||||
let pos = match client {
|
||||
0 => Position::Left,
|
||||
1 => Position::Right,
|
||||
2 => Position::Top,
|
||||
_ => Position::Bottom,
|
||||
};
|
||||
log::info!("position: {pos}, event: {event}");
|
||||
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
|
||||
input_capture.release()?;
|
||||
for _ in 0..2 {
|
||||
let mut input_capture = Some(input_capture::create(backend).await?);
|
||||
log::info!("creating clients");
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(0, Position::Left)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(1, Position::Right)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(2, Position::Top)
|
||||
.await?;
|
||||
input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.create(3, Position::Bottom)
|
||||
.await?;
|
||||
loop {
|
||||
let (client, event) = input_capture
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.next()
|
||||
.await
|
||||
.ok_or(anyhow!("capture stream closed"))??;
|
||||
let pos = match client {
|
||||
0 => Position::Left,
|
||||
1 => Position::Right,
|
||||
2 => Position::Top,
|
||||
_ => Position::Bottom,
|
||||
};
|
||||
log::info!("position: {pos}, event: {event}");
|
||||
if let Event::Keyboard(KeyboardEvent::Key { key: 1, .. }) = event {
|
||||
// input_capture.as_mut().unwrap().release()?;
|
||||
break;
|
||||
}
|
||||
}
|
||||
input_capture.take().unwrap().async_drop().await.unwrap();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -52,16 +52,16 @@ pub fn new(
|
||||
match e {
|
||||
Some(e) => match e {
|
||||
CaptureEvent::Release => {
|
||||
capture.release()?;
|
||||
capture.release().await?;
|
||||
server.state.replace(State::Receiving);
|
||||
}
|
||||
CaptureEvent::Create(h, p) => capture.create(h, p)?,
|
||||
CaptureEvent::Destroy(h) => capture.destroy(h)?,
|
||||
CaptureEvent::Create(h, p) => capture.create(h, p).await?,
|
||||
CaptureEvent::Destroy(h) => capture.destroy(h).await?,
|
||||
CaptureEvent::Restart => {
|
||||
let clients = server.client_manager.borrow().get_client_states().map(|(h, (c,_))| (h, c.pos)).collect::<Vec<_>>();
|
||||
capture = input_capture::create(backend).await?;
|
||||
for (handle, pos) in clients {
|
||||
capture.create(handle, pos.into())?;
|
||||
capture.create(handle, pos.into()).await?;
|
||||
}
|
||||
}
|
||||
CaptureEvent::Terminate => break,
|
||||
@@ -104,7 +104,7 @@ async fn handle_capture_event(
|
||||
if release_bind.iter().all(|k| pressed_keys.contains(k)) {
|
||||
pressed_keys.clear();
|
||||
log::info!("releasing pointer");
|
||||
capture.release()?;
|
||||
capture.release().await?;
|
||||
server.state.replace(State::Receiving);
|
||||
log::trace!("STATE ===> Receiving");
|
||||
// send an event to release all the modifiers
|
||||
@@ -123,7 +123,7 @@ async fn handle_capture_event(
|
||||
None => {
|
||||
// should not happen
|
||||
log::warn!("unknown client!");
|
||||
capture.release()?;
|
||||
capture.release().await?;
|
||||
server.state.replace(State::Receiving);
|
||||
log::trace!("STATE ===> Receiving");
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user