#[cfg(feature = "win")]
pub mod win;
#[cfg(feature = "x11")]
pub mod x11;
#[cfg(feature = "win")]
extern crate windows;
#[cfg(feature = "x11")]
extern crate xcb;
use std::sync::Arc;
use anyhow::Result;
#[derive(Debug, Clone)]
pub struct ActiveWindowData {
pub window_title: Arc<str>,
pub process_name: Arc<str>,
}
#[cfg_attr(test, mockall::automock)]
pub trait WindowManager {
fn get_active_window_data(&mut self) -> Result<ActiveWindowData>;
fn get_idle_time(&mut self) -> Result<u32>;
}
pub struct GenericWindowManager {
inner: Box<dyn WindowManager>,
}
impl GenericWindowManager {
pub fn new() -> Result<Self> {
cfg_if::cfg_if! {
if #[cfg(feature = "win")] {
use win::WindowsWindowManager;
Ok(Self {
inner: Box::new(WindowsWindowManager::new()),
})
}
else if #[cfg(feature = "x11")] {
use x11::LinuxWindowManager;
Ok(Self {
inner: Box::new(LinuxWindowManager::new()?),
})
}
else {
unimplemented!("No window manager was specified")
}
}
}
}
impl WindowManager for GenericWindowManager {
fn get_active_window_data(&mut self) -> Result<ActiveWindowData> {
self.inner.get_active_window_data()
}
fn get_idle_time(&mut self) -> Result<u32> {
self.inner.get_idle_time()
}
}