use crate::config::application::OnlyOrNot;
use crate::config::expmap_operator::ExpmapAction;
use crate::device::InputDeviceInfo;
use crate::emit_handler::Emit;
use crate::event::{Event, KeyEvent, KeyValue};
use evdev::KeyCode as Key;
use std::fmt::Debug;
use std::rc::Rc;
pub trait StaticOperator: Debug {
fn get_operators(&self) -> Vec<(Key, Box<dyn StaticOperator>)>;
fn get_active_operator(&self, event: &Event) -> Box<dyn ActiveOperator>;
}
#[derive(Debug, Clone)]
pub enum OperatorAction {
Undecided,
Cancel,
Unhandled,
Partial(Vec<Emit>, Vec<Event>),
Done(Vec<Emit>, Vec<Event>),
}
pub trait ActiveOperator: Debug {
fn on_event(&mut self, event: &Event) -> OperatorAction;
}
pub fn map_actions(actions: &Vec<ExpmapAction>, device: Rc<InputDeviceInfo>, value: KeyValue) -> Vec<Emit> {
actions
.iter()
.filter_map(|action| match action {
ExpmapAction::Key(key) => Some(Emit::key_event(device.clone(), KeyEvent::new(*key, value))),
})
.collect()
}
#[derive(Debug)]
pub struct OperatorEntry {
pub operator: Box<dyn StaticOperator>,
pub application: Option<OnlyOrNot>,
pub title: Option<OnlyOrNot>,
}