1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// See LICENSE file for copyright and license details.
pub mod parser;
use std::sync::mpsc::{Receiver, TryRecvError};
use std::os::unix::net::UnixStream;
use dotwm::DotWM;
use command::*;
#[derive(Debug,PartialEq)]
pub enum FnType {
BindKey,
BindButton,
Exec,
}
pub struct ParsedCmd<'a> {
pub f: FnType,
pub modifiers: Vec<u32>,
pub key: u32,
pub args: Vec<&'a str>,
pub func: ExecFn,
}
impl<'a> ParsedCmd<'a> {
pub fn handle(self, wm: &mut DotWM, bindings: &mut BindingHash) {
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);
},
_ => {},
}
}
}
pub fn next_socket_event(rx: &Receiver<UnixStream>) -> Option<UnixStream> {
match rx.try_recv() {
Ok(stream) => Some(stream),
Err(TryRecvError::Empty) => None,
Err(TryRecvError::Disconnected) => panic!("Socket disconnected"),
}
}
|