initial windows support

This commit is contained in:
Ferdinand Schober
2023-02-12 19:04:28 +01:00
parent f545fe2686
commit 70b484878e
12 changed files with 89 additions and 11 deletions

1
Cargo.lock generated
View File

@@ -244,6 +244,7 @@ dependencies = [
"wayland-protocols",
"wayland-protocols-misc",
"wayland-protocols-wlr",
"winapi",
]
[[package]]

View File

@@ -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
View File

@@ -0,0 +1,2 @@
pub mod windows;
pub mod wayland;

2
src/backend/wayland.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod consumer;
pub mod producer;

View File

@@ -1,3 +1,4 @@
#![cfg(unix)]
use crate::client::{Client, ClientHandle};
use crate::request::{self, Request};
use std::collections::HashMap;

View File

@@ -1,3 +1,4 @@
#![cfg(unix)]
use crate::{
client::{Client, ClientHandle, Position},
request,

2
src/backend/windows.rs Normal file
View File

@@ -0,0 +1,2 @@
pub mod consumer;
pub mod producer;

View 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() => {},
}
}
}

View 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>) {
}

View File

@@ -1,7 +1,5 @@
use std::{error::Error, fmt};
pub mod consumer;
pub mod producer;
pub mod server;
pub enum PointerEvent {

View File

@@ -3,3 +3,5 @@ pub mod config;
pub mod dns;
pub mod event;
pub mod request;
pub mod backend;

View File

@@ -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();