diff options
author | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-09-24 19:58:46 +0200 |
---|---|---|
committer | Anna (navi) Figueiredo Gomes <navi@vlhl.dev> | 2023-09-24 19:58:46 +0200 |
commit | 338b6d8b96fb1ef11727e0501525ab28047ba3d8 (patch) | |
tree | b942ebfb74f6be0d04fe8b2114ef4c4a20942023 /src | |
parent | 63b8e1b07e725384e4c8323af7f3e63600721a82 (diff) |
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 <navi@vlhl.dev>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 8 |
1 files changed, 4 insertions, 4 deletions
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<i32> { + fn get_parent_term_pid(&self, pid: i32, is_root: bool) -> Option<i32> { 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"))?; |