diff --git a/src/lib/monitor/windows.rs b/src/lib/monitor/windows.rs index e263b0b..9591bbb 100644 --- a/src/lib/monitor/windows.rs +++ b/src/lib/monitor/windows.rs @@ -1,22 +1,18 @@ use std::{fmt::Write}; use swayipc::WindowEvent; use crate::config::WindowIcon; -use regex::Regex; pub fn get_window_title(title_length: usize, window_event: WindowEvent, window_icons: Vec) -> String { let mut window_title = window_event.container.name.unwrap().trim_end().to_string(); -// println!("{}") for pair in window_icons { - println!("{}: {}",pair.icon,pair.substring); - let substring_regex = Regex::new(&pair.substring).unwrap().captures(&window_title); -// if window_title. - println!("{:?}",substring_regex); + if window_title.contains(&pair.substring) { + window_title = pair.icon + " " + &window_title.replace(&pair.substring, ""); + } + } - // window_title.trim(); - let pretrunc_window_title = window_title.clone(); - window_title.truncate(title_length); - if window_title.ne(&pretrunc_window_title) { - let _ = window_title.write_str("…"); + if window_title.len().gt(&title_length) { + window_title.truncate(title_length); + let _ = window_title.write_char('…'); } window_title } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e326568..007a0f3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,8 @@ use windows::get_window_title; #[path = "lib/monitor/workspaces.rs"] mod workspaces; use workspaces::get_workspace_name; + +use crate::config::Config; mod monitor; @@ -34,8 +36,9 @@ struct Cli { #[derive(Subcommand)] enum Commands { - /// does testing things + /// Prints the Currently Active Window Title WindowTitle, + // Launch, Lock, Rename, @@ -71,40 +74,46 @@ fn main() -> Fallible<()> { } match &cli.command { Commands::WindowTitle => { - println!("Print window title") - } + println!("Print window title"); + let sway_connection = Connection::new()?; + sway_connection.get_tree().unwrap(); +// println!("{:?}", sway_connection.get_tree().map(op)) + } Commands::Monitor { monitor_type } => { - match monitor_type { - MonitorTypes::Workspaces => { - println!("monitoring workspace changes!") - } - MonitorTypes::Windows => { - println!("monitoring window changes!") - } - MonitorTypes::Profile => { - println!("monitoring profile changes!") + match monitor_type { + MonitorTypes::Workspaces => { + println!("monitoring workspace changes!") + } + MonitorTypes::Windows => { + println!("monitoring window changes!"); + monitor_events(EventType::Window, config); + } + MonitorTypes::Profile => { + println!("monitoring profile changes!") + } } } - } + Commands::Launch => todo!(), + Commands::Lock => todo!(), + Commands::Rename => todo!(), + Commands::Profile => todo!(), + Commands::Shortcuts { global } => todo!(), } exit(0); +} - let subs = [ - EventType::Workspace, -// EventType::Output, -// EventType::Input, - EventType::Tick, -// EventType::Shutdown, -// EventType::Mode, - EventType::Window, -// EventType::BarStateUpdate, -// EventType::BarConfigUpdate, -// EventType::Binding, - ]; +pub fn monitor_events(event_type: EventType, config: Config) -> Fallible<()> { +/* let subs = [ + // Valid EventTypes: Workspace, Output, Input, Tick, Shutdown, Mode, Window, BarStateUpdate, BarConfigUpdate, Binding + //EventType::Workspace, + //EventType::Tick, + //EventType::Window, + event_type + ]; */ let sway_connection = Connection::new()?; // for event in Connection::new()?.subscribe(subs)? { - for event in sway_connection.subscribe(subs)? { + for event in sway_connection.subscribe([event_type])? { let e = event?; // println!("{:?}\n", e); match e {