mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-23 21:43:19 +03:00
add release bind check
This commit is contained in:
@@ -12,7 +12,7 @@ use tokio::{
|
|||||||
|
|
||||||
use crate::{connect::LanMouseConnection, server::Server};
|
use crate::{connect::LanMouseConnection, server::Server};
|
||||||
|
|
||||||
pub(crate) struct CaptureProxy {
|
pub(crate) struct Capture {
|
||||||
tx: Sender<CaptureRequest>,
|
tx: Sender<CaptureRequest>,
|
||||||
_task: JoinHandle<()>,
|
_task: JoinHandle<()>,
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ enum CaptureRequest {
|
|||||||
Destroy(CaptureHandle),
|
Destroy(CaptureHandle),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CaptureProxy {
|
impl Capture {
|
||||||
pub(crate) fn new(server: Server, conn: LanMouseConnection) -> Self {
|
pub(crate) fn new(server: Server, conn: LanMouseConnection) -> Self {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let _task = spawn_local(Self::run(server.clone(), rx, conn));
|
let _task = spawn_local(Self::run(server.clone(), rx, conn));
|
||||||
@@ -126,7 +126,9 @@ async fn handle_capture_event(
|
|||||||
let (handle, event) = event;
|
let (handle, event) = event;
|
||||||
log::trace!("({handle}): {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;
|
return capture.release().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 futures::StreamExt;
|
||||||
use hickory_resolver::error::ResolveError;
|
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 local_channel::mpsc::{channel, Sender};
|
||||||
use log;
|
use log;
|
||||||
use std::{
|
use std::{
|
||||||
@@ -13,21 +26,6 @@ use thiserror::Error;
|
|||||||
use tokio::{join, signal, sync::Notify};
|
use tokio::{join, signal, sync::Notify};
|
||||||
use tokio_util::sync::CancellationToken;
|
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)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ServiceError {
|
pub enum ServiceError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
@@ -47,7 +45,7 @@ pub struct Server {
|
|||||||
pub(crate) client_manager: Rc<RefCell<ClientManager>>,
|
pub(crate) client_manager: Rc<RefCell<ClientManager>>,
|
||||||
port: Rc<Cell<u16>>,
|
port: Rc<Cell<u16>>,
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
release_bind: Vec<input_event::scancode::Linux>,
|
pub(crate) release_bind: Vec<input_event::scancode::Linux>,
|
||||||
notifies: Rc<Notifies>,
|
notifies: Rc<Notifies>,
|
||||||
pub(crate) config: Rc<Config>,
|
pub(crate) config: Rc<Config>,
|
||||||
pending_frontend_events: Rc<RefCell<VecDeque<FrontendEvent>>>,
|
pending_frontend_events: Rc<RefCell<VecDeque<FrontendEvent>>>,
|
||||||
@@ -125,7 +123,7 @@ impl Server {
|
|||||||
let conn = LanMouseConnection::new(self.clone());
|
let conn = LanMouseConnection::new(self.clone());
|
||||||
|
|
||||||
// input capture + emulation
|
// input capture + emulation
|
||||||
let capture = CaptureProxy::new(self.clone(), conn);
|
let capture = Capture::new(self.clone(), conn);
|
||||||
let _emulation = Emulation::new(self.clone(), listener);
|
let _emulation = Emulation::new(self.clone(), listener);
|
||||||
|
|
||||||
// create dns resolver
|
// create dns resolver
|
||||||
@@ -233,7 +231,7 @@ impl Server {
|
|||||||
|
|
||||||
fn handle_request(
|
fn handle_request(
|
||||||
&self,
|
&self,
|
||||||
capture: &CaptureProxy,
|
capture: &Capture,
|
||||||
event: FrontendRequest,
|
event: FrontendRequest,
|
||||||
dns: &Sender<ClientHandle>,
|
dns: &Sender<ClientHandle>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@@ -295,7 +293,7 @@ impl Server {
|
|||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deactivate_client(&self, capture: &CaptureProxy, handle: ClientHandle) {
|
fn deactivate_client(&self, capture: &Capture, handle: ClientHandle) {
|
||||||
log::debug!("deactivating client {handle}");
|
log::debug!("deactivating client {handle}");
|
||||||
match self.client_manager.borrow_mut().get_mut(handle) {
|
match self.client_manager.borrow_mut().get_mut(handle) {
|
||||||
None => return,
|
None => return,
|
||||||
@@ -308,7 +306,7 @@ impl Server {
|
|||||||
log::info!("deactivated client {handle}");
|
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");
|
log::debug!("activating client");
|
||||||
/* deactivate potential other client at this position */
|
/* deactivate potential other client at this position */
|
||||||
let pos = match self.client_manager.borrow().get(handle) {
|
let pos = match self.client_manager.borrow().get(handle) {
|
||||||
@@ -335,7 +333,7 @@ impl Server {
|
|||||||
log::info!("activated client {handle} ({pos})");
|
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
|
let Some(active) = self
|
||||||
.client_manager
|
.client_manager
|
||||||
.borrow_mut()
|
.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 (changed, active) = {
|
||||||
let mut client_manager = self.client_manager.borrow_mut();
|
let mut client_manager = self.client_manager.borrow_mut();
|
||||||
let Some((c, s)) = client_manager.get_mut(handle) else {
|
let Some((c, s)) = client_manager.get_mut(handle) else {
|
||||||
|
|||||||
Reference in New Issue
Block a user