use regex::Regex; use std::{process::Command, process::Output, str}; pub fn get_title_clean() -> String { let title = get_window_info().title; let re = Regex::new(r"-?\d+([:.]\d+)+%?").unwrap(); re.replace_all(&title, "").to_string() } pub fn minimize_other(class: &str) { let window_info = get_window_info(); if &window_info.class != class { run(&format!("xdotool windowminimize {}", window_info.wid)); } } struct WindowInfo { title: String, class: String, wid: String, } fn run(cmd: &str) -> Option { let output = Command::new("sh").arg("-c").arg(cmd).output(); let Ok(Output { status, stdout, stderr: _, }) = output else { return None; }; if status.code() != Some(0) { return None; } let Ok(output_str) = str::from_utf8(&stdout) else { return None; }; Some(output_str.trim().to_string()) } fn get_window_info() -> WindowInfo { let none = WindowInfo { title: "none".to_string(), class: "none".to_string(), wid: "".to_string(), }; let Some(wid) = run("xdotool getactivewindow") else { return none; }; let Some(class) = run(&format!("xdotool getwindowclassname {wid}")) else { return none; }; let Some(title) = run(&format!("xdotool getwindowname {wid}")) else { return none; }; WindowInfo { title, class, wid } }