From a7e338b3c0aeb37f7cc6095f27056fc77e1760a7 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 21 Sep 2023 19:58:03 +0400 Subject: Add spawn-at-startup config option Fixes https://github.com/YaLTeR/niri/issues/12 --- src/config.rs | 13 +++++++++++++ src/main.rs | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/config.rs b/src/config.rs index 88773fd3..dd664ff8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,6 +13,8 @@ pub struct Config { pub input: Input, #[knuffel(children(name = "output"))] pub outputs: Vec, + #[knuffel(children(name = "spawn-at-startup"))] + pub spawn_at_startup: Vec, #[knuffel(child, default)] pub binds: Binds, #[knuffel(child, default)] @@ -81,6 +83,12 @@ impl Default for Output { } } +#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)] +pub struct SpawnAtStartup { + #[knuffel(arguments)] + pub command: Vec, +} + #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] pub struct Binds(#[knuffel(children)] pub Vec); @@ -286,6 +294,8 @@ mod tests { scale 2.0 } + spawn-at-startup "alacritty" "-e" "fish" + binds { Mod+T { spawn "alacritty"; } Mod+Q { close-window; } @@ -320,6 +330,9 @@ mod tests { name: "eDP-1".to_owned(), scale: 2., }], + spawn_at_startup: vec![SpawnAtStartup { + command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()], + }], binds: Binds(vec![ Bind { key: Key { diff --git a/src/main.rs b/src/main.rs index cb58910e..3ec8b323 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,9 +13,9 @@ mod niri; mod pw_utils; mod utils; -use std::env; use std::ffi::OsString; use std::path::PathBuf; +use std::{env, mem}; use clap::Parser; use config::Config; @@ -57,7 +57,7 @@ fn main() { let _client = tracy_client::Client::start(); - let config = match Config::load(cli.config).context("error loading config") { + let mut config = match Config::load(cli.config).context("error loading config") { Ok(config) => config, Err(err) => { warn!("{err:?}"); @@ -65,6 +65,7 @@ fn main() { } }; animation::ANIMATION_SLOWDOWN.store(config.debug.animation_slowdown, Ordering::Relaxed); + let spawn_at_startup = mem::take(&mut config.spawn_at_startup); let mut event_loop = EventLoop::try_new().unwrap(); let mut display = Display::new().unwrap(); @@ -76,10 +77,17 @@ fn main() { ); let mut data = LoopData { display, state }; + // Spawn commands from cli and auto-start. if let Some((command, args)) = cli.command.split_first() { spawn(command, args); } + for elem in spawn_at_startup { + if let Some((command, args)) = elem.command.split_first() { + spawn(command, args); + } + } + event_loop .run(None, &mut data, move |data| { let _span = tracy_client::span!("loop callback"); -- cgit