From e1ec354306742a5804a20e2651cf49945cd17287 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 28 Nov 2015 22:16:43 -0300 Subject: Better socket handling The socket interface now allows almost everything that vould be done by the internals of the window manager. Also the Window manager now closes fine (on a success exit). --- src/command.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/command.rs') diff --git a/src/command.rs b/src/command.rs index 3bebc52..0ccee17 100644 --- a/src/command.rs +++ b/src/command.rs @@ -7,7 +7,6 @@ use std::ffi::OsStr; use std::io::Result; use std::ops::Deref; use std::process::{Command,Child}; -use std::process; use std::ptr; use libc::c_int; @@ -47,6 +46,7 @@ pub type ExecFn = fn(&mut DotWM, XEvent, &[String]) -> bool; /// Map for keys => functions pub type BindingHash = HashMap<(u32, u32), (ExecFn, Vec)>; +/// Exec a binding function. pub 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)) { let v = args.clone(); @@ -54,6 +54,7 @@ pub fn exec_func(wm: &mut DotWM, bindings: &mut BindingHash, key: u32, modifiers } } +/// Exec a external function pub fn exec(_: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { if let Some(program) = args.first() { let mut prog_args = vec![]; @@ -65,6 +66,7 @@ pub fn exec(_: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { true } +/// Move the window to a relative position pub fn move_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { let x = args[0].parse::().unwrap(); let y = args[1].parse::().unwrap(); @@ -74,6 +76,24 @@ pub fn move_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { true } +/// Move the window to an absolute position. +pub fn move_win_to(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { + let x = args[0].parse::().unwrap(); + let y = args[1].parse::().unwrap(); + if let Some(ref win) = wm.current_window() { + match win.move_to(x, y) { + Ok(()) => true, + Err(e) => { + println!("{}", e); + false + } + } + } else { + true + } +} + +/// Resize the window certain amount in x and y. pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { let w = args[0].parse::().unwrap(); let h = args[1].parse::().unwrap(); @@ -85,13 +105,16 @@ pub fn resize_win(wm: &mut DotWM, _: xlib::XEvent, args: &[String]) -> bool { true } +/// Focus the next window on the list pub fn focus_next(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool { wm.focus_next(); true } -pub fn quit_dotwm(_: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool { - process::exit(0); +/// Tells the window manager that is time to exit. +pub fn quit_dotwm(wm: &mut DotWM, _: xlib::XEvent, _: &[String]) -> bool { + wm.finish = true; + true } /// Add a binding to the WM. -- cgit v1.2.3-54-g00ecf