diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input.rs | 4 | ||||
| -rw-r--r-- | src/main.rs | 8 | ||||
| -rw-r--r-- | src/utils.rs | 23 |
3 files changed, 25 insertions, 10 deletions
diff --git a/src/input.rs b/src/input.rs index 96b21c7f..063d321c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -118,9 +118,7 @@ impl State { self.backend.toggle_debug_tint(); } Action::Spawn(command) => { - if let Some((command, args)) = command.split_first() { - spawn(command, args); - } + spawn(command); } Action::ScreenshotScreen => { let active = self.niri.layout.active_output().cloned(); diff --git a/src/main.rs b/src/main.rs index fcfd6f83..686abc81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,14 +164,10 @@ fn main() { }; // Spawn commands from cli and auto-start. - if let Some((command, args)) = cli.command.split_first() { - spawn(command, args); - } + spawn(cli.command); for elem in spawn_at_startup { - if let Some((command, args)) = elem.command.split_first() { - spawn(command, args); - } + spawn(elem.command); } // Run the compositor. diff --git a/src/utils.rs b/src/utils.rs index 94b5c427..bf25819b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use std::process::{Command, Stdio}; use std::ptr::null_mut; use std::sync::atomic::{AtomicBool, Ordering}; +use std::thread; use std::time::Duration; use anyhow::{ensure, Context}; @@ -58,7 +59,27 @@ pub static REMOVE_ENV_RUST_BACKTRACE: AtomicBool = AtomicBool::new(false); pub static REMOVE_ENV_RUST_LIB_BACKTRACE: AtomicBool = AtomicBool::new(false); /// Spawns the command to run independently of the compositor. -pub fn spawn(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) { +pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { + let _span = tracy_client::span!(); + + if command.is_empty() { + return; + } + + // Spawning and waiting takes some milliseconds, so do it in a thread. + let res = thread::Builder::new() + .name("Command Spawner".to_owned()) + .spawn(move || { + let (command, args) = command.split_first().unwrap(); + spawn_sync(command, args); + }); + + if let Err(err) = res { + warn!("error spawning a thread to spawn the command: {err:?}"); + } +} + +fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) { let _span = tracy_client::span!(); let command = command.as_ref(); |
