Commit ef38fd3e authored by Dorota Czaplejewicz's avatar Dorota Czaplejewicz
Browse files

symbol: Eliminate in favor of Action

parent 46d3312c
......@@ -319,7 +319,7 @@ impl Layout {
pressed: false,
locked: false,
keycode: keycodes.get(*name).map(|k| *k),
symbol: create_symbol(
action: create_action(
&self.buttons,
name,
self.views.keys().collect()
......@@ -380,11 +380,11 @@ impl Layout {
}
}
fn create_symbol(
fn create_action(
button_info: &HashMap<String, ButtonMeta>,
name: &str,
view_names: Vec<&String>,
) -> ::symbol::Symbol {
) -> ::symbol::Action {
let default_meta = ButtonMeta::default();
let symbol_meta = button_info.get(name)
.unwrap_or(&default_meta);
......@@ -440,34 +440,28 @@ fn create_symbol(
};
match &symbol_meta.action {
Some(Action::SetView(view_name)) => ::symbol::Symbol {
action: ::symbol::Action::SetLevel(
filter_view_name(name, view_name.clone(), &view_names)
Some(Action::SetView(view_name)) => ::symbol::Action::SetLevel(
filter_view_name(name, view_name.clone(), &view_names)
),
Some(Action::Locking {
lock_view, unlock_view
}) => ::symbol::Action::LockLevel {
lock: filter_view_name(name, lock_view.clone(), &view_names),
unlock: filter_view_name(
name,
unlock_view.clone(),
&view_names
),
},
Some(Action::Locking { lock_view, unlock_view }) => ::symbol::Symbol {
action: ::symbol::Action::LockLevel {
lock: filter_view_name(name, lock_view.clone(), &view_names),
unlock: filter_view_name(
name,
unlock_view.clone(),
&view_names
),
},
},
Some(Action::ShowPrefs) => ::symbol::Symbol {
action: ::symbol::Action::Submit {
text: None,
keys: Vec::new(),
},
Some(Action::ShowPrefs) => ::symbol::Action::Submit {
text: None,
keys: Vec::new(),
},
None => ::symbol::Symbol {
action: ::symbol::Action::Submit {
text: None,
keys: vec!(
::symbol::KeySym(keysym.unwrap()),
),
},
None => ::symbol::Action::Submit {
text: None,
keys: vec!(
::symbol::KeySym(keysym.unwrap()),
),
},
}
}
......@@ -674,7 +668,7 @@ mod tests {
#[test]
fn test_key_unicode() {
assert_eq!(
create_symbol(
create_action(
&hashmap!{
".".into() => ButtonMeta {
icon: None,
......@@ -687,11 +681,9 @@ mod tests {
".",
Vec::new()
),
::symbol::Symbol {
action: ::symbol::Action::Submit {
text: None,
keys: vec!(::symbol::KeySym("U002E".into())),
},
::symbol::Action::Submit {
text: None,
keys: vec!(::symbol::KeySym("U002E".into())),
}
);
}
......
......@@ -7,7 +7,7 @@ use std::io;
use std::rc::Rc;
use std::string::FromUtf8Error;
use ::symbol::{ Symbol, Action };
use ::symbol::Action;
use std::io::Write;
use std::iter::{ FromIterator, IntoIterator };
......@@ -73,7 +73,8 @@ pub struct KeyState {
pub pressed: bool,
pub locked: bool,
pub keycode: Option<u32>,
pub symbol: Symbol,
/// Static description of what the key does when pressed or released
pub action: Action,
}
/// Generates a mapping where each key gets a keycode, starting from 8
......@@ -124,7 +125,7 @@ pub fn generate_keymap(
for (name, state) in keystates.iter() {
let state = state.borrow();
if let ::symbol::Action::Submit { text: _, keys } = &state.symbol.action {
if let ::symbol::Action::Submit { text: _, keys } = &state.action {
match keys.len() {
0 => eprintln!("Key {} has no keysyms", name),
a => {
......@@ -156,7 +157,7 @@ pub fn generate_keymap(
)?;
for (name, state) in keystates.iter() {
if let ::symbol::Action::Submit { text: _, keys } = &state.borrow().symbol.action {
if let ::symbol::Action::Submit { text: _, keys } = &state.borrow().action {
if let Some(keysym) = keys.iter().next() {
write!(
buf,
......
......@@ -268,7 +268,7 @@ pub mod c {
) {
let layout = unsafe { &mut *layout };
let view_name = match key.to_owned().symbol.action {
let view_name = match key.to_owned().action {
::symbol::Action::SetLevel(name) => {
Some(name.clone())
},
......@@ -485,9 +485,7 @@ pub mod c {
pressed: false,
locked: false,
keycode: None,
symbol: Symbol {
action: Action::SetLevel("default".into()),
}
action: Action::SetLevel("default".into()),
}))
}
......
......@@ -37,10 +37,3 @@ pub enum Action {
keys: Vec<KeySym>,
},
}
/// Contains a static description of a particular key's actions
#[derive(Debug, Clone, PartialEq)]
pub struct Symbol {
/// The action that this key performs
pub action: Action,
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment