diff --git a/Cargo.lock b/Cargo.lock index 09bb87d..65d80c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -684,6 +684,15 @@ dependencies = [ "ttf-parser", ] +[[package]] +name = "fork" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9788ce090af4bf8d6e8f43d3f7d12305c787456387bd2d88856fcda3aa1f0dca" +dependencies = [ + "libc", +] + [[package]] name = "freedesktop_entry_parser" version = "1.3.0" @@ -1497,6 +1506,7 @@ dependencies = [ "directories", "dirs", "ez-pixmap", + "fork", "glam", "image", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index c09c708..eb37e63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ color-eyre = "0.6.2" directories = "4.0.1" dirs = "4.0.0" ez-pixmap = "0.2.2" +fork = "0.1.20" glam = { version = "0.22.0", features = ["mint"] } image = "0.24.5" lazy_static = "1.4.0" diff --git a/examples/hexagon_launcher.rs b/examples/hexagon_launcher.rs index a3ee830..85cc8f3 100644 --- a/examples/hexagon_launcher.rs +++ b/examples/hexagon_launcher.rs @@ -32,8 +32,8 @@ impl Hex { } fn get_coords(&self) -> [f32; 3]{ - let x: f32 = 3.0/2.0 * APP_SIZE.to_f32()/2.0 * (-self.q-self.s).to_f32(); - let y = 3.0_f32.sqrt() * APP_SIZE.to_f32()/2.0 * ( (-self.q-self.s).to_f32()/2.0 + self.s.to_f32()); + let x = 3.0/2.0 * APP_SIZE/2.0 * (-self.q-self.s).to_f32(); + let y = 3.0_f32.sqrt() * APP_SIZE/2.0 * ( (-self.q-self.s).to_f32()/2.0 + self.s.to_f32()); [x,y,0.0] } diff --git a/src/protostar.rs b/src/protostar.rs index 621d550..eb62e45 100644 --- a/src/protostar.rs +++ b/src/protostar.rs @@ -2,7 +2,9 @@ use crate::xdg::{DesktopFile, Icon, IconType}; use color_eyre::eyre::{eyre, Result}; use glam::Quat; use mint::Vector3; -use nix::unistd::{execv, fork}; +use fork::{daemon, Fork, setsid}; +use std::process::{Command,Stdio}; +use std::os::unix::process::CommandExt; use stardust_xr_molecules::{ fusion::{ client::{Client, FrameInfo, RootHandler}, @@ -18,6 +20,7 @@ use stardust_xr_molecules::{ use std::{f32::consts::PI, ffi::CStr, sync::Arc}; use tween::{QuartInOut, Tweener}; use ustr::ustr; +use nix::unistd::fork; fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result { @@ -57,6 +60,7 @@ pub struct ProtoStar { field: BoxField, icon: Model, icon_shrink: Option>, + icon_grow: Option>, execute_command: String, } impl ProtoStar { @@ -125,6 +129,7 @@ impl ProtoStar { field, icon, icon_shrink: None, + icon_grow: None, execute_command, }) } @@ -142,9 +147,15 @@ impl RootHandler for ProtoStar { self.icon .set_scale(None, Vector3::from([scale; 3])) .unwrap(); - } else { - self.client.stop_loop(); + } + if let Some(icon_grow) = &mut self.icon_shrink { + if !icon_grow.is_finished(){ + let scale = icon_grow.move_by(info.delta); + self.icon + .set_scale(None, Vector3::from([scale; 3])) + .unwrap(); } + } } else if self.grabbable.grab_action().actor_stopped() { let startup_settings = StartupSettings::create(&self.field.client().unwrap()).unwrap(); self.icon @@ -166,19 +177,21 @@ impl RootHandler for ProtoStar { //TODO: split the executable string for the args tokio::task::spawn(async move { std::env::set_var("STARDUST_STARTUP_TOKEN", future.await.unwrap()); - if unsafe { fork() }.unwrap().is_parent() { - println!("Launching \"{}\"...", &executable); - execv::<&CStr>( - ustr("/bin/sh").as_cstr(), - &[ - ustr("/bin/sh").as_cstr(), - ustr("-c").as_cstr(), - ustr(&executable).as_cstr(), - ], - ) - .unwrap(); + unsafe { + Command::new(executable) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .pre_exec(|| { + setsid(); + Ok(()) + }) + .spawn() + .expect("Failed to start child process") } }); + self.icon_grow = Some(Tweener::quart_in_out(0.00, 0.03, 0.25)); //TODO make the scale a parameter + dbg!("reached here"); } } }