From 338b6d8b96fb1ef11727e0501525ab28047ba3d8 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sun, 24 Sep 2023 19:58:46 +0200 Subject: fix new terminals being hidden the get_pid function was considering newly spawned terminals as the parents of themselves. adds a check for the recursion. Signed-off-by: Anna (navi) Figueiredo Gomes --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b251bab..280afb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ struct WindowHider { } impl WindowHider { - fn get_parent_term_pid(&self, pid: i32) -> Option { + fn get_parent_term_pid(&self, pid: i32, is_root: bool) -> Option { let mut file = String::new(); File::open(format!("/proc/{pid}/stat")).expect("procfs stat doesn't exist").read_to_string(&mut file).unwrap(); let re = Regex::new(r"\d+ \((.*)\) (\w) (\d+) \d+").unwrap().captures(&file).unwrap(); @@ -17,20 +17,20 @@ impl WindowHider { println!("looking for {pid}. {name}, {status}, {ppid}"); match name { - _ if name == self.term => { + _ if name == self.term && !is_root => { Some(pid) }, _ if name == "init" => { None } _ => { - self.get_parent_term_pid(ppid) + self.get_parent_term_pid(ppid, false) } } } fn hide(&self, conn: &mut Connection, pid: i32) -> Result<(), swayipc::Error> { - let ppid = self.get_parent_term_pid(pid); + let ppid = self.get_parent_term_pid(pid, true); if let Some(ppid) = ppid { println!("found parent pid of {pid} as {ppid}"); conn.run_command(format!("[pid={ppid}] mark --add {pid}, move scratchpad"))?; -- cgit v1.2.3