Skip to content

Commit

Permalink
Add --no-cache option to swww-daemon
Browse files Browse the repository at this point in the history
With the deprecation of swww init, swww-daemon was missing a key
featureof allowing users to start the deamon without caching wallpapers
fromprevious sessions. This is a step on fixing this issue, although
thisstill invalidates loading the cache even for new outputs (monitor
re-connections).

fix formatting
  • Loading branch information
lucasreis1 committed Apr 18, 2024
1 parent 4bcb979 commit b6fc649
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
15 changes: 14 additions & 1 deletion daemon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use utils::ipc::PixelFormat;
pub struct Cli {
pub format: Option<PixelFormat>,
pub quiet: bool,
pub no_cache: bool,
}

impl Cli {
pub fn new() -> Self {
let mut quiet = false;
let mut no_cache = false;
let mut format = None;
let mut args = std::env::args();
args.next(); // skip the first argument
Expand All @@ -25,6 +27,7 @@ impl Cli {
}
},
"-q" | "--quiet" => quiet = true,
"--no-cache" => no_cache = true,
"-h" | "--help" => {
println!("swww-daemon");
println!();
Expand All @@ -40,6 +43,12 @@ impl Cli {
println!(" Whatever you chose, make sure you compositor actually supports it!");
println!(" 'xrgb' is the most compatible one.");
println!();
println!(" --no-cache");
println!(
" Don't search the cache for the last wallpaper for each output"
);
println!(" Useful if you always want to select which iamge `swww` loads manually using `swww img`");
println!();
println!(" -q|--quiet will only log errors");
println!(" -h|--help print help");
println!(" -V|--version print version");
Expand All @@ -57,6 +66,10 @@ impl Cli {
}
}

Self { format, quiet }
Self {
format,
quiet,
no_cache,
}
}
}
12 changes: 7 additions & 5 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn main() -> Result<(), String> {
registry_queue_init(&conn).expect("failed to initialize the event queue");
let qh = event_queue.handle();

let mut daemon = Daemon::new(&globals, &qh);
let mut daemon = Daemon::new(&globals, &qh, cli.no_cache);
// roundtrip to get the shm formats before setting up the outputs
event_queue.roundtrip(&mut daemon).unwrap();

Expand Down Expand Up @@ -335,10 +335,11 @@ struct Daemon {
// swww stuff
wallpapers: Vec<Arc<Wallpaper>>,
animator: Animator,
use_cache: bool,
}

impl Daemon {
fn new(globals: &GlobalList, qh: &QueueHandle<Self>) -> Self {
fn new(globals: &GlobalList, qh: &QueueHandle<Self>, no_cache: bool) -> Self {
// The compositor (not to be confused with the server which is commonly called the compositor) allows
// configuring surfaces to be presented.
let compositor: WlCompositor = globals
Expand Down Expand Up @@ -372,6 +373,7 @@ impl Daemon {

wallpapers: Vec::new(),
animator: Animator::new(),
use_cache: !no_cache,
}
}

Expand Down Expand Up @@ -530,7 +532,7 @@ impl Dispatch<wl_output::WlOutput, ()> for Daemon {
height,
..
} => wallpaper.set_dimensions(width, height),
wl_output::Event::Done => wallpaper.commit_surface_changes(),
wl_output::Event::Done => wallpaper.commit_surface_changes(state.use_cache),
wl_output::Event::Scale { factor } => match NonZeroI32::new(factor) {
Some(factor) => wallpaper.set_scale(Scale::Whole(factor)),
None => error!("received scale factor of 0 from compositor"),
Expand Down Expand Up @@ -579,7 +581,7 @@ impl Dispatch<WlSurface, ()> for Daemon {
match NonZeroI32::new(factor) {
Some(factor) => {
wallpaper.set_scale(Scale::Whole(factor));
wallpaper.commit_surface_changes();
wallpaper.commit_surface_changes(state.use_cache);
}
None => error!("received scale factor of 0 from compositor"),
}
Expand Down Expand Up @@ -760,7 +762,7 @@ impl Dispatch<WpFractionalScaleV1, WlSurface> for Daemon {
match NonZeroI32::new(scale as i32) {
Some(factor) => {
wallpaper.set_scale(Scale::Fractional(factor));
wallpaper.commit_surface_changes();
wallpaper.commit_surface_changes(state.use_cache);
}
None => error!("received scale factor of 0 from compositor"),
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ impl Wallpaper {
}

#[inline]
pub fn commit_surface_changes(&self) {
pub fn commit_surface_changes(&self, use_cache: bool) {
let mut inner = self.inner.write().unwrap();
let staging = self.inner_staging.lock().unwrap();

if inner.name != staging.name {
if inner.name != staging.name && use_cache {
let name = staging.name.clone().unwrap_or("".to_string());
if let Err(e) = std::thread::Builder::new()
.name("cache loader".to_string())
Expand Down

0 comments on commit b6fc649

Please sign in to comment.