mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-25 14:10:55 +03:00
initial windows support
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -244,6 +244,7 @@ dependencies = [
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
13
Cargo.toml
13
Cargo.toml
@@ -6,10 +6,6 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
wayland-client = { git="https://github.com/Smithay/wayland-rs.git" }
|
||||
wayland-protocols = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "staging", "unstable"] }
|
||||
wayland-protocols-wlr = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||
wayland-protocols-misc = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||
tempfile = "3.2"
|
||||
trust-dns-resolver = "0.22"
|
||||
memmap = "0.7"
|
||||
@@ -17,3 +13,12 @@ toml = "0.5"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
threadpool = "1.8"
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
wayland-client = { git="https://github.com/Smithay/wayland-rs.git" }
|
||||
wayland-protocols = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "staging", "unstable"] }
|
||||
wayland-protocols-wlr = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||
wayland-protocols-misc = { git="https://github.com/Smithay/wayland-rs.git", features=["client", "server"] }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3.9", features = ["winuser"] }
|
||||
|
||||
2
src/backend.rs
Normal file
2
src/backend.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod windows;
|
||||
pub mod wayland;
|
||||
2
src/backend/wayland.rs
Normal file
2
src/backend/wayland.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod consumer;
|
||||
pub mod producer;
|
||||
@@ -1,3 +1,4 @@
|
||||
#![cfg(unix)]
|
||||
use crate::client::{Client, ClientHandle};
|
||||
use crate::request::{self, Request};
|
||||
use std::collections::HashMap;
|
||||
@@ -1,3 +1,4 @@
|
||||
#![cfg(unix)]
|
||||
use crate::{
|
||||
client::{Client, ClientHandle, Position},
|
||||
request,
|
||||
2
src/backend/windows.rs
Normal file
2
src/backend/windows.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod consumer;
|
||||
pub mod producer;
|
||||
45
src/backend/windows/consumer.rs
Normal file
45
src/backend/windows/consumer.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::sync::mpsc::Receiver;
|
||||
|
||||
use winapi::{self, um::winuser::{INPUT, LPINPUT, INPUT_MOUSE, MOUSEINPUT, MOUSEEVENTF_MOVE}};
|
||||
|
||||
use crate::{event::Event, client::{Client, ClientHandle}};
|
||||
|
||||
fn rel_mouse(dx: i32, dy: i32) {
|
||||
let mi = MOUSEINPUT {
|
||||
dx,
|
||||
dy,
|
||||
mouseData: 0,
|
||||
dwFlags: MOUSEEVENTF_MOVE,
|
||||
time: 0,
|
||||
dwExtraInfo: 0,
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let mut input = INPUT {
|
||||
type_: INPUT_MOUSE,
|
||||
u: std::mem::transmute(mi),
|
||||
};
|
||||
|
||||
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 {
|
||||
crate::event::PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
||||
rel_mouse(relative_x as i32, relative_y as i32);
|
||||
},
|
||||
crate::event::PointerEvent::Button { .. } => {},
|
||||
crate::event::PointerEvent::Axis { .. } => {},
|
||||
crate::event::PointerEvent::Frame { } => {},
|
||||
}
|
||||
},
|
||||
Event::Keyboard(_) => {},
|
||||
Event::Release() => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/backend/windows/producer.rs
Normal file
7
src/backend/windows/producer.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
use std::sync::mpsc::SyncSender;
|
||||
|
||||
use crate::{event::Event, client::{ClientHandle, Client}, request::Server};
|
||||
|
||||
pub fn run(_produce_tx: SyncSender<(Event, ClientHandle)>, _server: Server, _clients: Vec<Client>) {
|
||||
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
pub mod consumer;
|
||||
pub mod producer;
|
||||
pub mod server;
|
||||
|
||||
pub enum PointerEvent {
|
||||
|
||||
@@ -3,3 +3,5 @@ pub mod config;
|
||||
pub mod dns;
|
||||
pub mod event;
|
||||
pub mod request;
|
||||
|
||||
pub mod backend;
|
||||
|
||||
22
src/main.rs
22
src/main.rs
@@ -2,11 +2,15 @@ use std::{net::SocketAddr, sync::mpsc, thread};
|
||||
|
||||
use lan_mouse::{
|
||||
client::{ClientManager, Position},
|
||||
config, dns,
|
||||
event::{self, consumer, producer},
|
||||
request,
|
||||
config, dns, event, request,
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
use lan_mouse::backend::windows;
|
||||
|
||||
#[cfg(unix)]
|
||||
use lan_mouse::backend::wayland;
|
||||
|
||||
fn add_client(client_manager: &mut ClientManager, client: &config::Client, pos: Position) {
|
||||
let ip = match client.ip {
|
||||
Some(ip) => ip,
|
||||
@@ -60,11 +64,15 @@ pub fn main() {
|
||||
let (request_server, request_thread) = request::Server::listen(port).unwrap();
|
||||
|
||||
let clients = client_manager.get_clients();
|
||||
|
||||
// start producing and consuming events
|
||||
let event_producer = thread::Builder::new()
|
||||
.name("event producer".into())
|
||||
.spawn(|| {
|
||||
producer::run(produce_tx, request_server, clients);
|
||||
#[cfg(windows)]
|
||||
windows::producer::run(produce_tx, request_server, clients);
|
||||
#[cfg(unix)]
|
||||
wayland::producer::run(produce_tx, request_server, clients);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
@@ -72,7 +80,11 @@ pub fn main() {
|
||||
let event_consumer = thread::Builder::new()
|
||||
.name("event consumer".into())
|
||||
.spawn(|| {
|
||||
consumer::run(consume_rx, clients);
|
||||
#[cfg(windows)]
|
||||
windows::consumer::run(consume_rx, clients);
|
||||
|
||||
#[cfg(unix)]
|
||||
wayland::consumer::run(consume_rx, clients);
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user