mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-07 20:09:59 +03:00
formatting
This commit is contained in:
@@ -99,10 +99,14 @@ impl App {
|
||||
let data = loop {
|
||||
let result = request::request_data(client.addr, Request::KeyMap);
|
||||
eprint!("\rconnecting to {} ", client.addr);
|
||||
for _ in 0..attempts { eprint!("."); }
|
||||
for _ in 0..attempts {
|
||||
eprint!(".");
|
||||
}
|
||||
match result {
|
||||
Ok(data) => break data,
|
||||
Err(e) => { eprint!(" - {}", e); }
|
||||
Err(e) => {
|
||||
eprint!(" - {}", e);
|
||||
}
|
||||
}
|
||||
io::stderr().flush().unwrap();
|
||||
thread::sleep(Duration::from_millis(500));
|
||||
@@ -110,7 +114,9 @@ impl App {
|
||||
};
|
||||
|
||||
eprint!("\rconnecting to {} ", client.addr);
|
||||
for _ in 0..attempts { eprint!("."); }
|
||||
for _ in 0..attempts {
|
||||
eprint!(".");
|
||||
}
|
||||
eprintln!(" done! ");
|
||||
|
||||
// TODO use shm_open
|
||||
@@ -163,11 +169,7 @@ impl VirtualInput {
|
||||
}
|
||||
},
|
||||
Event::Keyboard(e) => match e {
|
||||
KeyboardEvent::Key {
|
||||
time,
|
||||
key,
|
||||
state,
|
||||
} => {
|
||||
KeyboardEvent::Key { time, key, state } => {
|
||||
self.keyboard.key(time, key, state as u32);
|
||||
}
|
||||
KeyboardEvent::Modifiers {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
use winapi::{self, um::winuser::{INPUT, LPINPUT, INPUT_MOUSE, MOUSEINPUT, MOUSEEVENTF_MOVE}};
|
||||
use crate::event::{PointerEvent, KeyboardEvent};
|
||||
use crate::event::{KeyboardEvent, PointerEvent};
|
||||
use winapi::{
|
||||
self,
|
||||
um::winuser::{INPUT, INPUT_MOUSE, LPINPUT, MOUSEEVENTF_MOVE, MOUSEINPUT},
|
||||
};
|
||||
|
||||
use crate::{event::Event, client::{Client, ClientHandle}};
|
||||
use crate::{
|
||||
client::{Client, ClientHandle},
|
||||
event::Event,
|
||||
};
|
||||
|
||||
fn rel_mouse(dx: i32, dy: i32) {
|
||||
let mi = MOUSEINPUT {
|
||||
@@ -21,31 +27,34 @@ fn rel_mouse(dx: i32, dy: i32) {
|
||||
u: std::mem::transmute(mi),
|
||||
};
|
||||
|
||||
winapi::um::winuser::SendInput(1 as u32, &mut input as LPINPUT, std::mem::size_of::<INPUT>() as i32);
|
||||
winapi::um::winuser::SendInput(
|
||||
1 as u32,
|
||||
&mut input as LPINPUT,
|
||||
std::mem::size_of::<INPUT>() as i32,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
||||
loop {
|
||||
match event_rx.recv().expect("event receiver unavailable").0 {
|
||||
Event::Pointer(pointer_event) => {
|
||||
match pointer_event {
|
||||
PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
||||
rel_mouse(relative_x as i32, relative_y as i32);
|
||||
},
|
||||
PointerEvent::Button { .. } => {},
|
||||
PointerEvent::Axis { .. } => {},
|
||||
PointerEvent::Frame { } => {},
|
||||
Event::Pointer(pointer_event) => match pointer_event {
|
||||
PointerEvent::Motion {
|
||||
time: _,
|
||||
relative_x,
|
||||
relative_y,
|
||||
} => {
|
||||
rel_mouse(relative_x as i32, relative_y as i32);
|
||||
}
|
||||
PointerEvent::Button { .. } => {}
|
||||
PointerEvent::Axis { .. } => {}
|
||||
PointerEvent::Frame {} => {}
|
||||
},
|
||||
Event::Keyboard(keyboard_event) => {
|
||||
match keyboard_event {
|
||||
KeyboardEvent::Key {..} => {},
|
||||
KeyboardEvent::Modifiers {..} => {},
|
||||
}
|
||||
Event::Keyboard(keyboard_event) => match keyboard_event {
|
||||
KeyboardEvent::Key { .. } => {}
|
||||
KeyboardEvent::Modifiers { .. } => {}
|
||||
},
|
||||
Event::Release() => { },
|
||||
Event::Release() => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
use std::sync::mpsc::SyncSender;
|
||||
|
||||
use crate::{event::Event, client::{ClientHandle, Client}, request::Server};
|
||||
use crate::{
|
||||
client::{Client, ClientHandle},
|
||||
event::Event,
|
||||
request::Server,
|
||||
};
|
||||
|
||||
pub fn run(_produce_tx: SyncSender<(Event, ClientHandle)>, _server: Server, _clients: Vec<Client>) {
|
||||
todo!();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use std::{sync::mpsc::Receiver, ptr};
|
||||
use x11::{xtest, xlib};
|
||||
use std::{ptr, sync::mpsc::Receiver};
|
||||
use x11::{xlib, xtest};
|
||||
|
||||
use crate::{client::{ClientHandle, Client}, event::Event};
|
||||
use crate::{
|
||||
client::{Client, ClientHandle},
|
||||
event::Event,
|
||||
};
|
||||
|
||||
fn open_display() -> Option<*mut xlib::Display> {
|
||||
unsafe {
|
||||
@@ -27,18 +30,20 @@ pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
||||
|
||||
loop {
|
||||
match event_rx.recv().expect("event receiver unavailable").0 {
|
||||
Event::Pointer(pointer_event) => {
|
||||
match pointer_event {
|
||||
crate::event::PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
||||
relative_motion(display, relative_x as i32, relative_y as i32);
|
||||
},
|
||||
crate::event::PointerEvent::Button { .. } => {},
|
||||
crate::event::PointerEvent::Axis { .. } => {},
|
||||
crate::event::PointerEvent::Frame { } => {},
|
||||
Event::Pointer(pointer_event) => match pointer_event {
|
||||
crate::event::PointerEvent::Motion {
|
||||
time: _,
|
||||
relative_x,
|
||||
relative_y,
|
||||
} => {
|
||||
relative_motion(display, relative_x as i32, relative_y as i32);
|
||||
}
|
||||
crate::event::PointerEvent::Button { .. } => {}
|
||||
crate::event::PointerEvent::Axis { .. } => {}
|
||||
crate::event::PointerEvent::Frame {} => {}
|
||||
},
|
||||
Event::Keyboard(_) => {},
|
||||
Event::Release() => {},
|
||||
Event::Keyboard(_) => {}
|
||||
Event::Release() => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use std::sync::mpsc::SyncSender;
|
||||
|
||||
use crate::client::Client;
|
||||
use crate::event::Event;
|
||||
use crate::request::Server;
|
||||
use crate::client::Client;
|
||||
|
||||
|
||||
pub fn run(_produce_tx: SyncSender<(Event, u32)>, _request_server: Server, _clients: Vec<Client>) {
|
||||
todo!()
|
||||
|
||||
35
src/event.rs
35
src/event.rs
@@ -265,8 +265,12 @@ impl TryFrom<Vec<u8>> for PointerEvent {
|
||||
}))
|
||||
}
|
||||
};
|
||||
Ok(Self::Button { time, button, state })
|
||||
},
|
||||
Ok(Self::Button {
|
||||
time,
|
||||
button,
|
||||
state,
|
||||
})
|
||||
}
|
||||
PointerEventType::AXIS => {
|
||||
let time = match data.get(2..6) {
|
||||
Some(d) => u32::from_be_bytes(d.try_into().unwrap()),
|
||||
@@ -279,7 +283,7 @@ impl TryFrom<Vec<u8>> for PointerEvent {
|
||||
let axis = match data.get(6) {
|
||||
Some(d) => *d,
|
||||
None => {
|
||||
return Err(Box::new(ProtocolError{
|
||||
return Err(Box::new(ProtocolError {
|
||||
msg: "Expected 1 Byte at index 6".into(),
|
||||
}));
|
||||
}
|
||||
@@ -287,16 +291,14 @@ impl TryFrom<Vec<u8>> for PointerEvent {
|
||||
let value = match data.get(7..15) {
|
||||
Some(d) => f64::from_be_bytes(d.try_into().unwrap()),
|
||||
None => {
|
||||
return Err(Box::new(ProtocolError{
|
||||
return Err(Box::new(ProtocolError {
|
||||
msg: "Expected 8 Bytes at index 7".into(),
|
||||
}));
|
||||
}
|
||||
};
|
||||
Ok(Self::Axis { time, axis, value })
|
||||
},
|
||||
PointerEventType::FRAME => {
|
||||
Ok(Self::Frame {})
|
||||
},
|
||||
}
|
||||
PointerEventType::FRAME => Ok(Self::Frame {}),
|
||||
}
|
||||
}
|
||||
None => Err(Box::new(ProtocolError {
|
||||
@@ -310,11 +312,7 @@ impl Into<Vec<u8>> for &KeyboardEvent {
|
||||
fn into(self) -> Vec<u8> {
|
||||
let id = vec![self.event_type() as u8];
|
||||
let data = match self {
|
||||
KeyboardEvent::Key {
|
||||
time,
|
||||
key,
|
||||
state,
|
||||
} => {
|
||||
KeyboardEvent::Key { time, key, state } => {
|
||||
let time = time.to_be_bytes();
|
||||
let key = key.to_be_bytes();
|
||||
let state = state.to_be_bytes();
|
||||
@@ -414,13 +412,18 @@ impl TryFrom<Vec<u8>> for KeyboardEvent {
|
||||
}))
|
||||
}
|
||||
};
|
||||
Ok(KeyboardEvent::Modifiers { mods_depressed, mods_latched, mods_locked, group })
|
||||
},
|
||||
Ok(KeyboardEvent::Modifiers {
|
||||
mods_depressed,
|
||||
mods_latched,
|
||||
mods_locked,
|
||||
group,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Err(Box::new(ProtocolError {
|
||||
msg: "Expected an element at index 0".into(),
|
||||
}))
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main.rs
16
src/main.rs
@@ -12,7 +12,7 @@ use lan_mouse::{
|
||||
use lan_mouse::backend::windows;
|
||||
|
||||
#[cfg(unix)]
|
||||
use lan_mouse::backend::{Backend,wayland,x11};
|
||||
use lan_mouse::backend::{wayland, x11, Backend};
|
||||
|
||||
fn add_client(client_manager: &mut ClientManager, client: &config::Client, pos: Position) {
|
||||
let ip = match client.ip {
|
||||
@@ -74,7 +74,7 @@ pub fn main() {
|
||||
"x11" => Backend::X11,
|
||||
"wayland" => Backend::WAYLAND,
|
||||
_ => panic!("unknown XDG_SESSION_TYPE"),
|
||||
}
|
||||
},
|
||||
Err(_) => panic!("could not detect session type"),
|
||||
};
|
||||
|
||||
@@ -82,11 +82,13 @@ pub fn main() {
|
||||
println!("using backend: windows");
|
||||
|
||||
#[cfg(unix)]
|
||||
println!("using backend: {}", match backend {
|
||||
Backend::X11 => "x11",
|
||||
Backend::WAYLAND => "wayland",
|
||||
});
|
||||
|
||||
println!(
|
||||
"using backend: {}",
|
||||
match backend {
|
||||
Backend::X11 => "x11",
|
||||
Backend::WAYLAND => "wayland",
|
||||
}
|
||||
);
|
||||
|
||||
// start producing and consuming events
|
||||
let event_producer = thread::Builder::new()
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
error::Error,
|
||||
fmt::Display,
|
||||
io::prelude::*,
|
||||
net::{SocketAddr, TcpListener, TcpStream},
|
||||
sync::{Arc, RwLock},
|
||||
thread::{self, JoinHandle}, fmt::Display,
|
||||
thread::{self, JoinHandle},
|
||||
};
|
||||
|
||||
use memmap::MmapMut;
|
||||
@@ -121,7 +122,7 @@ pub fn request_data(addr: SocketAddr, req: Request) -> Result<Vec<u8>, Box<dyn E
|
||||
|
||||
// check for bad request
|
||||
if len == 0 {
|
||||
return Err(Box::new(BadRequest{}));
|
||||
return Err(Box::new(BadRequest {}));
|
||||
}
|
||||
|
||||
// read the data
|
||||
|
||||
Reference in New Issue
Block a user