feat: proper ctrl+c stop

This commit is contained in:
Nova
2023-09-29 00:26:53 -04:00
parent 109affec81
commit da894143f9
3 changed files with 20 additions and 2 deletions

1
Cargo.lock generated
View File

@@ -2088,6 +2088,7 @@ dependencies = [
"glam 0.23.0",
"global_counter",
"lazy_static",
"libc",
"mint",
"nanoid",
"once_cell",

View File

@@ -61,6 +61,7 @@ rand = "0.8.5"
atty = "0.2.14"
xkbcommon = { version = "0.6.0", default-features = false, optional = true }
ctrlc = "3.4.1"
libc = "0.2.148"
[dependencies.smithay]
# git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures

View File

@@ -19,7 +19,9 @@ use self::core::eventloop::EventLoop;
use clap::Parser;
use directories::ProjectDirs;
use once_cell::sync::OnceCell;
use smithay::reexports::nix;
use stardust_xr::server;
use std::os::unix::process::CommandExt;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::Arc;
@@ -88,7 +90,12 @@ fn setup_tracing() {
}
fn main() {
ctrlc::set_handler(|| STOP_NOTIFIER.notify_waiters()).unwrap();
ctrlc::set_handler(|| {
if atty::isnt(atty::Stream::Stdout) {
STOP_NOTIFIER.notify_waiters()
}
})
.unwrap();
setup_tracing();
@@ -210,7 +217,9 @@ fn main() {
.clone()
.and_then(|p| p.canonicalize().ok())
.unwrap_or_else(|| project_dirs.config_dir().join("startup"));
let mut startup_command = Command::new(startup_script_path);
let mut startup_command = Command::new("bash");
startup_command.arg(startup_script_path);
startup_command.arg("&");
startup_command.stdin(Stdio::null());
startup_command.stdout(Stdio::null());
@@ -239,6 +248,13 @@ fn main() {
startup_command.env("CLUTTER_BACKEND", "wayland");
startup_command.env("SDL_VIDEODRIVER", "wayland");
}
unsafe {
startup_command.pre_exec(|| {
nix::unistd::setsid()
.map(|_| ())
.map_err(|_| std::io::ErrorKind::Other.into())
})
};
let child = startup_command.spawn().ok()?;
Some(child)
})();