aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2016-09-04 15:10:49 -0300
committerMatias Linares <matiaslina@openmailbox.org>2016-09-04 15:10:49 -0300
commitfec7616b482224244d07900533ea160bf8997b2b (patch)
tree95c480fbf373fbc581e4ddfc348a24fbc331f8af
parent5bcdb566c69523edb1ceb857cbf6d0a676cc318d (diff)
downloaddotwm-fec7616b482224244d07900533ea160bf8997b2b.tar.gz
Better path handling for socket
-rw-r--r--Cargo.lock2
-rwxr-xr-xautostart3
-rw-r--r--src/main.rs37
3 files changed, 32 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 30cd182..8548148 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/autostart b/autostart
index 359934d..cc7db20 100755
--- a/autostart
+++ b/autostart
@@ -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);
}