1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::output::actions::*;
use serde::{Deserialize, Serialize};

/// User actions accepted by the chord2key [Mapper].
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum Action {
    /// Actions that are sent to the [OutputDevice].
    OutputAction(OutputAction),

    /// Actions that act on or depend on the internal state of the [Mapper].
    InnerAction(InnerAction),
}

/// Actions that act on or depend on the internal state of the [Mapper].
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum InnerAction {
    /// Repeat the last emitted chord in whatever [OutputActionType], converting if necessary
    RepeatLastChord(OutputActionType),

    /// Switch to a new configuration given by the path.
    SwitchConfig(std::path::PathBuf),
}

impl From<OutputAction> for Action {
    fn from(oe: OutputAction) -> Self {
        Self::OutputAction(oe)
    }
}

impl From<Pulse> for Action {
    fn from(pulse: Pulse) -> Self {
        Self::OutputAction(OutputAction::Pulse(pulse))
    }
}

impl From<StateChange> for Action {
    fn from(sc: StateChange) -> Self {
        Self::OutputAction(OutputAction::StateChange(sc))
    }
}

impl From<Toggle> for Action {
    fn from(toggle: Toggle) -> Self {
        Self::OutputAction(OutputAction::Toggle(toggle))
    }
}

impl From<InnerAction> for Action {
    fn from(ie: InnerAction) -> Self {
        Self::InnerAction(ie)
    }
}