handle `SIGINT`, `SIGTERM`, `SIGHUP`
Browse files at this commit22e43193e05ad49e2c3a34a0755ce41bc0c880a0Parent: 7a2379a3 changed files +17 -2
- Cargo.lock +1 -0
- Cargo.toml +1 -1
- src/main.rs +15 -1
Cargo.lockmodified+1 -0
| @@ -494,6 +494,7 @@ dependencies = [ | ||
| 494 | 494 | "async-task", |
| 495 | 495 | "bitflags 2.9.1", |
| 496 | 496 | "futures-io", |
| 497 | + "nix 0.29.0", | |
| 497 | 498 | "polling", |
| 498 | 499 | "rustix 0.38.44", |
| 499 | 500 | "slab", |
Cargo.tomlmodified+1 -1
| @@ -57,7 +57,7 @@ async-io = { version = "2.4.1", optional = true } | ||
| 57 | 57 | atomic = "0.6.1" |
| 58 | 58 | bitflags.workspace = true |
| 59 | 59 | 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"] } | |
| 61 | 61 | clap = { workspace = true, features = ["string"] } |
| 62 | 62 | clap_complete = "4.5.55" |
| 63 | 63 | clap_complete_nushell = "4.5.8" |
src/main.rsmodified+15 -1
| @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf}; | ||
| 9 | 9 | use std::process::Command; |
| 10 | 10 | use std::{env, mem}; |
| 11 | 11 | |
| 12 | +use calloop::signals::{Signal, Signals}; | |
| 12 | 13 | use calloop::EventLoop; |
| 13 | 14 | use clap::{CommandFactory, Parser}; |
| 14 | 15 | use clap_complete::Shell; |
| @@ -192,8 +193,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| 192 | 193 | |
| 193 | 194 | store_and_increase_nofile_rlimit(); |
| 194 | 195 | |
| 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 | + | |
| 195 | 210 | // Create the compositor. |
| 196 | - let mut event_loop = EventLoop::try_new().unwrap(); | |
| 197 | 211 | let display = Display::new().unwrap(); |
| 198 | 212 | let mut state = State::new( |
| 199 | 213 | config, |