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

14
src/backend/consumer.rs Normal file
View File

@@ -0,0 +1,14 @@
#[cfg(windows)]
pub mod windows;
#[cfg(feature="x11")]
pub mod x11;
#[cfg(feature = "wayland")]
pub mod wlroots;
#[cfg(feature = "xdg_desktop_portal")]
pub mod xdg_desktop_portal;
#[cfg(feature = "libei")]
pub mod libei;

View File

@@ -0,0 +1,9 @@
use std::sync::mpsc::Receiver;
use crate::{event::Event, client::{ClientHandle, Client}};
pub(crate) fn run(_consume_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
todo!()
}

View File

@@ -35,13 +35,8 @@ use tempfile;
use crate::event::{Event, KeyboardEvent, PointerEvent};
enum VirtualInputManager {
Wlroots {
vpm: VpManager,
vkm: VkManager,
},
Kde {
fake_input: OrgKdeKwinFakeInput,
}
Wlroots { vpm: VpManager, vkm: VkManager },
Kde { fake_input: OrgKdeKwinFakeInput },
}
// App State, implements Dispatch event handlers
@@ -72,16 +67,21 @@ impl App {
let virtual_input_manager = match (vpm, vkm, fake_input) {
(Ok(vpm), Ok(vkm), _) => VirtualInputManager::Wlroots { vpm, vkm },
(_, _, Ok(fake_input)) => {
fake_input.authenticate("lan-mouse".into(), "Allow remote clients to control this devices".into());
fake_input.authenticate(
"lan-mouse".into(),
"Allow remote clients to control this devices".into(),
);
VirtualInputManager::Kde { fake_input }
},
}
(Err(e1), Err(e2), Err(e3)) => {
eprintln!("zwlr_virtual_pointer_v1: {e1}");
eprintln!("zwp_virtual_keyboard_v1: {e2}");
eprintln!("org_kde_kwin_fake_input: {e3}");
panic!("neither wlroots nor kde input emulation protocol supported!")
},
_ => { panic!() }
}
_ => {
panic!()
}
};
let input_for_client: HashMap<ClientHandle, VirtualInput> = HashMap::new();
@@ -152,28 +152,22 @@ impl App {
buf.flush().unwrap();
keyboard.keymap(1, f.as_raw_fd(), data.len() as u32);
let vinput = VirtualInput::Wlroots{ pointer, keyboard };
let vinput = VirtualInput::Wlroots { pointer, keyboard };
self.input_for_client.insert(client.handle, vinput);
},
}
VirtualInputManager::Kde { fake_input } => {
let fake_input = fake_input.clone();
let vinput = VirtualInput::Kde { fake_input };
self.input_for_client.insert(client.handle, vinput);
},
}
}
}
}
enum VirtualInput {
Wlroots {
pointer: Vp,
keyboard: Vk,
},
Kde {
fake_input: OrgKdeKwinFakeInput,
}
Wlroots { pointer: Vp, keyboard: Vk },
Kde { fake_input: OrgKdeKwinFakeInput },
}
impl VirtualInput {
@@ -185,17 +179,18 @@ impl VirtualInput {
time,
relative_x,
relative_y,
} => {
match self {
VirtualInput::Wlroots { pointer, keyboard:_ } => {
pointer.motion(time, relative_x, relative_y);
pointer.frame();
},
VirtualInput::Kde { fake_input } => {
fake_input.pointer_motion(relative_y, relative_y);
},
} => match self {
VirtualInput::Wlroots {
pointer,
keyboard: _,
} => {
pointer.motion(time, relative_x, relative_y);
pointer.frame();
}
}
VirtualInput::Kde { fake_input } => {
fake_input.pointer_motion(relative_y, relative_y);
}
},
PointerEvent::Button {
time,
button,
@@ -203,70 +198,80 @@ impl VirtualInput {
} => {
let state: ButtonState = state.try_into().unwrap();
match self {
VirtualInput::Wlroots { pointer, keyboard:_ } => {
VirtualInput::Wlroots {
pointer,
keyboard: _,
} => {
pointer.button(time, button, state);
pointer.frame();
},
}
VirtualInput::Kde { fake_input } => {
fake_input.button(button, state as u32);
},
}
}
}
PointerEvent::Axis { time, axis, value } => {
let axis: Axis = (axis as u32).try_into().unwrap();
match self {
VirtualInput::Wlroots { pointer, keyboard:_ } => {
VirtualInput::Wlroots {
pointer,
keyboard: _,
} => {
pointer.axis(time, axis, value);
pointer.frame();
},
}
VirtualInput::Kde { fake_input } => {
fake_input.axis(axis as u32, value);
},
}
}
}
PointerEvent::Frame {} => {
match self {
VirtualInput::Wlroots { pointer, keyboard:_ } => {
pointer.frame();
},
VirtualInput::Kde { fake_input:_ } => { },
PointerEvent::Frame {} => match self {
VirtualInput::Wlroots {
pointer,
keyboard: _,
} => {
pointer.frame();
}
}
VirtualInput::Kde { fake_input: _ } => {}
},
},
Event::Keyboard(e) => match e {
KeyboardEvent::Key { time, key, state } => {
match self {
VirtualInput::Wlroots { pointer:_, keyboard } => {
keyboard.key(time, key, state as u32);
},
VirtualInput::Kde { fake_input } => {
fake_input.keyboard_key(key, state as u32);
},
KeyboardEvent::Key { time, key, state } => match self {
VirtualInput::Wlroots {
pointer: _,
keyboard,
} => {
keyboard.key(time, key, state as u32);
}
}
VirtualInput::Kde { fake_input } => {
fake_input.keyboard_key(key, state as u32);
}
},
KeyboardEvent::Modifiers {
mods_depressed,
mods_latched,
mods_locked,
group,
} => {
match self {
VirtualInput::Wlroots { pointer:_, keyboard } => {
keyboard.modifiers(mods_depressed, mods_latched, mods_locked, group);
},
VirtualInput::Kde { fake_input:_ } => { },
} => match self {
VirtualInput::Wlroots {
pointer: _,
keyboard,
} => {
keyboard.modifiers(mods_depressed, mods_latched, mods_locked, group);
}
}
VirtualInput::Kde { fake_input: _ } => {}
},
},
Event::Release() => {
match self {
VirtualInput::Wlroots { pointer:_, keyboard } => {
keyboard.modifiers(77, 0, 0, 0);
keyboard.modifiers(0, 0, 0, 0);
},
VirtualInput::Kde { fake_input:_ } => {},
Event::Release() => match self {
VirtualInput::Wlroots {
pointer: _,
keyboard,
} => {
keyboard.modifiers(77, 0, 0, 0);
keyboard.modifiers(0, 0, 0, 0);
}
}
VirtualInput::Kde { fake_input: _ } => {}
},
}
Ok(())
}

View File

@@ -0,0 +1,9 @@
use std::sync::mpsc::Receiver;
use crate::{event::Event, client::{ClientHandle, Client}};
pub(crate) fn run(_consume_rx: Receiver<(Event, ClientHandle)>, _clients: Vec<Client>) {
todo!()
}

6
src/backend/producer.rs Normal file
View File

@@ -0,0 +1,6 @@
#[cfg(feature = "wayland")]
pub mod wayland;
#[cfg(windows)]
pub mod windows;
#[cfg(feature = "x11")]
pub mod x11;

View File

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

View File

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

View File

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