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