action.rs 1.73 KB
Newer Older
Dorota Czaplejewicz's avatar
WIP    
Dorota Czaplejewicz committed
1
/*! The symbol object, defining actions that the key can do when activated */
2

Dorota Czaplejewicz's avatar
WIP    
Dorota Czaplejewicz committed
3
use std::ffi::CString;
4

5
6
7
/// Name of the keysym
#[derive(Debug, Clone, PartialEq)]
pub struct KeySym(pub String);
8

9
10
/// Use to switch views
type View = String;
11
12

/// Use to send modified keypresses
13
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14
pub enum Modifier {
15
16
17
    /// Control and Alt are the only modifiers
    /// which doesn't interfere with levels,
    /// so it's simple to implement as levels are deprecated in squeekboard.
18
19
20
21
22
    Control,
    Alt,
}

/// Action to perform on the keypress and, in reverse, on keyrelease
23
#[derive(Debug, Clone, PartialEq)]
24
pub enum Action {
25
    /// Switch to this view
26
    SetView(View),
27
    /// Switch to a view and latch
28
29
    LockView {
        lock: View,
30
        /// When unlocked by pressing it or emitting a key
31
        unlock: View,
32
    },
33
34
    /// Hold this modifier for as long as the button is pressed
    ApplyModifier(Modifier),
35
36
    /// Submit some text
    Submit {
37
38
        /// Text to submit with input-method.
        /// If None, then keys are to be submitted instead.
39
40
        text: Option<CString>,
        /// The key events this symbol submits when submitting text is not possible
41
        keys: Vec<KeySym>,
42
    },
43
44
    /// Erase a position behind the cursor
    Erase,
45
    ShowPreferences,
46
}
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

impl Action {
    pub fn is_locked(&self, view_name: &str) -> bool {
        match self {
            Action::LockView { lock, unlock: _ } => lock == view_name,
            _ => false,
        }
    }
    pub fn is_active(&self, view_name: &str) -> bool {
        match self {
            Action::SetView(view) => view == view_name,
            Action::LockView { lock, unlock: _ } => lock == view_name,
            _ => false,
        }
    }
}