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
+0 −1 Cargo.lock
| @@ -295,7 +295,6 @@ version = "0.8.1" | |||
| 295 | dependencies = [ | 295 | dependencies = [ |
| 296 | "chrono", | 296 | "chrono", |
| 297 | "dirs", | 297 | "dirs", |
| 298 | - "libc", | ||
| 299 | "mlua", | 298 | "mlua", |
| 300 | "serde", | 299 | "serde", |
| 301 | "x11", | 300 | "x11", |
+0 −1 Cargo.toml
| @@ -18,4 +18,3 @@ chrono = "0.4" | |||
| 18 | dirs = "5.0" | 18 | dirs = "5.0" |
| 19 | serde = { version = "1.0", features = ["derive"] } | 19 | serde = { version = "1.0", features = ["derive"] } |
| 20 | mlua = { version = "0.10", features = ["lua54", "vendored"] } | 20 | mlua = { version = "0.10", features = ["lua54", "vendored"] } |
| 21 | -libc = "0.2" | ||
+0 −2 src/bin/main.rs
| @@ -1,8 +1,6 @@ | |||
| 1 | use std::path::PathBuf; | 1 | use std::path::PathBuf; |
| 2 | 2 | ||
| 3 | fn main() -> Result<(), Box<dyn std::error::Error>> { | 3 | fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 4 | - oxwm::signal::prevent_zombie_processes(); | ||
| 5 | - | ||
| 6 | let arguments: Vec<String> = std::env::args().collect(); | 4 | let arguments: Vec<String> = std::env::args().collect(); |
| 7 | 5 | ||
| 8 | let mut custom_config_path: Option<PathBuf> = None; | 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 | create_action_table(lua, "Restart", Value::Nil) | 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 | let toggle_gaps = lua.create_function(|lua, ()| { | 650 | let toggle_gaps = lua.create_function(|lua, ()| { |
| 655 | create_action_table(lua, "ToggleGaps", Value::Nil) | 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 | parent.set("autostart", autostart)?; | 689 | parent.set("autostart", autostart)?; |
| 694 | parent.set("quit", quit)?; | 690 | parent.set("quit", quit)?; |
| 695 | parent.set("restart", restart)?; | 691 | parent.set("restart", restart)?; |
| 696 | - parent.set("recompile", recompile)?; | ||
| 697 | parent.set("toggle_gaps", toggle_gaps)?; | 692 | parent.set("toggle_gaps", toggle_gaps)?; |
| 698 | parent.set("set_master_factor", set_master_factor)?; | 693 | parent.set("set_master_factor", set_master_factor)?; |
| 699 | parent.set("inc_num_master", inc_num_master)?; | 694 | parent.set("inc_num_master", inc_num_master)?; |
| @@ -781,7 +776,6 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> { | |||
| 781 | "MoveStack" => Ok(KeyAction::MoveStack), | 776 | "MoveStack" => Ok(KeyAction::MoveStack), |
| 782 | "Quit" => Ok(KeyAction::Quit), | 777 | "Quit" => Ok(KeyAction::Quit), |
| 783 | "Restart" => Ok(KeyAction::Restart), | 778 | "Restart" => Ok(KeyAction::Restart), |
| 784 | - "Recompile" => Ok(KeyAction::Recompile), | ||
| 785 | "ViewTag" => Ok(KeyAction::ViewTag), | 779 | "ViewTag" => Ok(KeyAction::ViewTag), |
| 786 | "ToggleView" => Ok(KeyAction::ToggleView), | 780 | "ToggleView" => Ok(KeyAction::ToggleView), |
| 787 | "MoveToTag" => Ok(KeyAction::MoveToTag), | 781 | "MoveToTag" => Ok(KeyAction::MoveToTag), |
+5 −23 src/keyboard/handlers.rs
| @@ -1,5 +1,4 @@ | |||
| 1 | -use std::io::{ErrorKind, Result}; | 1 | +use std::io::Result; |
| 2 | -use std::process::Command; | ||
| 3 | 2 | ||
| 4 | use serde::Deserialize; | 3 | use serde::Deserialize; |
| 5 | use x11rb::connection::Connection; | 4 | use x11rb::connection::Connection; |
| @@ -17,7 +16,6 @@ pub enum KeyAction { | |||
| 17 | MoveStack, | 16 | MoveStack, |
| 18 | Quit, | 17 | Quit, |
| 19 | Restart, | 18 | Restart, |
| 20 | - Recompile, | ||
| 21 | ViewTag, | 19 | ViewTag, |
| 22 | ToggleView, | 20 | ToggleView, |
| 23 | MoveToTag, | 21 | MoveToTag, |
| @@ -315,16 +313,9 @@ fn handle_next_key( | |||
| 315 | pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize) -> Result<()> { | 313 | pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize) -> Result<()> { |
| 316 | if let KeyAction::Spawn = action { | 314 | if let KeyAction::Spawn = action { |
| 317 | match arg { | 315 | match arg { |
| 318 | - Arg::Str(command) => match Command::new(command.as_str()).spawn() { | 316 | + Arg::Str(command) => { |
| 319 | - Err(error) if error.kind() == ErrorKind::NotFound => { | 317 | + crate::signal::spawn_detached(command); |
| 320 | - eprintln!( | 318 | + } |
| 321 | - "KeyAction::Spawn failed: could not spawn \"{}\", command not found", | ||
| 322 | - command | ||
| 323 | - ); | ||
| 324 | - } | ||
| 325 | - Err(error) => Err(error)?, | ||
| 326 | - _ => (), | ||
| 327 | - }, | ||
| 328 | Arg::Array(command) => { | 319 | Arg::Array(command) => { |
| 329 | let Some((cmd, args)) = command.split_first() else { | 320 | let Some((cmd, args)) = command.split_first() else { |
| 330 | return Ok(()); | 321 | return Ok(()); |
| @@ -341,16 +332,7 @@ pub fn handle_spawn_action(action: KeyAction, arg: &Arg, selected_monitor: usize | |||
| 341 | } | 332 | } |
| 342 | 333 | ||
| 343 | let args_str: Vec<&str> = args_vec.iter().map(|s| s.as_str()).collect(); | 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() { | 335 | + crate::signal::spawn_detached_with_args(cmd, &args_str); |
| 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 | - } | ||
| 354 | } | 336 | } |
| 355 | _ => {} | 337 | _ => {} |
| 356 | } | 338 | } |
+0 −1 src/overlay/keybind.rs
| @@ -198,7 +198,6 @@ impl KeybindOverlay { | |||
| 198 | KeyAction::ShowKeybindOverlay => "Show This Keybind Help".to_string(), | 198 | KeyAction::ShowKeybindOverlay => "Show This Keybind Help".to_string(), |
| 199 | KeyAction::Quit => "Quit Window Manager".to_string(), | 199 | KeyAction::Quit => "Quit Window Manager".to_string(), |
| 200 | KeyAction::Restart => "Restart Window Manager".to_string(), | 200 | KeyAction::Restart => "Restart Window Manager".to_string(), |
| 201 | - KeyAction::Recompile => "Recompile Window Manager".to_string(), | ||
| 202 | KeyAction::KillClient => "Close Focused Window".to_string(), | 201 | KeyAction::KillClient => "Close Focused Window".to_string(), |
| 203 | KeyAction::Spawn => match &binding.arg { | 202 | KeyAction::Spawn => match &binding.arg { |
| 204 | Arg::Str(cmd) => format!("Launch: {}", cmd), | 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() { | 3 | +pub fn spawn_detached(cmd: &str) { |
| 4 | - unsafe { | 4 | + if let Ok(mut child) = Command::new("sh") |
| 5 | - let mut sa: libc::sigaction = std::mem::zeroed(); | 5 | + .arg("-c") |
| 6 | - libc::sigemptyset(&mut sa.sa_mask); | 6 | + .arg(format!("({}) &", cmd)) |
| 7 | - sa.sa_flags = libc::SA_NOCLDSTOP | libc::SA_NOCLDWAIT | libc::SA_RESTART; | 7 | + .stdin(Stdio::null()) |
| 8 | - sa.sa_sigaction = libc::SIG_IGN; | 8 | + .stdout(Stdio::null()) |
| 9 | - libc::sigaction(libc::SIGCHLD, &sa, ptr::null_mut()); | 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 | use crate::monitor::{Monitor, detect_monitors}; | 9 | use crate::monitor::{Monitor, detect_monitors}; |
| 10 | use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; | 10 | use crate::overlay::{ErrorOverlay, KeybindOverlay, Overlay}; |
| 11 | use std::collections::{HashMap, HashSet}; | 11 | use std::collections::{HashMap, HashSet}; |
| 12 | -use std::process::Command; | ||
| 13 | use x11rb::cursor::Handle as CursorHandle; | 12 | use x11rb::cursor::Handle as CursorHandle; |
| 14 | 13 | ||
| 15 | use x11rb::connection::Connection; | 14 | use x11rb::connection::Connection; |
| @@ -299,7 +298,7 @@ impl WindowManager { | |||
| 299 | 298 | ||
| 300 | window_manager.scan_existing_windows()?; | 299 | window_manager.scan_existing_windows()?; |
| 301 | window_manager.update_bar()?; | 300 | window_manager.update_bar()?; |
| 302 | - window_manager.run_autostart_commands()?; | 301 | + window_manager.run_autostart_commands(); |
| 303 | 302 | ||
| 304 | Ok(window_manager) | 303 | Ok(window_manager) |
| 305 | } | 304 | } |
| @@ -718,11 +717,7 @@ impl WindowManager { | |||
| 718 | match action { | 717 | match action { |
| 719 | KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?, | 718 | KeyAction::Spawn => handlers::handle_spawn_action(action, arg, self.selected_monitor)?, |
| 720 | KeyAction::SpawnTerminal => { | 719 | KeyAction::SpawnTerminal => { |
| 721 | - use std::process::Command; | 720 | + crate::signal::spawn_detached(&self.config.terminal); |
| 722 | - let terminal = &self.config.terminal; | ||
| 723 | - if let Err(error) = Command::new(terminal).spawn() { | ||
| 724 | - eprintln!("Failed to spawn terminal {}: {:?}", terminal, error); | ||
| 725 | - } | ||
| 726 | } | 721 | } |
| 727 | KeyAction::KillClient => { | 722 | KeyAction::KillClient => { |
| 728 | if let Some(focused) = self | 723 | if let Some(focused) = self |
| @@ -787,15 +782,6 @@ impl WindowManager { | |||
| 787 | KeyAction::Quit | KeyAction::Restart => { | 782 | KeyAction::Quit | KeyAction::Restart => { |
| 788 | // Handled in handle_event | 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 | KeyAction::ViewTag => { | 785 | KeyAction::ViewTag => { |
| 800 | if let Arg::Int(tag_index) = arg { | 786 | if let Arg::Int(tag_index) = arg { |
| 801 | self.view_tag(*tag_index as usize)?; | 787 | self.view_tag(*tag_index as usize)?; |
| @@ -3808,15 +3794,10 @@ impl WindowManager { | |||
| 3808 | Ok(()) | 3794 | Ok(()) |
| 3809 | } | 3795 | } |
| 3810 | 3796 | ||
| 3811 | - fn run_autostart_commands(&self) -> Result<(), WmError> { | 3797 | + fn run_autostart_commands(&self) { |
| 3812 | for command in &self.config.autostart { | 3798 | for command in &self.config.autostart { |
| 3813 | - Command::new("sh") | 3799 | + crate::signal::spawn_detached(command); |
| 3814 | - .arg("-c") | ||
| 3815 | - .arg(command) | ||
| 3816 | - .spawn() | ||
| 3817 | - .map_err(|e| WmError::Autostart(command.clone(), e))?; | ||
| 3818 | eprintln!("[autostart] Spawned: {}", command); | 3800 | eprintln!("[autostart] Spawned: {}", command); |
| 3819 | } | 3801 | } |
| 3820 | - Ok(()) | ||
| 3821 | } | 3802 | } |
| 3822 | } | 3803 | } |