Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ wallbash status # Show daemon status

# options for "set"
wallbash set [option] <value>
-p, --palette <color> # Generate color palette (auto, dark, light)
-w, --wall <file> # Wallpaper file /path/to/file.img
-c, --cycle <signed int> # Cycle in current folder (+1, -2, etc.)
-p, --palette <color> # Generate color palette (auto, dark, light)
-m, --mode <scale> # Scaling mode (cover, fit, original)
-a, --anchor <1-9> # Anchor point (1=top-left ... 9=bottom-right)
-w, --wall <file> # Wallpaper file /path/to/file.img
```


Expand Down
107 changes: 56 additions & 51 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub mod wayland;
pub mod vulkan;
pub mod filters;
pub mod colors;

use std::{
env, io::Write,
os::unix::net::UnixStream,
Expand Down Expand Up @@ -48,11 +47,11 @@ fn print_usage() {

::Options
wallbash set [option] <value>
-p, --palette <color> | Generate color palette (auto, dark, light)
-w, --wall <file> | Wallpaper file /path/to/file.img
-c, --cycle <signed int> | Cycle in current folder (+1, -2, etc.)
-p, --palette <color> | Generate color palette (auto, dark, light)
-m, --mode <scale> | Scaling mode (cover, fit, original)
-a, --anchor <1-9> | Anchor point (1=top-left ... 9=bottom-right)
-w, --wall <file> | Wallpaper file /path/to/file.img
" );
}

Expand Down Expand Up @@ -170,43 +169,6 @@ fn parse_args(args: &[String]) -> CachedState {
// get previous state
let mut state = load_cache();

// color generation - default "skip"
if let Some(pos) = args.iter().position(|a| a == "--palette" || a == "-p") {
let pal = args.get(pos + 1)
.filter(|s| matches!(s.as_str(), "auto" | "dark" | "light"))
.map(|s| s.clone()).unwrap_or_else(|| "skip".into());
state.palette = pal;
}

// mode – default "cover"
if let Some(pos) = args.iter().position(|a| a == "--mode" || a == "-m") {
let m = args.get(pos + 1)
.filter(|s| matches!(s.as_str(), "cover" | "fit" | "original"))
.map(|s| s.clone()).unwrap_or_else(|| "cover".into());
state.mode = m;
}

// anchor – default "center"
if let Some(pos) = args.iter().position(|a| a == "--anchor" || a == "-a") {
let anchor = args.get(pos + 1)
.and_then(|s| s.parse::<u8>().ok())
.filter(|&n| (1..10).contains(&n));
let (ax, ay) = match anchor {
Some(1) => (0.0, 0.0),
Some(2) => (0.5, 0.0),
Some(3) => (1.0, 0.0),
Some(4) => (0.0, 0.5),
Some(5) => (0.5, 0.5),
Some(6) => (1.0, 0.5),
Some(7) => (0.0, 1.0),
Some(8) => (0.5, 1.0),
Some(9) => (1.0, 1.0),
_ => (0.5, 0.5),
};
state.anchor_x = ax;
state.anchor_y = ay;
}

// wallpaper – default "cached"
let wall = args.iter().position(|a| a == "--wall" || a == "-w")
.and_then(|i| args.get(i + 1).cloned())
Expand Down Expand Up @@ -242,13 +204,50 @@ fn parse_args(args: &[String]) -> CachedState {
}
state.wall = cycle_wallpaper(&state.wall, cycle);
}

// cache and return state
if state.wall.is_empty() {
eprintln!("Missing wallpaper (use --wall <path> or bare path)");
print_usage();
std::process::exit(1);
}

// color generation - default "skip"
if let Some(pos) = args.iter().position(|a| a == "--palette" || a == "-p") {
let pal = args.get(pos + 1)
.filter(|s| matches!(s.as_str(), "auto" | "dark" | "light"))
.map(|s| s.clone()).unwrap_or_else(|| "skip".into());
state.palette = pal;
}

// mode – default "cover"
if let Some(pos) = args.iter().position(|a| a == "--mode" || a == "-m") {
let m = args.get(pos + 1)
.filter(|s| matches!(s.as_str(), "cover" | "fit" | "original"))
.map(|s| s.clone()).unwrap_or_else(|| "cover".into());
state.mode = m;
}

// anchor – default "center"
if let Some(pos) = args.iter().position(|a| a == "--anchor" || a == "-a") {
let anchor = args.get(pos + 1)
.and_then(|s| s.parse::<u8>().ok())
.filter(|&n| (1..10).contains(&n));
let (ax, ay) = match anchor {
Some(1) => (0.0, 0.0),
Some(2) => (0.5, 0.0),
Some(3) => (1.0, 0.0),
Some(4) => (0.0, 0.5),
Some(5) => (0.5, 0.5),
Some(6) => (1.0, 0.5),
Some(7) => (0.0, 1.0),
Some(8) => (0.5, 1.0),
Some(9) => (1.0, 1.0),
_ => (0.5, 0.5),
};
state.anchor_x = ax;
state.anchor_y = ay;
}

// cache and return state
save_cache(&state);
state
}
Expand All @@ -274,13 +273,10 @@ fn main() {
state.palette, state.mode, state.anchor_x, state.anchor_y, state.wall);
if !check_daemon() {
println!("Starting daemon");
let log_file = std::fs::File::create(LOG_FILE).expect("Cannot create log");
let log = std::fs::File::create(LOG_FILE).expect("Cannot create log");
let mut child = Command::new(env::current_exe().unwrap())
.arg("start")
.stdout(log_file.try_clone().unwrap())
.stderr(log_file)
.spawn()
.expect("Failed to start daemon");
.arg("start").stdout(log.try_clone().unwrap()).stderr(log)
.spawn().expect("Failed to start daemon");
if let Err(e) = wait_loop() {
eprintln!("Error {}", e);
let _ = child.kill();
Expand All @@ -293,14 +289,23 @@ fn main() {
}
Some("stop") => {
if let Err(e) = send_command("stop") {
eprintln!("Failed to stop daemon {}. Is it running?", e);
eprintln!("Failed to stop daemon {}. Is it even running?", e);
}
}
Some("status") => {
if check_daemon() {
println!("Daemon is running.");
println!("[wallbash] :: Daemon is running");
} else {
println!("[wallbash] :: Daemon is not running");
}
let state = load_cache();
if state.wall.is_empty() {
println!("[wallbash] :: No wallpaper cached yet");
} else {
println!("Daemon is not running.");
println!("Wallpaper :: {}", state.wall);
println!("Palette :: {}", state.palette);
println!("Mode :: {}", state.mode);
println!("Anchor :: ({:.1}, {:.1})", state.anchor_x, state.anchor_y);
}
}
_ => print_usage()
Expand Down
2 changes: 1 addition & 1 deletion src/wallbash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ impl DaemonState {
let resolved = std::fs::canonicalize(&path)
.map(|p| p.to_string_lossy().to_string())
.unwrap_or(path);
println!("[wallbash] loading '{}' ({}|{}|ax:{:?}|ay:{:?})", resolved, palette, mode, anchor_x, anchor_y);
println!("[wallbash] loading '{}' ({}|{}|ax:{:.1}|ay:{:.1})", resolved, palette, mode, anchor_x, anchor_y);

let effect = |tex: &vulkan::VulkanTexture| {
if mode != "cover" {
Expand Down
Loading