summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-28 22:16:43 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-28 22:16:43 -0300
commite1ec354306742a5804a20e2651cf49945cd17287 (patch)
tree7f607096fa43f96680d933b7a046f603227e566c /src/main.rs
parent901d03b3a8ac0b7d8533fd9a8d43238d665d9cb8 (diff)
downloaddotwm-e1ec354306742a5804a20e2651cf49945cd17287.tar.gz
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).
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);
}