tony / oxwm

Removed libc as a dep, and used a double-fork strategy to handle zombie processes instead of the dwm method due to shell being required as a hanging process for the bar. Browse files
tonybtw committed 2025-12-12 parent d5f7b65 commit d90e50dfcb3f6a12e59e0d221bf03147d43ec458
Showing 8 changed files with 37 additions and 66 deletions. UnifiedSplit
+0 −1 Cargo.lock
@@ -295,7 +295,6 @@ version = "0.8.1"
295 295 dependencies = [
296 296 "chrono",
297 297 "dirs",
298 - "libc",
299 298 "mlua",
300 299 "serde",
301 300 "x11",
+0 −1 Cargo.toml
@@ -18,4 +18,3 @@ chrono = "0.4"
18 18 dirs = "5.0"
19 19 serde = { version = "1.0", features = ["derive"] }
20 20 mlua = { version = "0.10", features = ["lua54", "vendored"] }
21 -libc = "0.2"
+0 −2 src/bin/main.rs
@@ -1,8 +1,6 @@
1 1 use std::path::PathBuf;
2 2
3 3 fn main() -> Result<(), Box<dyn std::error::Error>> {
4 - oxwm::signal::prevent_zombie_processes();
5 -
6 4 let arguments: Vec<String> = std::env::args().collect();
7 5
8 6 let mut custom_config_path: Option<PathBuf> = None;
+0 −6 src/config/lua_api.rs
@@ -647,10 +647,6 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
647 647 create_action_table(lua, "Restart", Value::Nil)
648 648 })?;
649 649
650 - let recompile = lua.create_function(|lua, ()| {
651 - create_action_table(lua, "Recompile", Value::Nil)
652 - })?;
653 -
654 650 let toggle_gaps = lua.create_function(|lua, ()| {
655 651 create_action_table(lua, "ToggleGaps", Value::Nil)
656 652 })?;
@@ -693,7 +689,6 @@ fn register_misc(lua: &Lua, parent: &Table, builder: SharedBuilder) -> Result<()
693 689 parent.set("autostart", autostart)?;
694 690 parent.set("quit", quit)?;
695 691 parent.set("restart", restart)?;
696 - parent.set("recompile", recompile)?;
697 692 parent.set("toggle_gaps", toggle_gaps)?;
698 693 parent.set("set_master_factor", set_master_factor)?;
699 694 parent.set("inc_num_master", inc_num_master)?;
@@ -781,7 +776,6 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
781 776 "MoveStack" => Ok(KeyAction::MoveStack),
782 777 "Quit" => Ok(KeyAction::Quit),
783 778 "Restart" => Ok(KeyAction::Restart),
784 - "Recompile" => Ok(KeyAction::Recompile),
785 779 "ViewTag" => Ok(KeyAction::ViewTag),
786 780 "ToggleView" => Ok(KeyAction::ToggleView),
787 781 "MoveToTag" => Ok(KeyAction::MoveToTag),
+5 −23 src/keyboard/handlers.rs
@@ -1,5 +1,4 @@
1 -use std::io::{ErrorKind, Result};
2 -use std::process::Command;
1 +use std::io::Result;
3 2
4 3 use serde::Deserialize;
5 4 use x11rb::connection::Connection;
@@ -17,7 +16,6 @@ pub enum KeyAction {
17 16 MoveStack,
18 17 Quit,
19 18 Restart,
20 - Recompile,
21 19 ViewTag,
22 20 ToggleView,
23 21 MoveToTag,
@@ -315,16 +313,9 @@ fn handle_next_key(
315 313 pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize) -> Result<()> {
316 314 if let KeyAction::Spawn = action {
317 315 match arg {
318 - Arg::Str(command) => match Command::new(command.as_str()).spawn() {
319 - Err(error) if error.kind() == ErrorKind::NotFound => {
320 - eprintln!(
321 - "KeyAction::Spawn failed: could not spawn \"{}\", command not found",
322 - command
323 - );
324 - }
325 - Err(error) => Err(error)?,
326 - _ => (),
327 - },
316 + Arg::Str(command) => {
317 + crate::signal::spawn_detached(command);
318 + }
328 319 Arg::Array(command) => {
329 320 let Some((cmd, args)) = command.split_first() else {
330 321 return Ok(());
@@ -341,16 +332,7 @@ pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize
341 332 }
342 333
343 334 let args_str: Vec<&str> = args_vec.iter().map(|s| s.as_str()).collect();
344 - match Command::new(cmd.as_str()).args(&args_str).spawn() {
345 - Err(error) if error.kind() == ErrorKind::NotFound => {
346 - eprintln!(
347 - "KeyAction::Spawn failed: could not spawn \"{}\", command not found",
348 - cmd
349 - );
350 - }
351 - Err(error) => Err(error)?,
352 - _ => (),
353 - }
335 + crate::signal::spawn_detached_with_args(cmd, &args_str);
354 336 }
355 337 _ => {}
356 338 }
+0 −1 src/overlay/keybind.rs
@@ -198,7 +198,6 @@ impl KeybindOverlay {
198 198 KeyAction::ShowKeybindOverlay => "Show This Keybind Help".to_string(),
199 199 KeyAction::Quit => "Quit Window Manager".to_string(),
200 200 KeyAction::Restart => "Restart Window Manager".to_string(),
201 - KeyAction::Recompile => "Recompile Window Manager".to_string(),
202 201 KeyAction::KillClient => "Close Focused Window".to_string(),
203 202 KeyAction::Spawn => match &binding.arg {
204 203 Arg::Str(cmd) => format!("Launch: {}", cmd),
+28 −9 src/signal.rs
@@ -1,13 +1,32 @@
1 -use std::ptr;
1 +use std::process::{Command, Stdio};
2 2
3 -pub fn prevent_zombie_processes() {
4 - unsafe {
5 - let mut sa: libc::sigaction = std::mem::zeroed();
6 - libc::sigemptyset(&mut sa.sa_mask);
7 - sa.sa_flags = libc::SA_NOCLDSTOP | libc::SA_NOCLDWAIT | libc::SA_RESTART;
8 - sa.sa_sigaction = libc::SIG_IGN;
9 - libc::sigaction(libc::SIGCHLD, &sa, ptr::null_mut());
3 +pub fn spawn_detached(cmd: &str) {
4 + if let Ok(mut child) = Command::new("sh")
5 + .arg("-c")
6 + .arg(format!("({}) &", cmd))
7 + .stdin(Stdio::null())
8 + .stdout(Stdio::null())
9 + .stderr(Stdio::null())
10 + .spawn()
11 + {
12 + let _ = child.wait();
13 + }
14 +}
15 +
16 +pub fn spawn_detached_with_args(program: &str, args: &[&str]) {
17 + let escaped_args: Vec<String> = args.iter().map(|a| shell_escape(a)).collect();
18 + let full_cmd = if escaped_args.is_empty() {
19 + program.to_string()
20 + } else {
21 + format!("{} {}", program, escaped_args.join(" "))
22 + };
23 + spawn_detached(&full_cmd)
24 +}
10 25
11 - while libc::waitpid(-1, ptr::null_mut(), libc::WNOHANG) > 0 {}
26 +fn shell_escape(s: &str) -> String {
27 + if s.contains(|c: char| c.is_whitespace() || c == '\'' || c == '"' || c == '\\') {
28 + format!("'{}'", s.replace('\'', "'\\''"))
29 + } else {
30 + s.to_string()
12 31 }
13 32 }
+4 −23 src/window_manager.rs
@@ -9,7 +9,6 @@ use crate::layout::{Layout, LayoutBox, LayoutType, layout_from_str, next_layout}
9 9 use crate::monitor::{Monitor, detect_monitors};
10 10 use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay};
11 11 use std::collections::{HashMap, HashSet};
12 -use std::process::Command;
13 12 use x11rb::cursor::Handle as CursorHandle;
14 13
15 14 use x11rb::connection::Connection;
@@ -299,7 +298,7 @@ impl WindowManager {
299 298
300 299 window_manager.scan_existing_windows()?;
301 300 window_manager.update_bar()?;
302 - window_manager.run_autostart_commands()?;
301 + window_manager.run_autostart_commands();
303 302
304 303 Ok(window_manager)
305 304 }
@@ -718,11 +717,7 @@ impl WindowManager {
718 717 match action {
719 718 KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?,
720 719 KeyAction::SpawnTerminal => {
721 - use std::process::Command;
722 - let terminal = &self.config.terminal;
723 - if let Err(error) = Command::new(terminal).spawn() {
724 - eprintln!("Failed to spawn terminal {}: {:?}", terminal, error);
725 - }
720 + crate::signal::spawn_detached(&self.config.terminal);
726 721 }
727 722 KeyAction::KillClient => {
728 723 if let Some(focused) = self
@@ -787,15 +782,6 @@ impl WindowManager {
787 782 KeyAction::Quit | KeyAction::Restart => {
788 783 // Handled in handle_event
789 784 }
790 - KeyAction::Recompile => {
791 - match std::process::Command::new("oxwm")
792 - .arg("--recompile")
793 - .spawn()
794 - {
795 - Ok(_) => eprintln!("Recompiling in background"),
796 - Err(e) => eprintln!("Failed to spawn recompile: {}", e),
797 - }
798 - }
799 785 KeyAction::ViewTag => {
800 786 if let Arg::Int(tag_index) = arg {
801 787 self.view_tag(*tag_index as usize)?;
@@ -3808,15 +3794,10 @@ impl WindowManager {
3808 3794 Ok(())
3809 3795 }
3810 3796
3811 - fn run_autostart_commands(&self) -> Result<(), WmError> {
3797 + fn run_autostart_commands(&self) {
3812 3798 for command in &self.config.autostart {
3813 - Command::new("sh")
3814 - .arg("-c")
3815 - .arg(command)
3816 - .spawn()
3817 - .map_err(|e| WmError::Autostart(command.clone(), e))?;
3799 + crate::signal::spawn_detached(command);
3818 3800 eprintln!("[autostart] Spawned: {}", command);
3819 3801 }
3820 - Ok(())
3821 3802 }
3822 3803 }