Skip to content

Commit

Permalink
Implement reload command
Browse files Browse the repository at this point in the history
Fixes #47.
  • Loading branch information
danyspin97 committed Apr 16, 2024
1 parent cd9eb31 commit 157b631
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fn main() {
}
SubCmd::NextWallpaper { monitors } => IpcMessage::NextWallpaper { monitors },
SubCmd::PreviousWallpaper { monitors } => IpcMessage::PreviousWallpaper { monitors },
SubCmd::ReloadWallpaper { monitors } => IpcMessage::ReloadWallpaper { monitors },
};
conn.write_all(&serde_json::to_vec(&msg).unwrap()).unwrap();
let mut buf = String::new();
Expand Down
2 changes: 2 additions & 0 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ pub enum SubCmd {
NextWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "previous")]
PreviousWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "reload")]
ReloadWallpaper { monitors: Vec<String> },
}
19 changes: 18 additions & 1 deletion daemon/src/image_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ pub struct ImagePicker {
action: Option<ImagePickerAction>,
sorting: ImagePickerSorting,
filelist_cache: Rc<RefCell<FilelistCache>>,
reload: bool,
}

impl ImagePicker {
Expand All @@ -153,6 +154,7 @@ impl ImagePicker {
Sorting::Descending => ImagePickerSorting::Descending(usize::MAX),
},
filelist_cache,
reload: false,
}
}

Expand Down Expand Up @@ -274,7 +276,7 @@ impl ImagePicker {
Some((img_path, index))
}
}
} else if path == self.current_img {
} else if path == self.current_img && !self.reload {
None
} else {
// path is not a directory and it's not the current image
Expand Down Expand Up @@ -367,6 +369,21 @@ impl ImagePicker {
ImagePickerSorting::Ascending(_) | ImagePickerSorting::Descending(_) => {}
}
}

#[inline]
pub fn reload(&mut self) {
self.reload = true;
}

#[inline]
pub fn reloaded(&mut self) {
self.reload = false;
}

#[inline]
pub fn is_reloading(&self) -> bool {
self.reload
}
}

#[cfg(test)]
Expand Down
8 changes: 8 additions & 0 deletions daemon/src/ipc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ pub fn handle_message(
surface.queue_draw(&qh);
}

IpcResponse::Ok
}),
IpcMessage::ReloadWallpaper { monitors } => check_monitors(wpaperd, &monitors).map(|_| {
for surface in collect_surfaces(wpaperd, monitors) {
surface.image_picker.reload();
surface.queue_draw(&qh);
}

IpcResponse::Ok
}),
};
Expand Down
6 changes: 5 additions & 1 deletion daemon/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ impl Surface {
self.renderer
.load_wallpaper(data.into(), self.wallpaper_info.mode)?;
self.renderer.start_transition(time);
self.image_picker.update_current_image(image_path, index);
if self.image_picker.is_reloading() {
self.image_picker.reloaded();
} else {
self.image_picker.update_current_image(image_path, index);
}
// Restart the counter
self.loading_image_tries = 0;
self.loading_image = None;
Expand Down
1 change: 1 addition & 0 deletions ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum IpcMessage {
NextWallpaper { monitors: Vec<String> },
PreviousWallpaper { monitors: Vec<String> },
AllWallpapers,
ReloadWallpaper { monitors: Vec<String> },
}

#[derive(Serialize, Deserialize)]
Expand Down

0 comments on commit 157b631

Please sign in to comment.