diff options
| -rw-r--r-- | src/input/mod.rs | 3 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/utils/spawning.rs | 16 |
3 files changed, 17 insertions, 6 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs index bafa1505..545c82d7 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -520,7 +520,8 @@ impl State { self.niri.debug_toggle_damage(); } Action::Spawn(command) => { - spawn(command); + let (token, _) = self.niri.activation_state.create_external_token(None); + spawn(command, Some(token.clone())); } Action::DoScreenTransition(delay_ms) => { self.backend.with_primary_renderer(|renderer| { diff --git a/src/main.rs b/src/main.rs index 43fa2db6..87edb329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -236,10 +236,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { }; // Spawn commands from cli and auto-start. - spawn(cli.command); + spawn(cli.command, None); for elem in spawn_at_startup { - spawn(elem.command); + spawn(elem.command, None); } // Show the config error notification right away if needed. diff --git a/src/utils/spawning.rs b/src/utils/spawning.rs index 871f05db..b7aa0d44 100644 --- a/src/utils/spawning.rs +++ b/src/utils/spawning.rs @@ -9,6 +9,7 @@ use std::{io, thread}; use atomic::Atomic; use libc::{getrlimit, rlim_t, rlimit, setrlimit, RLIMIT_NOFILE}; use niri_config::Environment; +use smithay::wayland::xdg_activation::XdgActivationToken; use crate::utils::expand_home; @@ -61,7 +62,7 @@ pub fn restore_nofile_rlimit() { } /// Spawns the command to run independently of the compositor. -pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { +pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>, token: Option<XdgActivationToken>) { let _span = tracy_client::span!(); if command.is_empty() { @@ -73,7 +74,7 @@ pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { .name("Command Spawner".to_owned()) .spawn(move || { let (command, args) = command.split_first().unwrap(); - spawn_sync(command, args); + spawn_sync(command, args, token); }); if let Err(err) = res { @@ -81,7 +82,11 @@ pub fn spawn<T: AsRef<OsStr> + Send + 'static>(command: Vec<T>) { } } -fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>) { +fn spawn_sync( + command: impl AsRef<OsStr>, + args: impl IntoIterator<Item = impl AsRef<OsStr>>, + token: Option<XdgActivationToken>, +) { let _span = tracy_client::span!(); let mut command = command.as_ref(); @@ -122,6 +127,11 @@ fn spawn_sync(command: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl As } drop(env); + if let Some(token) = token.as_ref() { + process.env("XDG_ACTIVATION_TOKEN", token.as_str()); + process.env("DESKTOP_STARTUP_ID", token.as_str()); + } + let Some(mut child) = do_spawn(command, process) else { return; }; |
