i3status_rs/
signals.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use futures::stream::StreamExt;
use libc::{SIGRTMAX, SIGRTMIN};
use signal_hook::consts::{SIGUSR1, SIGUSR2};
use signal_hook_tokio::Signals;

use crate::BoxedStream;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Signal {
    Usr1,
    Usr2,
    Custom(i32),
}

/// Returns an infinite stream of `Signal`s
pub fn signals_stream() -> BoxedStream<Signal> {
    let (sigmin, sigmax) = (SIGRTMIN(), SIGRTMAX());
    let signals = Signals::new((sigmin..sigmax).chain([SIGUSR1, SIGUSR2])).unwrap();
    signals
        .map(move |signal| match signal {
            SIGUSR1 => Signal::Usr1,
            SIGUSR2 => Signal::Usr2,
            x => Signal::Custom(x - sigmin),
        })
        .boxed()
}