symbol: Eliminate in favor of Action
This commit is contained in:
		
							
								
								
									
										60
									
								
								src/data.rs
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								src/data.rs
									
									
									
									
									
								
							@ -319,7 +319,7 @@ impl Layout {
 | 
				
			|||||||
                pressed: false,
 | 
					                pressed: false,
 | 
				
			||||||
                locked: false,
 | 
					                locked: false,
 | 
				
			||||||
                keycode: keycodes.get(*name).map(|k| *k),
 | 
					                keycode: keycodes.get(*name).map(|k| *k),
 | 
				
			||||||
                symbol: create_symbol(
 | 
					                action: create_action(
 | 
				
			||||||
                    &self.buttons,
 | 
					                    &self.buttons,
 | 
				
			||||||
                    name,
 | 
					                    name,
 | 
				
			||||||
                    self.views.keys().collect()
 | 
					                    self.views.keys().collect()
 | 
				
			||||||
@ -380,11 +380,11 @@ impl Layout {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn create_symbol(
 | 
					fn create_action(
 | 
				
			||||||
    button_info: &HashMap<String, ButtonMeta>,
 | 
					    button_info: &HashMap<String, ButtonMeta>,
 | 
				
			||||||
    name: &str,
 | 
					    name: &str,
 | 
				
			||||||
    view_names: Vec<&String>,
 | 
					    view_names: Vec<&String>,
 | 
				
			||||||
) -> ::symbol::Symbol {
 | 
					) -> ::symbol::Action {
 | 
				
			||||||
    let default_meta = ButtonMeta::default();
 | 
					    let default_meta = ButtonMeta::default();
 | 
				
			||||||
    let symbol_meta = button_info.get(name)
 | 
					    let symbol_meta = button_info.get(name)
 | 
				
			||||||
        .unwrap_or(&default_meta);
 | 
					        .unwrap_or(&default_meta);
 | 
				
			||||||
@ -440,34 +440,28 @@ fn create_symbol(
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    match &symbol_meta.action {
 | 
					    match &symbol_meta.action {
 | 
				
			||||||
        Some(Action::SetView(view_name)) => ::symbol::Symbol {
 | 
					        Some(Action::SetView(view_name)) => ::symbol::Action::SetLevel(
 | 
				
			||||||
            action: ::symbol::Action::SetLevel(
 | 
					            filter_view_name(name, view_name.clone(), &view_names)
 | 
				
			||||||
                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 {
 | 
					        Some(Action::ShowPrefs) => ::symbol::Action::Submit {
 | 
				
			||||||
            action: ::symbol::Action::LockLevel {
 | 
					            text: None,
 | 
				
			||||||
                lock: filter_view_name(name, lock_view.clone(), &view_names),
 | 
					            keys: Vec::new(),
 | 
				
			||||||
                unlock: filter_view_name(
 | 
					 | 
				
			||||||
                    name,
 | 
					 | 
				
			||||||
                    unlock_view.clone(),
 | 
					 | 
				
			||||||
                    &view_names
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        Some(Action::ShowPrefs) => ::symbol::Symbol {
 | 
					        None => ::symbol::Action::Submit {
 | 
				
			||||||
            action: ::symbol::Action::Submit {
 | 
					            text: None,
 | 
				
			||||||
                text: None,
 | 
					            keys: vec!(
 | 
				
			||||||
                keys: Vec::new(),
 | 
					                ::symbol::KeySym(keysym.unwrap()),
 | 
				
			||||||
            },
 | 
					            ),
 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
        None => ::symbol::Symbol {
 | 
					 | 
				
			||||||
            action: ::symbol::Action::Submit {
 | 
					 | 
				
			||||||
                text: None,
 | 
					 | 
				
			||||||
                keys: vec!(
 | 
					 | 
				
			||||||
                    ::symbol::KeySym(keysym.unwrap()),
 | 
					 | 
				
			||||||
                ),
 | 
					 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -674,7 +668,7 @@ mod tests {
 | 
				
			|||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn test_key_unicode() {
 | 
					    fn test_key_unicode() {
 | 
				
			||||||
        assert_eq!(
 | 
					        assert_eq!(
 | 
				
			||||||
            create_symbol(
 | 
					            create_action(
 | 
				
			||||||
                &hashmap!{
 | 
					                &hashmap!{
 | 
				
			||||||
                    ".".into() => ButtonMeta {
 | 
					                    ".".into() => ButtonMeta {
 | 
				
			||||||
                        icon: None,
 | 
					                        icon: None,
 | 
				
			||||||
@ -687,11 +681,9 @@ mod tests {
 | 
				
			|||||||
                ".",
 | 
					                ".",
 | 
				
			||||||
                Vec::new()
 | 
					                Vec::new()
 | 
				
			||||||
            ),
 | 
					            ),
 | 
				
			||||||
            ::symbol::Symbol {
 | 
					            ::symbol::Action::Submit {
 | 
				
			||||||
                action: ::symbol::Action::Submit {
 | 
					                text: None,
 | 
				
			||||||
                    text: None,
 | 
					                keys: vec!(::symbol::KeySym("U002E".into())),
 | 
				
			||||||
                    keys: vec!(::symbol::KeySym("U002E".into())),
 | 
					 | 
				
			||||||
                },
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,7 @@ use std::io;
 | 
				
			|||||||
use std::rc::Rc;
 | 
					use std::rc::Rc;
 | 
				
			||||||
use std::string::FromUtf8Error;
 | 
					use std::string::FromUtf8Error;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
use ::symbol::{ Symbol, Action };
 | 
					use ::symbol::Action;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use std::io::Write;
 | 
					use std::io::Write;
 | 
				
			||||||
use std::iter::{ FromIterator, IntoIterator };
 | 
					use std::iter::{ FromIterator, IntoIterator };
 | 
				
			||||||
@ -73,7 +73,8 @@ pub struct KeyState {
 | 
				
			|||||||
    pub pressed: bool,
 | 
					    pub pressed: bool,
 | 
				
			||||||
    pub locked: bool,
 | 
					    pub locked: bool,
 | 
				
			||||||
    pub keycode: Option<u32>,
 | 
					    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
 | 
					/// 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() {
 | 
					    for (name, state) in keystates.iter() {
 | 
				
			||||||
        let state = state.borrow();
 | 
					        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() {
 | 
					            match keys.len() {
 | 
				
			||||||
                0 => eprintln!("Key {} has no keysyms", name),
 | 
					                0 => eprintln!("Key {} has no keysyms", name),
 | 
				
			||||||
                a => {
 | 
					                a => {
 | 
				
			||||||
@ -156,7 +157,7 @@ pub fn generate_keymap(
 | 
				
			|||||||
    )?;
 | 
					    )?;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    for (name, state) in keystates.iter() {
 | 
					    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() {
 | 
					            if let Some(keysym) = keys.iter().next() {
 | 
				
			||||||
                write!(
 | 
					                write!(
 | 
				
			||||||
                    buf,
 | 
					                    buf,
 | 
				
			||||||
 | 
				
			|||||||
@ -268,7 +268,7 @@ pub mod c {
 | 
				
			|||||||
        ) {
 | 
					        ) {
 | 
				
			||||||
            let layout = unsafe { &mut *layout };
 | 
					            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) => {
 | 
					                ::symbol::Action::SetLevel(name) => {
 | 
				
			||||||
                    Some(name.clone())
 | 
					                    Some(name.clone())
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
@ -485,9 +485,7 @@ pub mod c {
 | 
				
			|||||||
                pressed: false,
 | 
					                pressed: false,
 | 
				
			||||||
                locked: false,
 | 
					                locked: false,
 | 
				
			||||||
                keycode: None,
 | 
					                keycode: None,
 | 
				
			||||||
                symbol: Symbol {
 | 
					                action: Action::SetLevel("default".into()),
 | 
				
			||||||
                    action: Action::SetLevel("default".into()),
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }))
 | 
					            }))
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -37,10 +37,3 @@ pub enum Action {
 | 
				
			|||||||
        keys: Vec<KeySym>,
 | 
					        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,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user