aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs37
1 files changed, 29 insertions, 8 deletions
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);
}