mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Add spawn-at-startup config option
Fixes https://github.com/YaLTeR/niri/issues/12
This commit is contained in:
@@ -35,6 +35,11 @@ input {
|
||||
scale 2.0
|
||||
}
|
||||
|
||||
// Add lines like this to spawn processes at startup.
|
||||
// Note that running niri as a session supports xdg-desktop-autostart,
|
||||
// which may be more convenient to use.
|
||||
// spawn-at-startup "alacritty" "-e" "fish"
|
||||
|
||||
binds {
|
||||
// Keys consist of modifiers separated by + signs, followed by an XKB key name
|
||||
// in the end. To find an XKB name for a particular key, you may use a program
|
||||
|
||||
@@ -13,6 +13,8 @@ pub struct Config {
|
||||
pub input: Input,
|
||||
#[knuffel(children(name = "output"))]
|
||||
pub outputs: Vec<Output>,
|
||||
#[knuffel(children(name = "spawn-at-startup"))]
|
||||
pub spawn_at_startup: Vec<SpawnAtStartup>,
|
||||
#[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<String>,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
|
||||
pub struct Binds(#[knuffel(children)] pub Vec<Bind>);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+10
-2
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user