forge
Explore
Log in

Don't you dare go Hollow

handle `SIGINT`, `SIGTERM`, `SIGHUP`

Browse files at this commit

22e43193e05ad49e2c3a34a0755ce41bc0c880a0sodibooParent: 7a2379a
Cargo.lockmodified+1 -0
@@ -494,6 +494,7 @@ dependencies = [
494494 "async-task",
495495 "bitflags 2.9.1",
496496 "futures-io",
497+ "nix 0.29.0",
497498 "polling",
498499 "rustix 0.38.44",
499500 "slab",
Cargo.tomlmodified+1 -1
@@ -57,7 +57,7 @@ async-io = { version = "2.4.1", optional = true }
5757 atomic = "0.6.1"
5858 bitflags.workspace = true
5959 bytemuck = { version = "1.23.1", features = ["derive"] }
60-calloop = { version = "0.14.2", features = ["executor", "futures-io"] }
60+calloop = { version = "0.14.2", features = ["executor", "futures-io", "signals"] }
6161 clap = { workspace = true, features = ["string"] }
6262 clap_complete = "4.5.55"
6363 clap_complete_nushell = "4.5.8"
src/main.rsmodified+15 -1
@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
99 use std::process::Command;
1010 use std::{env, mem};
1111
12+use calloop::signals::{Signal, Signals};
1213 use calloop::EventLoop;
1314 use clap::{CommandFactory, Parser};
1415 use clap_complete::Shell;
@@ -192,8 +193,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
192193
193194 store_and_increase_nofile_rlimit();
194195
196+ // Create the main event loop.
197+ let mut event_loop = EventLoop::<State>::try_new().unwrap();
198+
199+ // Handle Ctrl+C and other signals.
200+ event_loop
201+ .handle()
202+ .insert_source(
203+ Signals::new(&[Signal::SIGINT, Signal::SIGTERM, Signal::SIGHUP]).unwrap(),
204+ |_, _, state| {
205+ state.niri.stop_signal.stop();
206+ },
207+ )
208+ .unwrap();
209+
195210 // Create the compositor.
196- let mut event_loop = EventLoop::try_new().unwrap();
197211 let display = Display::new().unwrap();
198212 let mut state = State::new(
199213 config,