oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

removed unneeded functions, fixed recompile function (again?)

Commit
23924cf9fdf6760d548df83e4d96e24c69ec8533
Parent
40d6e3c
Author
tonybanters <tony@tonybtw.com>
Date
2025-10-13 18:26:31

Diff

diff --git a/Cargo.lock b/Cargo.lock
index f9e06ef..70c684a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -213,7 +213,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
 
 [[package]]
 name = "oxwm"
-version = "0.1.1"
+version = "0.1.11"
 dependencies = [
  "anyhow",
  "chrono",
diff --git a/Cargo.toml b/Cargo.toml
index 577ea56..a53158a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "oxwm"
-version = "0.1.1"
+version = "0.1.11"
 edition = "2024"
 
 [lib]
diff --git a/src/bin/main.rs b/src/bin/main.rs
index f2202aa..b3b6974 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -26,24 +26,16 @@ fn main() -> Result<()> {
         _ => {}
     }
 
-    let user_binary = get_user_binary_path();
-    let config_path = get_config_path().join("config.rs");
-
-    if config_path.exists() && user_binary.exists() {
-        if !should_recompile(&config_path, &user_binary)? {
-            use std::os::unix::process::CommandExt;
-            let err = std::process::Command::new(&user_binary)
-                .args(&args[1..])
-                .exec();
-            eprintln!("Failed to exec user binary: {}", err);
-            std::process::exit(1);
-        }
-    }
+    let config_dir = get_config_path();
+    let user_bin = config_dir.join("target/release/oxwm-user");
 
-    if !config_path.exists() {
-        eprintln!("No config found, creating default at ~/.config/oxwm/config.rs");
-        init_config()?;
-        eprintln!("✓ Edit ~/.config/oxwm/config.rs and run 'oxwm --recompile'");
+    if user_bin.exists() {
+        use std::os::unix::process::CommandExt;
+        let err = std::process::Command::new(&user_bin)
+            .args(&args[1..])
+            .exec();
+        eprintln!("Failed to exec user binary: {}", err);
+        std::process::exit(1);
     }
 
     let config = oxwm::Config::default();
@@ -175,13 +167,7 @@ fn recompile_config() -> Result<()> {
         anyhow::bail!("Failed to compile configuration");
     }
 
-    let source = config_dir.join("target/release/oxwm-user");
-    let dest = get_user_binary_path();
-
-    std::fs::create_dir_all(dest.parent().unwrap())?;
-    std::fs::copy(&source, &dest)?;
-
-    println!("✓ Compiled successfully to {}", dest.display());
+    println!("✓ Compiled successfully.");
     println!("  Restart oxwm to use new config");
 
     Ok(())
diff --git a/src/window_manager.rs b/src/window_manager.rs
index 1b2e4f3..7ba67d6 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -300,72 +300,9 @@ impl WindowManager {
     }
 
     fn handle_restart(&self) -> Result<bool> {
-        let user_binary = get_config_path().join("oxwm-user");
-
-        if user_binary.exists() && self.needs_recompile()? {
-            println!("Config changed, recompiling...");
-            self.recompile()?;
-        }
-
         Ok(true)
     }
 
-    fn needs_recompile(&self) -> Result<bool> {
-        let config_dir = get_config_path();
-        let binary_path = get_user_binary_path();
-
-        if !binary_path.exists() {
-            return Ok(true);
-        }
-
-        let binary_time = std::fs::metadata(&binary_path)?.modified()?;
-
-        let watch_files = ["config.rs", "main.rs", "Cargo.toml"];
-
-        for filename in &watch_files {
-            let path = config_dir.join(filename);
-            if !path.exists() {
-                continue;
-            }
-
-            let file_time = std::fs::metadata(&path)?.modified()?;
-            if file_time > binary_time {
-                println!("✓ Change detected: {}", filename);
-                return Ok(true);
-            }
-        }
-
-        Ok(false)
-    }
-
-    fn recompile(&self) -> Result<()> {
-        let config_dir = get_config_path();
-
-        notify("OXWM", "Recompiling configuration...");
-
-        let output = std::process::Command::new("cargo")
-            .args(&["build", "--release"])
-            .current_dir(&config_dir)
-            .output()?;
-
-        if !output.status.success() {
-            let stderr = String::from_utf8_lossy(&output.stderr);
-            notify_error("OXWM Compile Error", &stderr);
-            eprintln!("Compilation failed:\n{}", stderr);
-            anyhow::bail!("Failed to compile configuration");
-        }
-
-        let source = config_dir.join("target/release/oxwm-user");
-        let dest = get_user_binary_path();
-
-        std::fs::create_dir_all(dest.parent().unwrap())?;
-        std::fs::copy(&source, &dest)?;
-
-        notify("OXWM", "Recompiled successfully! Restarting...");
-
-        Ok(())
-    }
-
     pub fn run(&mut self) -> Result<bool> {
         println!("oxwm started on display {}", self.screen_number);
 
@@ -462,8 +399,12 @@ impl WindowManager {
                 // Handled in handle_event
             }
             KeyAction::Recompile => {
-                if let Err(e) = self.recompile() {
-                    eprintln!("Recompile failed: {}", e);
+                match std::process::Command::new("oxwm")
+                    .arg("--recompile")
+                    .spawn()
+                {
+                    Ok(_) => eprintln!("Recompiling in background"),
+                    Err(e) => eprintln!("Failed to spawn recompile: {}", e),
                 }
             }
             KeyAction::ViewTag => {
@@ -924,33 +865,3 @@ impl WindowManager {
         Ok(())
     }
 }
-
-fn get_config_path() -> PathBuf {
-    dirs::config_dir()
-        .expect("Could not find config directory")
-        .join("oxwm")
-}
-
-fn get_user_binary_path() -> PathBuf {
-    get_config_path().join("oxwm-user")
-}
-
-fn can_recompile() -> bool {
-    std::process::Command::new("cargo")
-        .arg("--version")
-        .output()
-        .map(|o| o.status.success())
-        .unwrap_or(false)
-}
-
-fn notify(title: &str, body: &str) {
-    let _ = std::process::Command::new("notify-send")
-        .args(&[title, body])
-        .spawn();
-}
-
-fn notify_error(title: &str, body: &str) {
-    let _ = std::process::Command::new("notify-send")
-        .args(&["-u", "critical", title, body])
-        .spawn();
-}