summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-15 19:07:57 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-15 19:07:57 -0300
commit12af9d3ec0d55c258d10e73e8fe6a99f3c9f05ff (patch)
treef7a22b899d714902a07da2f3d66cb0c4261bb6d6 /src/main.rs
parent9eb8d5c3e10bda16c9edf5e8f430662a6c404093 (diff)
downloaddotwm-12af9d3ec0d55c258d10e73e8fe6a99f3c9f05ff.tar.gz
Move exec and add binding to the main.
The bindings don't need to be handled on the window manager This would be useful for the client/server feature.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 17 insertions, 1 deletions
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);