#![forbid(unsafe_code)]
#![warn(missing_docs)]
pub mod mesh_input;
use mesh::MeshPayload;
use std::pin::Pin;
use vm_resource::kind::KeyboardInputHandleKind;
use vm_resource::kind::MouseInputHandleKind;
use vm_resource::CanResolveTo;
use vm_resource::ResourceId;
#[derive(Debug, Copy, Clone, MeshPayload)]
pub enum InputData {
Keyboard(KeyboardData),
Mouse(MouseData),
}
#[derive(Debug, Copy, Clone, MeshPayload)]
pub struct MouseData {
pub button_mask: u8,
pub x: u16,
pub y: u16,
}
#[derive(Debug, Copy, Clone, MeshPayload)]
pub struct KeyboardData {
pub code: u16,
pub make: bool,
}
pub trait InputSource<T>: futures::Stream<Item = T> + Unpin + Send {
fn set_active(
&mut self,
active: bool,
) -> Pin<Box<dyn '_ + std::future::Future<Output = ()> + Send>>;
}
pub struct ResolvedInputSource<T>(pub Box<dyn InputSource<T>>);
impl<T: 'static + InputSource<KeyboardData>> From<T> for ResolvedInputSource<KeyboardData> {
fn from(value: T) -> Self {
Self(Box::new(value))
}
}
impl<T: 'static + InputSource<MouseData>> From<T> for ResolvedInputSource<MouseData> {
fn from(value: T) -> Self {
Self(Box::new(value))
}
}
impl CanResolveTo<ResolvedInputSource<KeyboardData>> for KeyboardInputHandleKind {
type Input<'a> = &'a str;
}
impl CanResolveTo<ResolvedInputSource<MouseData>> for MouseInputHandleKind {
type Input<'a> = &'a str;
}
#[derive(MeshPayload)]
pub struct MultiplexedInputHandle {
pub elevation: usize,
}
impl ResourceId<KeyboardInputHandleKind> for MultiplexedInputHandle {
const ID: &'static str = "keyboard";
}
impl ResourceId<MouseInputHandleKind> for MultiplexedInputHandle {
const ID: &'static str = "mouse";
}