mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-20 19:50:55 +03:00
add session detection
This commit is contained in:
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::{
|
||||
client::{ClientManager, Position},
|
||||
config, dns, event, request,
|
||||
config, dns, event, request, backend::Backend,
|
||||
};
|
||||
|
||||
#[cfg(windows)]
|
||||
@@ -10,6 +10,7 @@ use lan_mouse::backend::windows;
|
||||
|
||||
#[cfg(unix)]
|
||||
use lan_mouse::backend::wayland;
|
||||
use lan_mouse::backend::x11;
|
||||
|
||||
fn add_client(client_manager: &mut ClientManager, client: &config::Client, pos: Position) {
|
||||
let ip = match client.ip {
|
||||
@@ -65,26 +66,48 @@ pub fn main() {
|
||||
|
||||
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
|
||||
let event_producer = thread::Builder::new()
|
||||
.name("event producer".into())
|
||||
.spawn(|| {
|
||||
.spawn(move || {
|
||||
#[cfg(windows)]
|
||||
windows::producer::run(produce_tx, request_server, clients);
|
||||
|
||||
#[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();
|
||||
|
||||
let clients = client_manager.get_clients();
|
||||
let event_consumer = thread::Builder::new()
|
||||
.name("event consumer".into())
|
||||
.spawn(|| {
|
||||
.spawn(move || {
|
||||
#[cfg(windows)]
|
||||
windows::consumer::run(consume_rx, clients);
|
||||
|
||||
#[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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user