diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2015-11-08 23:02:00 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2015-11-08 23:02:00 -0300 |
commit | acf4a04b7452b6dd2e69064b4f85144b8445bbe9 (patch) | |
tree | aef2d5caab26bab04b300ef232ca75578716fa7f /src/main.rs | |
download | dotwm-acf4a04b7452b6dd2e69064b4f85144b8445bbe9.tar.gz |
Initial commit
This initial commit has the following:
* We can spawn a terminal.
* Given a new window, we can move it around the screen, but only the
window that was created, all the other windows disappear on the void,
so.. :(
and that's it
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c89544d --- /dev/null +++ b/src/main.rs @@ -0,0 +1,75 @@ +extern crate libc; +extern crate x11; + +pub mod safe_x11; +pub mod command; +pub mod dotwm; +pub mod event; + +use dotwm::DotWM; +use command::exec_cmd; +use event::{Event,next_event}; +use std::ops::Deref; +use std::process; + +use x11::xlib; +use x11::keysym; + +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 +} + +fn move_win(wm: &DotWM, _: xlib::XEvent, args: &[String]) -> bool { + println!("Parsing x"); + let x = args[0].parse::<i32>().unwrap(); + println!("Parsing y"); + let y = args[1].parse::<i32>().unwrap(); + if let Some(ref win) = wm.current_window() { + win.move_offset(x, y); + }; + true +} + +fn quit_dotwm(_: &DotWM, _: xlib::XEvent, _: &[String]) -> bool { + process::exit(0); +} + +fn main() { + println!("Creating dotwm"); + let mut dotwm = DotWM::new(); + + dotwm.add_binding(keysym::XK_Return, xlib::Mod4Mask, exec, + &["xterm"]); + dotwm.add_binding(keysym::XK_h, xlib::Mod4Mask, move_win, &["-10", "0"]); + dotwm.add_binding(keysym::XK_j, xlib::Mod4Mask, move_win, &["0", "10"]); + dotwm.add_binding(keysym::XK_k, xlib::Mod4Mask, move_win, &["0", "-10"]); + dotwm.add_binding(keysym::XK_l, xlib::Mod4Mask, move_win, &["10", "0"]); + + dotwm.add_binding(keysym::XK_q, xlib::Mod4Mask | xlib::ShiftMask, quit_dotwm, &[]); + + // Main loop + loop { + let event = next_event(dotwm.display); + match event { + Event::Key(mut e, true) => { + let keysym = unsafe { xlib::XLookupKeysym(&mut e, 0) as u32 }; + let mask = e.state; + + dotwm.exec_func(keysym, mask, xlib::XEvent::from(e)); + }, + Event::Create(e) => { + // XCreateWindowEvent + let create_event = xlib::XCreateWindowEvent::from(e); + dotwm.add_window(create_event.window); + } + _ => println!("Catched event! {:?}", event), + } + } +} |