mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-04-03 14:51:28 +03:00
add session detection
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
pub mod windows;
|
pub mod windows;
|
||||||
pub mod wayland;
|
pub mod wayland;
|
||||||
pub mod x11;
|
pub mod x11;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub enum Backend {
|
||||||
|
X11,
|
||||||
|
WAYLAND,
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ pub fn run(event_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
|
|||||||
crate::event::PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
crate::event::PointerEvent::Motion { time: _, relative_x, relative_y } => {
|
||||||
relative_motion(display, relative_x as i32, relative_y as i32);
|
relative_motion(display, relative_x as i32, relative_y as i32);
|
||||||
},
|
},
|
||||||
crate::event::PointerEvent::Button { .. } => todo!(),
|
crate::event::PointerEvent::Button { .. } => {},
|
||||||
crate::event::PointerEvent::Axis { .. } => todo!(),
|
crate::event::PointerEvent::Axis { .. } => {},
|
||||||
crate::event::PointerEvent::Frame { } => todo!(),
|
crate::event::PointerEvent::Frame { } => {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Event::Keyboard(_) => todo!(),
|
Event::Keyboard(_) => {},
|
||||||
Event::Release() => todo!(),
|
Event::Release() => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use std::sync::mpsc::SyncSender;
|
||||||
|
|
||||||
|
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/main.rs
35
src/main.rs
@@ -1,8 +1,8 @@
|
|||||||
use std::{net::SocketAddr, sync::mpsc, thread};
|
use std::{net::SocketAddr, sync::mpsc, thread, env};
|
||||||
|
|
||||||
use lan_mouse::{
|
use lan_mouse::{
|
||||||
client::{ClientManager, Position},
|
client::{ClientManager, Position},
|
||||||
config, dns, event, request,
|
config, dns, event, request, backend::Backend,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
@@ -10,6 +10,7 @@ use lan_mouse::backend::windows;
|
|||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use lan_mouse::backend::wayland;
|
use lan_mouse::backend::wayland;
|
||||||
|
use lan_mouse::backend::x11;
|
||||||
|
|
||||||
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 {
|
||||||
@@ -65,26 +66,48 @@ pub fn main() {
|
|||||||
|
|
||||||
let clients = client_manager.get_clients();
|
let clients = client_manager.get_clients();
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
let backend = match env::var("XDG_SESSION_TYPE") {
|
||||||
|
Ok(session_type) => match session_type.as_str() {
|
||||||
|
"x11" => Backend::X11,
|
||||||
|
"wayland" => Backend::WAYLAND,
|
||||||
|
_ => panic!("unknown XDG_SESSION_TYPE"),
|
||||||
|
}
|
||||||
|
Err(_) => panic!("could not detect session type"),
|
||||||
|
};
|
||||||
|
println!("using backend: {}", 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()
|
||||||
.name("event producer".into())
|
.name("event producer".into())
|
||||||
.spawn(|| {
|
.spawn(move || {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
windows::producer::run(produce_tx, request_server, clients);
|
windows::producer::run(produce_tx, request_server, clients);
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
wayland::producer::run(produce_tx, request_server, clients);
|
match backend {
|
||||||
|
Backend::X11 => x11::producer::run(produce_tx, request_server, clients),
|
||||||
|
Backend::WAYLAND => wayland::producer::run(produce_tx, request_server, clients),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let clients = client_manager.get_clients();
|
let clients = client_manager.get_clients();
|
||||||
let event_consumer = thread::Builder::new()
|
let event_consumer = thread::Builder::new()
|
||||||
.name("event consumer".into())
|
.name("event consumer".into())
|
||||||
.spawn(|| {
|
.spawn(move || {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
windows::consumer::run(consume_rx, clients);
|
windows::consumer::run(consume_rx, clients);
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
wayland::consumer::run(consume_rx, clients);
|
match backend {
|
||||||
|
Backend::X11 => x11::consumer::run(consume_rx, clients),
|
||||||
|
Backend::WAYLAND => wayland::consumer::run(consume_rx, clients),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user