diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rwxr-xr-x | autostart | 3 | ||||
-rw-r--r-- | src/main.rs | 37 |
3 files changed, 32 insertions, 10 deletions
@@ -1,6 +1,6 @@ [root] name = "dotwm" -version = "0.2.0" +version = "0.1.0" dependencies = [ "clippy 0.0.71 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1,8 +1,9 @@ #!/bin/bash +SOCKET=${HOME}/.config/dotwm/dotwm.sock dot() { # Using BSD netcat - printf "%s " $@ | netcat -U dotwm.sock + printf "%s " $@ | netcat -U ${SOCKET} } # nitrogen --restore & diff --git a/src/main.rs b/src/main.rs index f745e92..31d0423 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,17 +29,37 @@ use x11::xlib; use x11::keysym; use std::fs; +use std::env; +use std::path::{PathBuf}; use std::io::{Read,Write}; use unix_socket::UnixListener; -const SOCKET_PATH: &'static str = "./dotwm.sock"; +fn dotwm_dir() -> PathBuf { + let mut path = env::home_dir().unwrap(); + path.push(".config"); + path.push("dotwm"); + + if !path.exists() && !path.is_dir() { + fs::create_dir(&path).unwrap(); + } + + path +} + +fn socket_path() -> PathBuf { + let mut path = dotwm_dir(); + path.push("dotwm.sock"); + path +} fn run_autostart() { - let paths = &["./autostart", "/home/matias/.config/dotwm/autostart"]; - for path in paths { - if exec_cmd(path, &[]).is_ok() { - break; - } + let mut autostart = dotwm_dir(); + autostart.push("autostart"); + + let found = exec_cmd(autostart, &[]).is_ok(); + + if !found { + exec_cmd("./autostart", &[]).unwrap(); } } @@ -51,7 +71,8 @@ fn main() { add_binding(&mut dotwm, &mut bindings, keysym::XK_q, xlib::Mod4Mask | xlib::ShiftMask, quit_dotwm, &[]); - let listener = UnixListener::bind(SOCKET_PATH).unwrap(); + let sp = socket_path(); + let listener = UnixListener::bind(&sp).unwrap(); run_autostart(); @@ -115,5 +136,5 @@ fn main() { collect_zombies(); } - let _ = fs::remove_file(SOCKET_PATH); + let _ = fs::remove_file(sp); } |