trait Client { fn supported(&mut self) -> bool; fn current_application(&mut self) -> Option; } pub struct WMClient { name: String, client: Box, supported: Option, last_application: String, } impl WMClient { fn new(name: &str, client: Box) -> WMClient { WMClient { name: name.to_string(), client, supported: None, last_application: String::new(), } } pub fn current_application(&mut self) -> Option { if let None = self.supported { let supported = self.client.supported(); self.supported = Some(supported); println!("application-client: {} (supported: {})", self.name, supported); } if !self.supported.unwrap() { return None; } let result = self.client.current_application(); if let Some(application) = &result { if &self.last_application != application { self.last_application = application.clone(); println!("application: {}", application); } } result } } #[cfg(feature = "gnome")] mod gnome_client; #[cfg(feature = "gnome")] pub fn build_client() -> WMClient { WMClient::new("GNOME", Box::new(gnome_client::GnomeClient::new())) } #[cfg(feature = "sway")] mod sway_client; #[cfg(feature = "sway")] pub fn build_client() -> WMClient { WMClient::new("Sway", Box::new(sway_client::SwayClient::new())) } #[cfg(feature = "x11")] mod x11_client; #[cfg(feature = "x11")] pub fn build_client() -> WMClient { WMClient::new("X11", Box::new(x11_client::X11Client::new())) } #[cfg(not(any(feature = "gnome", feature = "sway", feature = "x11")))] mod null_client; #[cfg(not(any(feature = "gnome", feature = "sway", feature = "x11")))] pub fn build_client() -> WMClient { WMClient::new("none", Box::new(null_client::NullClient)) }