add ui mockup

This commit is contained in:
Ferdinand Schober
2024-09-25 02:00:48 +02:00
parent c480bb6ea6
commit f056f790c7
4 changed files with 75 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ use futures::StreamExt;
use input_emulation::{EmulationHandle, InputEmulation, InputEmulationError};
use input_event::Event;
use lan_mouse_ipc::Status;
use lan_mouse_proto::ProtoEvent;
use lan_mouse_proto::{Position, ProtoEvent};
use local_channel::mpsc::{channel, Receiver, Sender};
use std::{
collections::HashMap,
@@ -44,10 +44,11 @@ impl Emulation {
log::trace!("{event} <-<-<-<-<- {addr}");
last_response.insert(addr, Instant::now());
match event {
ProtoEvent::Enter(_) => {
ProtoEvent::Enter(pos) => {
log::info!("{addr} entered this device");
server.release_capture();
listener.reply(addr, ProtoEvent::Ack(0)).await;
server.register_incoming(addr, to_ipc_pos(pos));
}
ProtoEvent::Leave(_) => {
emulation_proxy.release_keys(addr);
@@ -196,3 +197,12 @@ impl EmulationProxy {
let _ = (&mut self.task).await;
}
}
fn to_ipc_pos(pos: Position) -> lan_mouse_ipc::Position {
match pos {
Position::Left => lan_mouse_ipc::Position::Left,
Position::Right => lan_mouse_ipc::Position::Right,
Position::Top => lan_mouse_ipc::Position::Top,
Position::Bottom => lan_mouse_ipc::Position::Bottom,
}
}

View File

@@ -51,6 +51,7 @@ pub struct Server {
capture_status: Rc<Cell<Status>>,
pub(crate) emulation_status: Rc<Cell<Status>>,
pub(crate) should_release: Rc<RefCell<Option<ReleaseToken>>>,
incoming_conns: Rc<RefCell<Vec<(SocketAddr, Position)>>>,
}
#[derive(Default)]
@@ -101,6 +102,7 @@ impl Server {
pending_frontend_events: Rc::new(RefCell::new(VecDeque::new())),
capture_status: Default::default(),
emulation_status: Default::default(),
incoming_conns: Rc::new(RefCell::new(Vec::new())),
should_release: Default::default(),
}
}
@@ -503,6 +505,10 @@ impl Server {
pub(crate) fn get_active(&self) -> Option<ClientHandle> {
self.active.get()
}
pub(crate) fn register_incoming(&self, addr: SocketAddr, pos: Position) {
self.incoming_conns.borrow_mut().push((addr, pos));
}
}
fn to_capture_pos(pos: Position) -> input_capture::Position {