summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 21133ef..c9cc11e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -23,35 +23,26 @@ use x11::xlib;
use x11::xlib::XEvent;
use x11::keysym;
+use std::fs;
use std::io::{Read,Write};
use unix_socket::UnixListener;
+const SOCKET_PATH: &'static str = "./dotwm.sock";
+
fn main() {
println!("Creating dotwm");
let mut dotwm = DotWM::new();
let mut bindings: BindingHash = HashMap::new();
let x11_fd = safe_x11::x11_fd(dotwm.display);
- // Resize
- add_binding(&mut dotwm,&mut bindings, keysym::XK_h, xlib::Mod4Mask | xlib::ControlMask,
- resize_win, &["-10", "0"]);
- add_binding(&mut dotwm,&mut bindings, keysym::XK_j, xlib::Mod4Mask | xlib::ControlMask,
- resize_win, &["0", "10"]);
- add_binding(&mut dotwm,&mut bindings, keysym::XK_k, xlib::Mod4Mask | xlib::ControlMask,
- resize_win, &["0", "-10"]);
- 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 listener = UnixListener::bind("./dotwm.sock").unwrap();
+ let listener = UnixListener::bind(SOCKET_PATH).unwrap();
exec_cmd("./autostart", &[]).unwrap();
// Main loop
- loop {
+ while !dotwm.finish {
let event = unsafe { select_event(dotwm.display, x11_fd, &listener) };
match event {
Event::Key(mut e, true) => {
@@ -84,12 +75,22 @@ fn main() {
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);
+ let res = parser::parse(&line);
+ match res {
+ Ok(pcmd) => {
+ pcmd.handle(&mut dotwm, &mut bindings);
+ let _ = write!(s, "+ok");
+ },
+ Err(e) => {
+ let _ = write!(s, "-{}", e);
+ },
+ }
}
},
_ => println!("Unknown event"),
}
collect_zombies();
}
+
+ let _ = fs::remove_file(SOCKET_PATH);
}