Initial implementation of breadpaper
CLI tool that sets a wallpaper with awww, generates a pywal colour palette, and reloads bread-theme to recolour all running bread GTK apps. Includes CI workflows, bakery metadata, and Arch PKGBUILD.
This commit is contained in:
commit
a8b38597ff
14 changed files with 548 additions and 0 deletions
61
src/lib.rs
Normal file
61
src/lib.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
mod pywal;
|
||||
mod theme;
|
||||
mod wallpaper;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
|
||||
const IMAGE_EXTENSIONS: &[&str] = &["png", "jpg", "jpeg", "webp", "gif", "bmp"];
|
||||
|
||||
pub fn set(path: &Path) -> Result<()> {
|
||||
let path = validate(path)?;
|
||||
apply_wallpaper(&path)?;
|
||||
generate_palette(&path)?;
|
||||
reload_theme()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get() -> Result<PathBuf> {
|
||||
let home = std::env::var("HOME").context("HOME not set")?;
|
||||
let wal_file = PathBuf::from(home).join(".cache/wal/wal");
|
||||
|
||||
let contents = std::fs::read_to_string(&wal_file)
|
||||
.with_context(|| format!("no wallpaper set yet ({})", wal_file.display()))?;
|
||||
|
||||
Ok(PathBuf::from(contents.trim()))
|
||||
}
|
||||
|
||||
pub fn apply_wallpaper(path: &Path) -> Result<()> {
|
||||
wallpaper::apply(path)
|
||||
}
|
||||
|
||||
pub fn generate_palette(path: &Path) -> Result<()> {
|
||||
pywal::generate(path)
|
||||
}
|
||||
|
||||
pub fn reload_theme() -> Result<()> {
|
||||
theme::reload()
|
||||
}
|
||||
|
||||
fn validate(path: &Path) -> Result<PathBuf> {
|
||||
let canonical = path
|
||||
.canonicalize()
|
||||
.with_context(|| format!("not found: {}", path.display()))?;
|
||||
|
||||
let ext = canonical
|
||||
.extension()
|
||||
.and_then(|e| e.to_str())
|
||||
.unwrap_or("")
|
||||
.to_lowercase();
|
||||
|
||||
if !IMAGE_EXTENSIONS.contains(&ext.as_str()) {
|
||||
bail!(
|
||||
"unsupported file type '.{}' — expected one of: {}",
|
||||
ext,
|
||||
IMAGE_EXTENSIONS.join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
Ok(canonical)
|
||||
}
|
||||
36
src/main.rs
Normal file
36
src/main.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "breadpaper", about = "Wallpaper manager for the bread desktop")]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Command {
|
||||
/// Set wallpaper, generate pywal palette, and reload bread themes
|
||||
Set {
|
||||
/// Path to the image file
|
||||
path: PathBuf,
|
||||
},
|
||||
/// Print the current wallpaper path
|
||||
Get,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let result = match cli.command {
|
||||
Command::Set { path } => breadpaper::set(&path),
|
||||
Command::Get => breadpaper::get().map(|p| println!("{}", p.display())),
|
||||
};
|
||||
|
||||
if let Err(e) = result {
|
||||
eprintln!("error: {e:#}");
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
18
src/pywal.rs
Normal file
18
src/pywal.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
|
||||
pub fn generate(path: &Path) -> Result<()> {
|
||||
let status = Command::new("wal")
|
||||
.arg("-i")
|
||||
.arg(path)
|
||||
.arg("-n") // skip wal's own wallpaper backend; awww already set it
|
||||
.status()
|
||||
.context("failed to run wal — is python-pywal installed?")?;
|
||||
|
||||
if !status.success() {
|
||||
bail!("wal exited with {}", status);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
15
src/theme.rs
Normal file
15
src/theme.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
|
||||
pub fn reload() -> Result<()> {
|
||||
let status = Command::new("bread-theme")
|
||||
.arg("reload")
|
||||
.status()
|
||||
.context("failed to run bread-theme — is it installed?")?;
|
||||
|
||||
if !status.success() {
|
||||
bail!("bread-theme reload exited with {}", status);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
17
src/wallpaper.rs
Normal file
17
src/wallpaper.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
|
||||
pub fn apply(path: &Path) -> Result<()> {
|
||||
let status = Command::new("awww")
|
||||
.arg("set")
|
||||
.arg(path)
|
||||
.status()
|
||||
.context("failed to run awww — is awww-daemon running?")?;
|
||||
|
||||
if !status.success() {
|
||||
bail!("awww set exited with {}", status);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue