summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotwm.rs41
-rw-r--r--src/main.rs18
2 files changed, 17 insertions, 42 deletions
diff --git a/src/dotwm.rs b/src/dotwm.rs
index 952fc8c..e94b17f 100644
--- a/src/dotwm.rs
+++ b/src/dotwm.rs
@@ -55,47 +55,6 @@ impl DotWM {
window_list: vec![],
}
}
-
- /// Add a binding to the WM.
- ///
- /// # Example
- ///
- /// ```
- /// fn exec(_: &DotWM, _: xlib::XEvent, args: &[String]) -> bool {
- /// if let Some(program) = args.first() {
- /// let mut prog_args = vec![];
- /// for arg in args[1..].iter() {
- /// prog_args.push(arg);
- /// }
- /// exec_cmd(program, prog_args.deref()).unwrap();
- /// }
- /// true
- /// }
- ///
- /// // ...
- ///
- /// dotwm.add_binding(keysym::XK_Return, xlib::Mod4Mask, exec,
- /// &["xterm"]);
- /// ```
- /*
- pub fn add_binding(&mut self, key: u32, modifiers: u32, func: ExecFn, args: &[&str]) {
- grab_key(self.display, key, modifiers, true, GrabModeAsync, GrabModeAsync);
- let mut v = vec![];
- for arg in args {
- v.push(arg.to_string());
- }
- self.bindings.insert((key, modifiers), (func, v));
- }
- */
-
- /*
- pub fn exec_func(&mut self, key: u32, modifiers: u32, ev: xlib::XEvent) {
- if let Some(&(func, ref args)) = self.bindings.get(&(key, modifiers)) {
- let v = args.clone();
- func(&self, ev, &v);
- }
- }
- */
pub fn add_window(&mut self, w: xlib::Window) {
self.unfocus_current_window();
diff --git a/src/main.rs b/src/main.rs
index 1374446..02df6fd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,7 +23,9 @@ use x11::keysym;
/// Defines a callback to call no certains events.
pub type ExecFn = fn(&mut DotWM, XEvent, &[String]) -> bool;
-type BindingHash = HashMap<(u32, u32), (ExecFn, Vec<String>)>;
+
+/// Map for keys => functions
+pub type BindingHash = HashMap<(u32, u32), (ExecFn, Vec<String>)>;
fn exec_func(wm: &mut DotWM, bindings: &mut BindingHash, key: u32, modifiers: u32, ev: xlib::XEvent) {
if let Some(&(func, ref args)) = bindings.get(&(key, modifiers)) {
@@ -72,6 +74,20 @@ fn quit_dotwm(_: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
process::exit(0);
}
+/// Add a binding to the WM.
+///
+/// # Example
+///
+/// ```
+/// fn quit_dotwm(_: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool {
+/// process::exit(0);
+/// }
+///
+/// // ...
+///
+/// add_binding(keysym::XK_Return, xlib::Mod4Mask, exec,
+/// &["xterm"]);
+/// ```
fn add_binding(wm: &mut DotWM, bindings: &mut BindingHash,
key: u32, modifiers: u32, func: ExecFn, args: &[&str]) {
grab_key(wm.display, key, modifiers, true, GrabModeAsync, GrabModeAsync);