tony / oxwm

removed unneeded functions, fixed recompile function (again?) Browse files
tonybanters committed 2025-10-13 parent 40d6e3c commit 23924cf9fdf6760d548df83e4d96e24c69ec8533
Showing 4 changed files with 18 additions and 121 deletions. UnifiedSplit
+1 −1 Cargo.lock
@@ -213,7 +213,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
213 213
214 [[package]] 214 [[package]]
215 name = "oxwm" 215 name = "oxwm"
216 -version = "0.1.1" 216 +version = "0.1.11"
217 dependencies = [ 217 dependencies = [
218 "anyhow", 218 "anyhow",
219 "chrono", 219 "chrono",
+1 −1 Cargo.toml
@@ -1,6 +1,6 @@
1 [package] 1 [package]
2 name = "oxwm" 2 name = "oxwm"
3 -version = "0.1.1" 3 +version = "0.1.11"
4 edition = "2024" 4 edition = "2024"
5 5
6 [lib] 6 [lib]
+10 −24 src/bin/main.rs
@@ -26,24 +26,16 @@ fn main() -> Result<()> {
26 _ => {} 26 _ => {}
27 } 27 }
28 28
29 - let user_binary = get_user_binary_path(); 29 + let config_dir = get_config_path();
30 - let config_path = get_config_path().join("config.rs"); 30 + let user_bin = config_dir.join("target/release/oxwm-user");
31 -
32 - if config_path.exists() && user_binary.exists() {
33 - if !should_recompile(&config_path, &user_binary)? {
34 - use std::os::unix::process::CommandExt;
35 - let err = std::process::Command::new(&user_binary)
36 - .args(&args[1..])
37 - .exec();
38 - eprintln!("Failed to exec user binary: {}", err);
39 - std::process::exit(1);
40 - }
41 - }
42 31
43 - if !config_path.exists() { 32 + if user_bin.exists() {
44 - eprintln!("No config found, creating default at ~/.config/oxwm/config.rs"); 33 + use std::os::unix::process::CommandExt;
45 - init_config()?; 34 + let err = std::process::Command::new(&user_bin)
46 - eprintln!("✓ Edit ~/.config/oxwm/config.rs and run 'oxwm --recompile'"); 35 + .args(&args[1..])
36 + .exec();
37 + eprintln!("Failed to exec user binary: {}", err);
38 + std::process::exit(1);
47 } 39 }
48 40
49 let config = oxwm::Config::default(); 41 let config = oxwm::Config::default();
@@ -175,13 +167,7 @@ fn recompile_config() -> Result<()> {
175 anyhow::bail!("Failed to compile configuration"); 167 anyhow::bail!("Failed to compile configuration");
176 } 168 }
177 169
178 - let source = config_dir.join("target/release/oxwm-user"); 170 + println!("✓ Compiled successfully.");
179 - let dest = get_user_binary_path();
180 -
181 - std::fs::create_dir_all(dest.parent().unwrap())?;
182 - std::fs::copy(&source, &dest)?;
183 -
184 - println!("✓ Compiled successfully to {}", dest.display());
185 println!(" Restart oxwm to use new config"); 171 println!(" Restart oxwm to use new config");
186 172
187 Ok(()) 173 Ok(())
+6 −95 src/window_manager.rs
@@ -300,72 +300,9 @@ impl WindowManager {
300 } 300 }
301 301
302 fn handle_restart(&self) -> Result<bool> { 302 fn handle_restart(&self) -> Result<bool> {
303 - let user_binary = get_config_path().join("oxwm-user");
304 -
305 - if user_binary.exists() && self.needs_recompile()? {
306 - println!("Config changed, recompiling...");
307 - self.recompile()?;
308 - }
309 -
310 Ok(true) 303 Ok(true)
311 } 304 }
312 305
313 - fn needs_recompile(&self) -> Result<bool> {
314 - let config_dir = get_config_path();
315 - let binary_path = get_user_binary_path();
316 -
317 - if !binary_path.exists() {
318 - return Ok(true);
319 - }
320 -
321 - let binary_time = std::fs::metadata(&binary_path)?.modified()?;
322 -
323 - let watch_files = ["config.rs", "main.rs", "Cargo.toml"];
324 -
325 - for filename in &watch_files {
326 - let path = config_dir.join(filename);
327 - if !path.exists() {
328 - continue;
329 - }
330 -
331 - let file_time = std::fs::metadata(&path)?.modified()?;
332 - if file_time > binary_time {
333 - println!("✓ Change detected: {}", filename);
334 - return Ok(true);
335 - }
336 - }
337 -
338 - Ok(false)
339 - }
340 -
341 - fn recompile(&self) -> Result<()> {
342 - let config_dir = get_config_path();
343 -
344 - notify("OXWM", "Recompiling configuration...");
345 -
346 - let output = std::process::Command::new("cargo")
347 - .args(&["build", "--release"])
348 - .current_dir(&config_dir)
349 - .output()?;
350 -
351 - if !output.status.success() {
352 - let stderr = String::from_utf8_lossy(&output.stderr);
353 - notify_error("OXWM Compile Error", &stderr);
354 - eprintln!("Compilation failed:\n{}", stderr);
355 - anyhow::bail!("Failed to compile configuration");
356 - }
357 -
358 - let source = config_dir.join("target/release/oxwm-user");
359 - let dest = get_user_binary_path();
360 -
361 - std::fs::create_dir_all(dest.parent().unwrap())?;
362 - std::fs::copy(&source, &dest)?;
363 -
364 - notify("OXWM", "Recompiled successfully! Restarting...");
365 -
366 - Ok(())
367 - }
368 -
369 pub fn run(&mut self) -> Result<bool> { 306 pub fn run(&mut self) -> Result<bool> {
370 println!("oxwm started on display {}", self.screen_number); 307 println!("oxwm started on display {}", self.screen_number);
371 308
@@ -462,8 +399,12 @@ impl WindowManager {
462 // Handled in handle_event 399 // Handled in handle_event
463 } 400 }
464 KeyAction::Recompile => { 401 KeyAction::Recompile => {
465 - if let Err(e) = self.recompile() { 402 + match std::process::Command::new("oxwm")
466 - eprintln!("Recompile failed: {}", e); 403 + .arg("--recompile")
404 + .spawn()
405 + {
406 + Ok(_) => eprintln!("Recompiling in background"),
407 + Err(e) => eprintln!("Failed to spawn recompile: {}", e),
467 } 408 }
468 } 409 }
469 KeyAction::ViewTag => { 410 KeyAction::ViewTag => {
@@ -924,33 +865,3 @@ impl WindowManager {
924 Ok(()) 865 Ok(())
925 } 866 }
926 } 867 }
927 -
928 -fn get_config_path() -> PathBuf {
929 - dirs::config_dir()
930 - .expect("Could not find config directory")
931 - .join("oxwm")
932 -}
933 -
934 -fn get_user_binary_path() -> PathBuf {
935 - get_config_path().join("oxwm-user")
936 -}
937 -
938 -fn can_recompile() -> bool {
939 - std::process::Command::new("cargo")
940 - .arg("--version")
941 - .output()
942 - .map(|o| o.status.success())
943 - .unwrap_or(false)
944 -}
945 -
946 -fn notify(title: &str, body: &str) {
947 - let _ = std::process::Command::new("notify-send")
948 - .args(&[title, body])
949 - .spawn();
950 -}
951 -
952 -fn notify_error(title: &str, body: &str) {
953 - let _ = std::process::Command::new("notify-send")
954 - .args(&["-u", "critical", title, body])
955 - .spawn();
956 -}