diff --git a/cli/src/main.rs b/cli/src/main.rs index a12c457..0e31b75 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -20,6 +20,7 @@ enum SubCmd { AllWallpapers, NextWallpaper { monitors: Vec }, PreviousWallpaper { monitors: Vec }, + ReloadConfig, } fn main() { @@ -31,6 +32,7 @@ fn main() { SubCmd::AllWallpapers => IpcMessage::AllWallpapers, SubCmd::NextWallpaper { monitors } => IpcMessage::NextWallpaper { monitors }, SubCmd::PreviousWallpaper { monitors } => IpcMessage::PreviousWallpaper { monitors }, + SubCmd::ReloadConfig => IpcMessage::ReloadConfig, }; conn.write_all(&serde_json::to_vec(&msg).unwrap()).unwrap(); // Add a new line after the message diff --git a/daemon/src/ipc_server.rs b/daemon/src/ipc_server.rs index 7a6b7fa..94351e0 100644 --- a/daemon/src/ipc_server.rs +++ b/daemon/src/ipc_server.rs @@ -120,6 +120,11 @@ fn handle_message(buffer: &mut String, ustream: UnixStream, wpaperd: &mut Wpaper IpcResponse::Ok }), + + IpcMessage::ReloadConfig => { + wpaperd.reload_config()?; + Ok(IpcResponse::Ok) + } }; let mut stream = BufWriter::new(ustream); diff --git a/daemon/src/wallpaper_config.rs b/daemon/src/wallpaper_config.rs index c33fc96..85009b0 100644 --- a/daemon/src/wallpaper_config.rs +++ b/daemon/src/wallpaper_config.rs @@ -10,7 +10,7 @@ use serde::Deserialize; use crate::wallpaper_info::WallpaperInfo; -#[derive(Deserialize, PartialEq)] +#[derive(Deserialize)] pub struct WallpaperConfig { #[serde(flatten)] data: HashMap>, @@ -53,3 +53,9 @@ Either remove `duration` or set `path` to a directory" self.data.get(name).unwrap_or(&self.default_config).clone() } } + +impl PartialEq for WallpaperConfig { + fn eq(&self, other: &Self) -> bool { + self.data == other.data + } +} diff --git a/daemon/src/wpaperd.rs b/daemon/src/wpaperd.rs index ef1b491..1f13c7c 100644 --- a/daemon/src/wpaperd.rs +++ b/daemon/src/wpaperd.rs @@ -1,5 +1,6 @@ use std::sync::{Arc, Mutex}; +use color_eyre::eyre::Context; use color_eyre::Result; use smithay_client_toolkit::compositor::{CompositorHandler, CompositorState}; use smithay_client_toolkit::output::{OutputHandler, OutputState}; @@ -50,6 +51,30 @@ impl Wpaperd { use_scaled_window, }) } + + pub fn reload_config(&mut self) -> Result<()> { + let mut wallpaper_config = self.wallpaper_config.lock().unwrap(); + let new_config = + WallpaperConfig::new_from_path(&wallpaper_config.path).with_context(|| { + format!( + "reading configuration from file {:?}", + wallpaper_config.path + ) + }); + match new_config { + Ok(config) => { + if !(*wallpaper_config == config) { + *wallpaper_config = config; + log::info!("Configuration updated"); + } + Ok(()) + } + Err(err) => { + log::error!("{:?}", err); + Err(err) + } + } + } } impl CompositorHandler for Wpaperd { diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index 92869e1..c5f6180 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -9,6 +9,7 @@ pub enum IpcMessage { NextWallpaper { monitors: Vec }, PreviousWallpaper { monitors: Vec }, AllWallpapers, + ReloadConfig, } #[derive(Serialize, Deserialize)]