diff options
Diffstat (limited to 'src/socket')
-rw-r--r-- | src/socket/mod.rs | 22 | ||||
-rw-r--r-- | src/socket/parser.rs | 46 |
2 files changed, 60 insertions, 8 deletions
diff --git a/src/socket/mod.rs b/src/socket/mod.rs index c29db2b..6ee1c09 100644 --- a/src/socket/mod.rs +++ b/src/socket/mod.rs @@ -11,7 +11,8 @@ use command::*; #[derive(Debug,PartialEq)] pub enum FnType { - Bind, + BindKey, + BindButton, Exec, } @@ -25,11 +26,20 @@ pub struct ParsedCmd<'a> { impl<'a> ParsedCmd<'a> { pub fn handle(self, wm: &mut DotWM, bindings: &mut BindingHash) { - if self.f == FnType::Bind { - let modifier: u32 = self.modifiers.iter() - .fold(0, |acc, x| acc | x ); - add_binding(wm, bindings, - self.key, modifier, self.func, &self.args); + match self.f { + FnType::BindKey => { + let modifier: u32 = self.modifiers.iter() + .fold(0, |acc, x| acc | x ); + add_binding(wm, bindings, + self.key, modifier, self.func, &self.args); + }, + FnType::BindButton => { + let modifier: u32 = self.modifiers.iter() + .fold(0, |acc, x| acc | x); + add_button_binding(wm, bindings, self.key, + modifier, self.func, &self.args); + }, + _ => {}, } } } diff --git a/src/socket/parser.rs b/src/socket/parser.rs index e475962..0989aec 100644 --- a/src/socket/parser.rs +++ b/src/socket/parser.rs @@ -44,6 +44,15 @@ fn modifiers<'a>(s: &'a str) -> Result<Vec<u32>, &'static str> { Ok(result) } +fn button<'a>(s: &'a str) -> Result<u32, &'static str> { + match s { + "button1" => Ok(xlib::Button1), + "button2" => Ok(xlib::Button2), + "button3" => Ok(xlib::Button3), + _ => Err("unknown button") + } +} + fn key<'a>(s: &'a str) -> Result<u32, &'static str> { match s { "a" => Ok(keysym::XK_a), @@ -102,7 +111,10 @@ fn key<'a>(s: &'a str) -> Result<u32, &'static str> { "2" => Ok(keysym::XK_2), "Tab" => Ok(keysym::XK_Tab), "Return" => Ok(keysym::XK_Return), - _ => Err("unknown key"), + e => { + println!("Unknown Key {}", e); + Err("Unknown key") + }, } } @@ -112,6 +124,7 @@ fn func<'a>(s: &'a str) -> Result<ExecFn, &'static str> { "move-win" => Ok(move_win), "move-win-to" => Ok(move_win_to), "move-win-sticky" => Ok(move_win_sticky), + "move-win-drag" => Ok(move_win_drag), "resize-win" => Ok(resize_win), "resize-win-sticky" => Ok(resize_win_sticky), "focus-next" => Ok(focus_next), @@ -137,7 +150,25 @@ pub fn parse<'a>(input: &'a str) -> Result<ParsedCmd<'a>, &'static str> { let arguments: &[&'a str]= &args[4..]; Ok(ParsedCmd { - f: FnType::Bind, + f: FnType::BindKey, + modifiers: modifiers, + key: key, + args: arguments.to_vec(), + func: func, + }) + } else { + Err("missing arguments") + } + }, + "bind-button" => { + if args.len() > 2 { + let modifiers = simple_try!(modifiers(args[1])); + let key = simple_try!(button(args[2])); + let func = simple_try!(func(args[3])); + let arguments: &[&'a str] = &args[4..]; + + Ok(ParsedCmd { + f: FnType::BindButton, modifiers: modifiers, key: key, args: arguments.to_vec(), @@ -218,3 +249,14 @@ fn parse_exec() { assert!(false); } } + +#[test] +fn parse_button() { + let res = parse("bind-button Mod4 button1 move-win-drag"); + + if let Ok(pcmd) = res { + assert_eq!(pcmd.f, FnType::BindButton); + } else { + assert!(false); + } +} |