3 个稳定版本

2.0.0 2022 年 11 月 23 日
1.0.1 2022 年 11 月 22 日

#22 in #集合

Download history 13/week @ 2024-03-13 13/week @ 2024-03-20 72/week @ 2024-03-27 46/week @ 2024-04-03 7/week @ 2024-04-10 99/week @ 2024-04-17 44/week @ 2024-04-24 17/week @ 2024-05-01 46/week @ 2024-05-08 3/week @ 2024-05-15 4/week @ 2024-05-22 296/week @ 2024-05-29 122/week @ 2024-06-05 6/week @ 2024-06-12 8/week @ 2024-06-19 41/week @ 2024-06-26

每月 297 次下载
timewall 中使用

无授权

22KB
531 代码行

wallpape.rs crate docs

此 Rust 库用于获取和设置桌面壁纸/背景。

支持的桌面包括

  • Windows
  • macOS
  • GNOME
  • KDE
  • Cinnamon
  • Unity
  • Budgie
  • XFCE
  • LXDE
  • MATE
  • Deepin
  • 大多数 Wayland 合成器(仅设置,需要 swaybg)
  • i3(仅设置,需要 feh)

示例

use wallpape_rs as wallpaper;

fn main() {
    // Returns the wallpaper of the current desktop.
    println!("{:?}", wallpaper::get());
    // Sets the wallpaper for the current desktop from a file path.
    wallpaper::set_from_path("/usr/share/backgrounds/gnome/adwaita-day.png").unwrap();
    // Sets the wallpaper style.
    wallpaper::set_mode(wallpaper::Mode::Crop).unwrap();
    // Returns the wallpaper of the current desktop.
    println!("{:?}", wallpaper::get());
}

如果您想通过 URL 设置图片作为背景,请确保在 Cargo.toml 中激活 wallpaper crate 的 from_url 功能

[dependencies]
wallpape-rs = { version = "1.0.0", features = ["from_url"] }

然后,在您的 main.rs 中

use wallpape_rs as wallpaper;

fn main() {
    // Returns the wallpaper of the current desktop.
    println!("{:?}", wallpaper::get());
    // Sets the wallpaper for the current desktop from a URL.
    wallpaper::set_from_url("https://source.unsplash.com/random").unwrap();
    // Returns the wallpaper of the current desktop.
    println!("{:?}", wallpaper::get());
}

依赖项

~0.3–40MB
~559K SLoC