Files
squeekboard/src/action.rs
Dorota Czaplejewicz 92e9d994fe modifiers: Support Control and Alt
Control and Alt are special in that they aren't expected to switch levels, and so don't need to change what characters are output.

Use in layouts by adding `modifier: Control` or `modifier: Alt` in place of `text: "foo"`.

The latching of the modifier will force the keyboard to emit raw key presses and prevent it from outputting text.
2020-02-28 11:21:07 +00:00

63 lines
1.7 KiB
Rust

/*! The symbol object, defining actions that the key can do when activated */
use std::ffi::CString;
/// Name of the keysym
#[derive(Debug, Clone, PartialEq)]
pub struct KeySym(pub String);
/// Use to switch views
type View = String;
/// Use to send modified keypresses
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Modifier {
/// 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.
Control,
Alt,
}
/// Action to perform on the keypress and, in reverse, on keyrelease
#[derive(Debug, Clone, PartialEq)]
pub enum Action {
/// Switch to this view
SetView(View),
/// Switch to a view and latch
LockView {
lock: View,
/// When unlocked by pressing it or emitting a key
unlock: View,
},
/// Hold this modifier for as long as the button is pressed
ApplyModifier(Modifier),
/// Submit some text
Submit {
/// Text to submit with input-method.
/// If None, then keys are to be submitted instead.
text: Option<CString>,
/// The key events this symbol submits when submitting text is not possible
keys: Vec<KeySym>,
},
/// Erase a position behind the cursor
Erase,
ShowPreferences,
}
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,
}
}
}