From acf4a04b7452b6dd2e69064b4f85144b8445bbe9 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 8 Nov 2015 23:02:00 -0300 Subject: 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 --- src/main.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main.rs (limited to 'src/main.rs') 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::().unwrap(); + println!("Parsing y"); + let y = args[1].parse::().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), + } + } +} -- cgit v1.2.3-54-g00ecf