2018-07-20 03:54:45 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::thread;
|
|
|
|
|
2019-02-28 01:07:55 +00:00
|
|
|
use crossbeam_channel::Sender;
|
2018-07-20 03:54:45 +00:00
|
|
|
use signal_hook::iterator::Signals;
|
|
|
|
|
|
|
|
/// This starts a new thread to listen for SIGWINCH signals
|
2019-02-28 01:07:55 +00:00
|
|
|
#[allow(unused)]
|
2018-07-20 03:54:45 +00:00
|
|
|
pub fn start_resize_thread(
|
2019-02-28 01:07:55 +00:00
|
|
|
resize_sender: Sender<()>, resize_running: Arc<AtomicBool>,
|
2018-07-20 03:54:45 +00:00
|
|
|
) {
|
2019-02-28 01:07:55 +00:00
|
|
|
let signals = Signals::new(&[libc::SIGWINCH]).unwrap();
|
2018-07-20 03:54:45 +00:00
|
|
|
thread::spawn(move || {
|
|
|
|
// This thread will listen to SIGWINCH events and report them.
|
|
|
|
while resize_running.load(Ordering::Relaxed) {
|
|
|
|
// We know it will only contain SIGWINCH signals, so no need to check.
|
|
|
|
if signals.wait().count() > 0 {
|
2019-02-28 01:07:55 +00:00
|
|
|
resize_sender.send(()).unwrap();
|
2018-07-20 03:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|