aboutsummaryrefslogtreecommitdiff
path: root/src/socket/parser.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2016-09-04 14:01:37 -0300
committerMatias Linares <matiaslina@openmailbox.org>2016-09-04 14:01:37 -0300
commit5bcdb566c69523edb1ceb857cbf6d0a676cc318d (patch)
treed3506fee02510999128fdfb5ec6a84ca99c9962b /src/socket/parser.rs
parent67306a1f063f15bc8127cdc2f72f971f2d06dd69 (diff)
downloaddotwm-5bcdb566c69523edb1ceb857cbf6d0a676cc318d.tar.gz
Add Mouse drag support.
This concludes the first 'release' :p.
Diffstat (limited to 'src/socket/parser.rs')
-rw-r--r--src/socket/parser.rs46
1 files changed, 44 insertions, 2 deletions
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);
+ }
+}