enable conditional compilation for all backends

To reduce binary size one can now enable only specific backends, e.g.
wayland or x11 via cargo features

Additionally adds stubs for libei and xdg-desktop-portal backends
This commit is contained in:
Ferdinand Schober
2023-02-17 13:06:13 +01:00
parent 94a4b15cc3
commit 4c66b37a2f
22 changed files with 310 additions and 197 deletions

View File

@@ -1,5 +1,7 @@
use std::net::SocketAddr;
use crate::{config, dns};
#[derive(Eq, Hash, PartialEq, Clone, Copy)]
pub enum Position {
Left,
@@ -34,19 +36,56 @@ pub struct ClientManager {
pub type ClientHandle = u32;
impl ClientManager {
fn add_client(&mut self, client: &config::Client, pos: Position) {
let ip = match client.ip {
Some(ip) => ip,
None => match &client.host_name {
Some(host_name) => match dns::resolve(host_name) {
Ok(ip) => ip,
Err(e) => panic!("{}", e),
},
None => panic!("neither ip nor hostname specified"),
},
};
let addr = SocketAddr::new(ip, client.port.unwrap_or(42069));
self.register_client(addr, pos);
}
fn new_id(&mut self) -> ClientHandle {
self.next_id += 1;
self.next_id
}
pub fn new() -> Self {
ClientManager {
pub fn new(config: &config::Config) -> Self {
let mut client_manager = ClientManager {
next_id: 0,
clients: Vec::new(),
};
// add clients from config
for client in vec![
&config.client.left,
&config.client.right,
&config.client.top,
&config.client.bottom,
] {
if let Some(client) = client {
let pos = match client {
client if Some(client) == config.client.left.as_ref() => Position::Left,
client if Some(client) == config.client.right.as_ref() => Position::Right,
client if Some(client) == config.client.top.as_ref() => Position::Top,
client if Some(client) == config.client.bottom.as_ref() => Position::Bottom,
_ => panic!(),
};
client_manager.add_client(client, pos);
}
}
client_manager
}
pub fn add_client(&mut self, addr: SocketAddr, pos: Position) {
pub fn register_client(&mut self, addr: SocketAddr, pos: Position) {
let handle = self.new_id();
let client = Client { addr, pos, handle };
self.clients.push(client);