use euclid::RigidTransform3D;
use crate::ApiSpace;
use crate::BaseSpace;
use crate::Frame;
use crate::InputFrame;
use crate::InputId;
use crate::InputSource;
use crate::SelectEvent;
use crate::SelectKind;
use crate::Sender;
#[derive(Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
pub enum Event {
AddInput(InputSource),
RemoveInput(InputId),
UpdateInput(InputId, InputSource),
SessionEnd,
VisibilityChange(Visibility),
Select(InputId, SelectKind, SelectEvent, Frame),
InputChanged(InputId, InputFrame),
ReferenceSpaceChanged(BaseSpace, RigidTransform3D<f32, ApiSpace, ApiSpace>),
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "ipc", derive(serde::Serialize, serde::Deserialize))]
pub enum Visibility {
Visible,
VisibleBlurred,
Hidden,
}
pub enum EventBuffer {
Buffered(Vec<Event>),
Sink(Sender<Event>),
}
impl Default for EventBuffer {
fn default() -> Self {
EventBuffer::Buffered(vec![])
}
}
impl EventBuffer {
pub fn callback(&mut self, event: Event) {
match *self {
EventBuffer::Buffered(ref mut events) => events.push(event),
EventBuffer::Sink(ref dest) => {
let _ = dest.send(event);
}
}
}
pub fn upgrade(&mut self, dest: Sender<Event>) {
if let EventBuffer::Buffered(ref mut events) = *self {
for event in events.drain(..) {
let _ = dest.send(event);
}
}
*self = EventBuffer::Sink(dest)
}
}