diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/main.rs b/src/main.rs index d871288..cd64f87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,8 @@ pub mod socket; use dotwm::DotWM; use command::*; -use event::{Event,next_event}; -use socket::listen_socket; -use safe_x11::event as x11_event; +use event::{Event,select_event}; +use socket::parser; use std::collections::HashMap; @@ -22,15 +21,15 @@ use x11::xlib; use x11::xlib::XEvent; use x11::keysym; -use std::thread; -use std::sync::mpsc::channel; +use std::os::unix::io::AsRawFd; +use std::io::{Read,Write}; use unix_socket::UnixListener; fn main() { println!("Creating dotwm"); let mut dotwm = DotWM::new(); let mut bindings: BindingHash = HashMap::new(); - let x11_fd = x11_event::x11_fd(dotwm.display); + let x11_fd = safe_x11::x11_fd(dotwm.display); // Resize add_binding(&mut dotwm,&mut bindings, keysym::XK_h, xlib::Mod4Mask | xlib::ControlMask, @@ -42,33 +41,18 @@ fn main() { add_binding(&mut dotwm,&mut bindings, keysym::XK_l, xlib::Mod4Mask | xlib::ControlMask, resize_win, &["10", "0"]); + add_binding(&mut dotwm,&mut bindings, keysym::XK_Return, xlib::Mod4Mask, exec, &["xterm"]); add_binding(&mut dotwm,&mut bindings, keysym::XK_Tab, xlib::Mod4Mask, focus_next, &[]); add_binding(&mut dotwm, &mut bindings, keysym::XK_q, xlib::Mod4Mask | xlib::ShiftMask, quit_dotwm, &[]); - let (transmission, receiver) = channel(); - - thread::spawn(move || { - println!("Creating socket"); - let listener = UnixListener::bind("./dotwm.sock").unwrap(); - - for stream in listener.incoming() { - match stream { - Ok(stream) => transmission.send(stream).unwrap() , - Err(e) => println!("{}", e), - } - } - }); + let listener = UnixListener::bind("./dotwm.sock").unwrap(); + let socket_fd = listener.as_raw_fd(); exec_cmd("./autostart", &[]).unwrap(); // Main loop loop { - println!("Listening socket"); - listen_socket(&mut dotwm, &mut bindings, &receiver); - // Event handling. - println!("Waiting event"); - let event = next_event(dotwm.display, x11_fd); - println!("Event {:?}", event); + let event = unsafe { select_event(dotwm.display, x11_fd, socket_fd, &listener) }; match event { Event::Key(mut e, true) => { let keysym = unsafe { xlib::XLookupKeysym(&mut e, 0) as u32 }; @@ -81,7 +65,6 @@ fn main() { // be handled by the wm. let map_event = xlib::XMapEvent::from(e); if map_event.override_redirect == 0 { - println!("Adding window"); dotwm.add_window(map_event.window); } else { println!("Map event 0 :("); @@ -95,6 +78,16 @@ fn main() { dotwm.change_focus_of(idx); } }, + Event::Socket(stream) => { + let mut s = stream.try_clone().unwrap(); + let mut buf = String::new(); + s.read_to_string(&mut buf).unwrap(); + + for line in buf.lines() { + let result = parser::parse(&mut dotwm, &mut bindings, &line); + let _ = write!(s, "{}", result); + } + }, _ => println!("Unknown event"), } collect_zombies(); |