Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pause/resume auto wallpaper sequence #68

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
431 changes: 285 additions & 146 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ categories = ["command-line-utilities", "multimedia"]
[dependencies]
wpaperd-ipc = { path = "../ipc", version = "1.0.0" }
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"

[build-dependencies]
clap = { version = "4.5.4", features = ["derive", "cargo"] }
Expand Down
2 changes: 2 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ fn main() {
SubCmd::NextWallpaper { monitors } => IpcMessage::NextWallpaper { monitors },
SubCmd::PreviousWallpaper { monitors } => IpcMessage::PreviousWallpaper { monitors },
SubCmd::ReloadWallpaper { monitors } => IpcMessage::ReloadWallpaper { monitors },
SubCmd::PauseWallpaper { monitors } => IpcMessage::PauseWallpaper { monitors },
SubCmd::ResumeWallpaper { monitors } => IpcMessage::ResumeWallpaper { monitors },
};
conn.write_all(&serde_json::to_vec(&msg).unwrap()).unwrap();
let mut buf = String::new();
Expand Down
4 changes: 4 additions & 0 deletions cli/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ pub enum SubCmd {
PreviousWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "reload")]
ReloadWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "pause")]
PauseWallpaper { monitors: Vec<String> },
#[clap(visible_alias = "resume")]
ResumeWallpaper { monitors: Vec<String> },
}
10 changes: 5 additions & 5 deletions daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ rust-version = "1.61.0"
wpaperd-ipc = { path = "../ipc", version = "1.0.0" }
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
color-eyre = { version = "0.6.3", default-features = false }
flexi_logger = { version = "0.28.0", default-features = false, features = ["colors"] }
flexi_logger = { version = "0.28.1", default-features = false, features = ["colors"] }
image = "0.25.1"
hotwatch = "0.5.0"
humantime-serde = "1.1.1"
log = "0.4.21"
new_mime_guess = "4.0.1"
nix = { version = "0.28.0", features = ["process"] }
rand = "0.8.5"
serde = { version = "1.0.198", features = ["derive", "rc"] }
serde = { version = "1.0.203", features = ["derive", "rc"] }
smithay-client-toolkit = { version = "0.18.1", default-features = false, features = [ "calloop" ] }
toml = "0.8.12"
toml = "0.8.13"
xdg = "2.5.2"
walkdir = "2.5.0"
dirs = "5.0.1"
serde_json = "1.0.116"
wayland-egl = "0.32.0"
serde_json = "1.0.117"
wayland-egl = "0.32.1"
khronos-egl = { version = "6.0.0", features = [ "static" ] }

[build-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions daemon/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub struct SerializedWallpaperInfo {
pub mode: Option<BackgroundMode>,
pub queue_size: Option<usize>,
pub transition_time: Option<u32>,
/// Determines if we should show the transition between black and first

/// Determines if we should show the transition between black and first
/// wallpaper. `Some(false)` means we instantly cut to the first wallpaper,
/// `Some(true)` means we fade from black to the first wallpaper.
///
Expand Down Expand Up @@ -146,7 +146,7 @@ impl SerializedWallpaperInfo {
mode,
drawn_images_queue_size,
transition_time,
initial_transition
initial_transition,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/image_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl ImagePicker {
}

// Otherwise pick a new random image that has not been drawn before
// Try 5 times, then get a random image. We do this because it might appen
// Try 5 times, then get a random image. We do this because it might happen
// that the queue is bigger than the amount of available wallpapers
let mut tries = 5;
loop {
Expand Down
17 changes: 16 additions & 1 deletion daemon/src/ipc_server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! IPC socket server.
//! Based on https://github.com/catacombing/catacomb/blob/master/src/ipc_server.rs
//! Based on <https://github.com/catacombing/catacomb/blob/master/src/ipc_server.rs>

use std::collections::HashSet;
use std::fs;
Expand Down Expand Up @@ -123,6 +123,7 @@ pub fn handle_message(

IpcResponse::Ok
}),

IpcMessage::ReloadWallpaper { monitors } => check_monitors(wpaperd, &monitors).map(|_| {
for surface in collect_surfaces(wpaperd, monitors) {
surface.image_picker.reload();
Expand All @@ -131,6 +132,20 @@ pub fn handle_message(

IpcResponse::Ok
}),

IpcMessage::PauseWallpaper { monitors } => check_monitors(wpaperd, &monitors).map(|_| {
for surface in collect_surfaces(wpaperd, monitors) {
surface.pause();
}
IpcResponse::Ok
}),

IpcMessage::ResumeWallpaper { monitors } => check_monitors(wpaperd, &monitors).map(|_| {
for surface in collect_surfaces(wpaperd, monitors) {
surface.resume();
}
IpcResponse::Ok
}),
};

let mut stream = BufWriter::new(ustream);
Expand Down
13 changes: 11 additions & 2 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,21 @@ fn run(opts: Opts, xdg_dirs: BaseDirectories) -> Result<()> {
// We cannot use WlSurface::frame() because it only works for windows that are
// already visible, hence we need to draw for the first time and then commit.
wpaperd.surfaces.iter_mut().for_each(|surface| {
if surface.is_configured() && !surface.drawn() {
if !surface.is_configured() {
return;
};

if !surface.drawn() {
surface.add_timer(None, &event_loop.handle(), qh.clone());
if let Err(err) = surface.draw(&qh, 0) {
error!("{err:?}");
}
};
}
// If the surface has already been drawn for the first time, then handle pausing/resuming
// the automatic wallpaper sequence.
else {
surface.handle_pause_state(&event_loop.handle(), qh.clone())
};
});

event_loop
Expand Down
2 changes: 1 addition & 1 deletion daemon/src/socket.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Calloop socket event source.
//!
//! This module provides a Calloop event source for Unix domain sockets.
//! https://github.com/catacombing/catacomb/blob/master/src/socket.rs
//! <https://github.com/catacombing/catacomb/blob/master/src/socket.rs>

use std::io::{self, ErrorKind};
use std::os::unix::net::{UnixListener, UnixStream};
Expand Down
Loading
Loading