From 61f2ac01d782f1142aefb78d1286db005021a7a0 Mon Sep 17 00:00:00 2001 From: Christian Meissl Date: Sun, 3 Nov 2024 14:29:36 +0100 Subject: xdg: startup activation pass an activation token to process spawned through actions --- src/input/mod.rs | 3 ++- src/main.rs | 4 ++-- 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> { }; // 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 + Send + 'static>(command: Vec) { +pub fn spawn + Send + 'static>(command: Vec, token: Option) { let _span = tracy_client::span!(); if command.is_empty() { @@ -73,7 +74,7 @@ pub fn spawn + Send + 'static>(command: Vec) { .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 + Send + 'static>(command: Vec) { } } -fn spawn_sync(command: impl AsRef, args: impl IntoIterator>) { +fn spawn_sync( + command: impl AsRef, + args: impl IntoIterator>, + token: Option, +) { let _span = tracy_client::span!(); let mut command = command.as_ref(); @@ -122,6 +127,11 @@ fn spawn_sync(command: impl AsRef, args: impl IntoIterator