aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsodiboo <git@sodi.boo>2025-07-13 15:44:51 +0200
committerIvan Molodetskikh <yalterz@gmail.com>2025-07-14 13:16:10 +0300
commit22e43193e05ad49e2c3a34a0755ce41bc0c880a0 (patch)
tree93f687a756555fad1a4c2ed028b110b6feea3dde
parent7a2379ad35a8ff9297379dfa61f6d62d35050bad (diff)
downloadniri-22e43193e05ad49e2c3a34a0755ce41bc0c880a0.tar.gz
niri-22e43193e05ad49e2c3a34a0755ce41bc0c880a0.tar.bz2
niri-22e43193e05ad49e2c3a34a0755ce41bc0c880a0.zip
handle `SIGINT`, `SIGTERM`, `SIGHUP`
-rw-r--r--Cargo.lock1
-rw-r--r--Cargo.toml2
-rw-r--r--src/main.rs16
3 files changed, 17 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 00be0ae2..a3cc043a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -494,6 +494,7 @@ dependencies = [
"async-task",
"bitflags 2.9.1",
"futures-io",
+ "nix 0.29.0",
"polling",
"rustix 0.38.44",
"slab",
diff --git a/Cargo.toml b/Cargo.toml
index 6f454e7f..c0132a49 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,7 +57,7 @@ async-io = { version = "2.4.1", optional = true }
atomic = "0.6.1"
bitflags.workspace = true
bytemuck = { version = "1.23.1", features = ["derive"] }
-calloop = { version = "0.14.2", features = ["executor", "futures-io"] }
+calloop = { version = "0.14.2", features = ["executor", "futures-io", "signals"] }
clap = { workspace = true, features = ["string"] }
clap_complete = "4.5.55"
clap_complete_nushell = "4.5.8"
diff --git a/src/main.rs b/src/main.rs
index 25e6d153..d036c2a8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::{env, mem};
+use calloop::signals::{Signal, Signals};
use calloop::EventLoop;
use clap::{CommandFactory, Parser};
use clap_complete::Shell;
@@ -192,8 +193,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
store_and_increase_nofile_rlimit();
+ // Create the main event loop.
+ let mut event_loop = EventLoop::<State>::try_new().unwrap();
+
+ // Handle Ctrl+C and other signals.
+ event_loop
+ .handle()
+ .insert_source(
+ Signals::new(&[Signal::SIGINT, Signal::SIGTERM, Signal::SIGHUP]).unwrap(),
+ |_, _, state| {
+ state.niri.stop_signal.stop();
+ },
+ )
+ .unwrap();
+
// Create the compositor.
- let mut event_loop = EventLoop::try_new().unwrap();
let display = Display::new().unwrap();
let mut state = State::new(
config,