From 0bf017397184717287888e908209ee9c640c9be9 Mon Sep 17 00:00:00 2001 From: Ferdinand Schober Date: Fri, 6 Sep 2024 23:31:35 +0200 Subject: [PATCH] add release bind check --- src/capture.rs | 8 +++++--- src/server.rs | 42 ++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/capture.rs b/src/capture.rs index bc0b3e4..d3a137a 100644 --- a/src/capture.rs +++ b/src/capture.rs @@ -12,7 +12,7 @@ use tokio::{ use crate::{connect::LanMouseConnection, server::Server}; -pub(crate) struct CaptureProxy { +pub(crate) struct Capture { tx: Sender, _task: JoinHandle<()>, } @@ -27,7 +27,7 @@ enum CaptureRequest { Destroy(CaptureHandle), } -impl CaptureProxy { +impl Capture { pub(crate) fn new(server: Server, conn: LanMouseConnection) -> Self { let (tx, rx) = channel(); let _task = spawn_local(Self::run(server.clone(), rx, conn)); @@ -126,7 +126,9 @@ async fn handle_capture_event( let (handle, event) = event; log::trace!("({handle}): {event:?}"); - if server.should_release.borrow_mut().take().is_some() { + if server.should_release.borrow_mut().take().is_some() + || capture.keys_pressed(&server.release_bind) + { return capture.release().await; } diff --git a/src/server.rs b/src/server.rs index 7190edf..a5b7057 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,18 @@ +use crate::{ + capture::Capture, + client::ClientManager, + config::Config, + connect::LanMouseConnection, + dns::DnsResolver, + emulation::Emulation, + listen::{LanMouseListener, ListenerCreationError}, +}; use futures::StreamExt; use hickory_resolver::error::ResolveError; +use lan_mouse_ipc::{ + AsyncFrontendListener, ClientConfig, ClientHandle, ClientState, FrontendEvent, FrontendRequest, + IpcListenerCreationError, Position, Status, +}; use local_channel::mpsc::{channel, Sender}; use log; use std::{ @@ -13,21 +26,6 @@ use thiserror::Error; use tokio::{join, signal, sync::Notify}; use tokio_util::sync::CancellationToken; -use crate::{ - capture::CaptureProxy, - client::ClientManager, - config::Config, - connect::LanMouseConnection, - dns::DnsResolver, - emulation::Emulation, - listen::{LanMouseListener, ListenerCreationError}, -}; - -use lan_mouse_ipc::{ - AsyncFrontendListener, ClientConfig, ClientHandle, ClientState, FrontendEvent, FrontendRequest, - IpcListenerCreationError, Position, Status, -}; - #[derive(Debug, Error)] pub enum ServiceError { #[error(transparent)] @@ -47,7 +45,7 @@ pub struct Server { pub(crate) client_manager: Rc>, port: Rc>, #[allow(unused)] - release_bind: Vec, + pub(crate) release_bind: Vec, notifies: Rc, pub(crate) config: Rc, pending_frontend_events: Rc>>, @@ -125,7 +123,7 @@ impl Server { let conn = LanMouseConnection::new(self.clone()); // input capture + emulation - let capture = CaptureProxy::new(self.clone(), conn); + let capture = Capture::new(self.clone(), conn); let _emulation = Emulation::new(self.clone(), listener); // create dns resolver @@ -233,7 +231,7 @@ impl Server { fn handle_request( &self, - capture: &CaptureProxy, + capture: &Capture, event: FrontendRequest, dns: &Sender, ) -> bool { @@ -295,7 +293,7 @@ impl Server { handle } - fn deactivate_client(&self, capture: &CaptureProxy, handle: ClientHandle) { + fn deactivate_client(&self, capture: &Capture, handle: ClientHandle) { log::debug!("deactivating client {handle}"); match self.client_manager.borrow_mut().get_mut(handle) { None => return, @@ -308,7 +306,7 @@ impl Server { log::info!("deactivated client {handle}"); } - fn activate_client(&self, capture: &CaptureProxy, handle: ClientHandle) { + fn activate_client(&self, capture: &Capture, handle: ClientHandle) { log::debug!("activating client"); /* deactivate potential other client at this position */ let pos = match self.client_manager.borrow().get(handle) { @@ -335,7 +333,7 @@ impl Server { log::info!("activated client {handle} ({pos})"); } - fn remove_client(&self, capture: &CaptureProxy, handle: ClientHandle) { + fn remove_client(&self, capture: &Capture, handle: ClientHandle) { let Some(active) = self .client_manager .borrow_mut() @@ -428,7 +426,7 @@ impl Server { } } - fn update_pos(&self, handle: ClientHandle, capture: &CaptureProxy, pos: Position) { + fn update_pos(&self, handle: ClientHandle, capture: &Capture, pos: Position) { let (changed, active) = { let mut client_manager = self.client_manager.borrow_mut(); let Some((c, s)) = client_manager.get_mut(handle) else {