forge
Explore
Log in

Don't you dare go Hollow

Add --session CLI flag instead of detection based on systemd service

Browse files at this commit

f0a5e9c9332624aa7ea201c8c83f4f20b0a9775fIvan MolodetskikhParent: c4c0784
Allows running without systemd.
resources/niri.servicemodified+1 -1
@@ -11,4 +11,4 @@ Before=xdg-desktop-autostart.target
11 [Service]11 [Service]
12 Slice=session.slice12 Slice=session.slice
13 Type=notify13 Type=notify
14-ExecStart=/usr/bin/niri14+ExecStart=/usr/bin/niri --session
src/cli.rsmodified+7 -0
@@ -15,6 +15,13 @@ pub struct Cli {
15 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).15 /// Path to config file (default: `$XDG_CONFIG_HOME/niri/config.kdl`).
16 #[arg(short, long)]16 #[arg(short, long)]
17 pub config: Option<PathBuf>,17 pub config: Option<PathBuf>,
18+ /// Import environment globally to systemd and D-Bus, run D-Bus services.
19+ ///
20+ /// Set this flag in a systemd service started by your display manager, or when running
21+ /// manually as your main compositor instance. Do not set when running as a nested window, or
22+ /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.
23+ #[arg(long)]
24+ pub session: bool,
18 /// Command to run upon compositor startup.25 /// Command to run upon compositor startup.
19 #[arg(last = true)]26 #[arg(last = true)]
20 pub command: Vec<OsString>,27 pub command: Vec<OsString>,
src/main.rsmodified+14 -15
@@ -38,8 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
38 REMOVE_ENV_RUST_LIB_BACKTRACE.store(true, Ordering::Relaxed);38 REMOVE_ENV_RUST_LIB_BACKTRACE.store(true, Ordering::Relaxed);
39 }39 }
40 40
41- let is_systemd_service = env::var_os("NOTIFY_SOCKET").is_some();41+ IS_SYSTEMD_SERVICE.store(env::var_os("NOTIFY_SOCKET").is_some(), Ordering::Relaxed);
42- IS_SYSTEMD_SERVICE.store(is_systemd_service, Ordering::Relaxed);
43 42
44 let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug".to_owned());43 let directives = env::var("RUST_LOG").unwrap_or_else(|_| "niri=debug".to_owned());
45 let env_filter = EnvFilter::builder().parse_lossy(directives);44 let env_filter = EnvFilter::builder().parse_lossy(directives);
@@ -48,22 +47,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
48 .with_env_filter(env_filter)47 .with_env_filter(env_filter)
49 .init();48 .init();
50 49
51- if is_systemd_service {50+ let cli = Cli::parse();
52- // If we're starting as a systemd service, assume that the intention is to start on a TTY.51+
53- // Remove DISPLAY or WAYLAND_DISPLAY from our environment if they are set, since they will52+ if cli.session {
54- // cause the winit backend to be selected instead.53+ // If we're starting as a session, assume that the intention is to start on a TTY. Remove
54+ // DISPLAY or WAYLAND_DISPLAY from our environment if they are set, since they will cause
55+ // the winit backend to be selected instead.
55 if env::var_os("DISPLAY").is_some() {56 if env::var_os("DISPLAY").is_some() {
56- debug!("we're running as a systemd service but DISPLAY is set, removing it");57+ debug!("running as a session but DISPLAY is set, removing it");
57 env::remove_var("DISPLAY");58 env::remove_var("DISPLAY");
58 }59 }
59 if env::var_os("WAYLAND_DISPLAY").is_some() {60 if env::var_os("WAYLAND_DISPLAY").is_some() {
60- debug!("we're running as a systemd service but WAYLAND_DISPLAY is set, removing it");61+ debug!("running as a session but WAYLAND_DISPLAY is set, removing it");
61 env::remove_var("WAYLAND_DISPLAY");62 env::remove_var("WAYLAND_DISPLAY");
62 }63 }
63 }64 }
64 65
65- let cli = Cli::parse();
66-
67 let _client = tracy_client::Client::start();66 let _client = tracy_client::Client::start();
68 67
69 // Set a better error printer for config loading.68 // Set a better error printer for config loading.
@@ -177,9 +176,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
177 info!("IPC listening on: {}", ipc.socket_path.to_string_lossy());176 info!("IPC listening on: {}", ipc.socket_path.to_string_lossy());
178 }177 }
179 178
180- if is_systemd_service {179+ if cli.session {
181- // We're starting as a systemd service. Export our variables.180+ // We're starting as a session. Import our variables.
182- import_env_to_systemd();181+ import_environment();
183 182
184 // Inhibit power key handling so we can suspend on it.183 // Inhibit power key handling so we can suspend on it.
185 #[cfg(feature = "dbus")]184 #[cfg(feature = "dbus")]
@@ -191,7 +190,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
191 }190 }
192 191
193 #[cfg(feature = "dbus")]192 #[cfg(feature = "dbus")]
194- dbus::DBusServers::start(&mut state, is_systemd_service);193+ dbus::DBusServers::start(&mut state, cli.session);
195 194
196 // Notify systemd we're ready.195 // Notify systemd we're ready.
197 if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {196 if let Err(err) = sd_notify::notify(true, &[NotifyState::Ready]) {
@@ -236,7 +235,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
236 Ok(())235 Ok(())
237 }236 }
238 237
239-fn import_env_to_systemd() {238+fn import_environment() {
240 let variables = ["WAYLAND_DISPLAY", niri_ipc::SOCKET_PATH_ENV].join(" ");239 let variables = ["WAYLAND_DISPLAY", niri_ipc::SOCKET_PATH_ENV].join(" ");
241 240
242 let rv = Command::new("/bin/sh")241 let rv = Command::new("/bin/sh")