forge
Explore
Log in

Don't you dare go Hollow

Add spawn-at-startup config option

Browse files at this commit

a7e338b3c0aeb37f7cc6095f27056fc77e1760a7Ivan MolodetskikhParent: 80dce05
Fixes https://github.com/YaLTeR/niri/issues/12
resources/default-config.kdlmodified+5 -0
@@ -35,6 +35,11 @@ input {
35 scale 2.035 scale 2.0
36 }36 }
37 37
38+// Add lines like this to spawn processes at startup.
39+// Note that running niri as a session supports xdg-desktop-autostart,
40+// which may be more convenient to use.
41+// spawn-at-startup "alacritty" "-e" "fish"
42+
38 binds {43 binds {
39 // Keys consist of modifiers separated by + signs, followed by an XKB key name44 // Keys consist of modifiers separated by + signs, followed by an XKB key name
40 // in the end. To find an XKB name for a particular key, you may use a program45 // in the end. To find an XKB name for a particular key, you may use a program
src/config.rsmodified+13 -0
@@ -13,6 +13,8 @@ pub struct Config {
13 pub input: Input,13 pub input: Input,
14 #[knuffel(children(name = "output"))]14 #[knuffel(children(name = "output"))]
15 pub outputs: Vec<Output>,15 pub outputs: Vec<Output>,
16+ #[knuffel(children(name = "spawn-at-startup"))]
17+ pub spawn_at_startup: Vec<SpawnAtStartup>,
16 #[knuffel(child, default)]18 #[knuffel(child, default)]
17 pub binds: Binds,19 pub binds: Binds,
18 #[knuffel(child, default)]20 #[knuffel(child, default)]
@@ -81,6 +83,12 @@ impl Default for Output {
81 }83 }
82 }84 }
83 85
86+#[derive(knuffel::Decode, Debug, Clone, PartialEq, Eq)]
87+pub struct SpawnAtStartup {
88+ #[knuffel(arguments)]
89+ pub command: Vec<String>,
90+}
91+
84 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]92 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
85 pub struct Binds(#[knuffel(children)] pub Vec<Bind>);93 pub struct Binds(#[knuffel(children)] pub Vec<Bind>);
86 94
@@ -286,6 +294,8 @@ mod tests {
286 scale 2.0294 scale 2.0
287 }295 }
288 296
297+ spawn-at-startup "alacritty" "-e" "fish"
298+
289 binds {299 binds {
290 Mod+T { spawn "alacritty"; }300 Mod+T { spawn "alacritty"; }
291 Mod+Q { close-window; }301 Mod+Q { close-window; }
@@ -320,6 +330,9 @@ mod tests {
320 name: "eDP-1".to_owned(),330 name: "eDP-1".to_owned(),
321 scale: 2.,331 scale: 2.,
322 }],332 }],
333+ spawn_at_startup: vec![SpawnAtStartup {
334+ command: vec!["alacritty".to_owned(), "-e".to_owned(), "fish".to_owned()],
335+ }],
323 binds: Binds(vec![336 binds: Binds(vec![
324 Bind {337 Bind {
325 key: Key {338 key: Key {
src/main.rsmodified+10 -2
@@ -13,9 +13,9 @@ mod niri;
13 mod pw_utils;13 mod pw_utils;
14 mod utils;14 mod utils;
15 15
16-use std::env;
17 use std::ffi::OsString;16 use std::ffi::OsString;
18 use std::path::PathBuf;17 use std::path::PathBuf;
18+use std::{env, mem};
19 19
20 use clap::Parser;20 use clap::Parser;
21 use config::Config;21 use config::Config;
@@ -57,7 +57,7 @@ fn main() {
57 57
58 let _client = tracy_client::Client::start();58 let _client = tracy_client::Client::start();
59 59
60- let config = match Config::load(cli.config).context("error loading config") {60+ let mut config = match Config::load(cli.config).context("error loading config") {
61 Ok(config) => config,61 Ok(config) => config,
62 Err(err) => {62 Err(err) => {
63 warn!("{err:?}");63 warn!("{err:?}");
@@ -65,6 +65,7 @@ fn main() {
65 }65 }
66 };66 };
67 animation::ANIMATION_SLOWDOWN.store(config.debug.animation_slowdown, Ordering::Relaxed);67 animation::ANIMATION_SLOWDOWN.store(config.debug.animation_slowdown, Ordering::Relaxed);
68+ let spawn_at_startup = mem::take(&mut config.spawn_at_startup);
68 69
69 let mut event_loop = EventLoop::try_new().unwrap();70 let mut event_loop = EventLoop::try_new().unwrap();
70 let mut display = Display::new().unwrap();71 let mut display = Display::new().unwrap();
@@ -76,10 +77,17 @@ fn main() {
76 );77 );
77 let mut data = LoopData { display, state };78 let mut data = LoopData { display, state };
78 79
80+ // Spawn commands from cli and auto-start.
79 if let Some((command, args)) = cli.command.split_first() {81 if let Some((command, args)) = cli.command.split_first() {
80 spawn(command, args);82 spawn(command, args);
81 }83 }
82 84
85+ for elem in spawn_at_startup {
86+ if let Some((command, args)) = elem.command.split_first() {
87+ spawn(command, args);
88+ }
89+ }
90+
83 event_loop91 event_loop
84 .run(None, &mut data, move |data| {92 .run(None, &mut data, move |data| {
85 let _span = tracy_client::span!("loop callback");93 let _span = tracy_client::span!("loop callback");