From 5bcdb566c69523edb1ceb857cbf6d0a676cc318d Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 4 Sep 2016 14:01:37 -0300 Subject: Add Mouse drag support. This concludes the first 'release' :p. --- src/socket/mod.rs | 22 ++++++++++++++++------ src/socket/parser.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 8 deletions(-) (limited to 'src/socket') 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, &'static str> { Ok(result) } +fn button<'a>(s: &'a str) -> Result { + match s { + "button1" => Ok(xlib::Button1), + "button2" => Ok(xlib::Button2), + "button3" => Ok(xlib::Button3), + _ => Err("unknown button") + } +} + fn key<'a>(s: &'a str) -> Result { match s { "a" => Ok(keysym::XK_a), @@ -102,7 +111,10 @@ fn key<'a>(s: &'a str) -> Result { "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 { "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, &'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); + } +} -- cgit v1.2.3-70-g09d2