use crate::cli::{Config, RendererType};
use crate::daemon::render::native::NativeRenderer;
use crate::wallpaper::WallpaperCache;
use tokio::process::Child;
pub mod awww;
pub mod native;
mod swaybg;
pub struct Renderer {
swaybg_child: Option<Child>,
awww_bin: Option<String>,
native: NativeRenderer,
}
impl Renderer {
pub async fn new(config: &Config) -> anyhow::Result<Self> {
let awww_bin = match config.renderer {
RendererType::Awww => {
let bin = awww::detect_awww_binary().await;
awww::ensure_awww_daemon(&bin).await?;
Some(bin)
}
RendererType::Swaybg | RendererType::Native => None,
};
Ok(Self {
swaybg_child: None,
awww_bin,
native: NativeRenderer::new(),
})
}
pub async fn apply(
&mut self,
config: &Config,
cache: &WallpaperCache,
monitors: &[String],
) -> anyhow::Result<()> {
match config.renderer {
RendererType::Swaybg => swaybg::apply(cache, monitors, &mut self.swaybg_child).await,
RendererType::Awww => {
let bin = self.awww_bin.as_deref().expect("Renderer::new sets this");
awww::apply(config, cache, monitors, bin).await
}
RendererType::Native => {
self.native.apply(cache, monitors);
Ok(())
}
}
}
}