#desktop #background #api-bindings

wallpaper

Gets and sets the desktop wallpaper/background

8 stable releases

3.2.0 Jul 9, 2021
3.1.1 Jul 6, 2021
3.1.0 Jun 30, 2021
2.0.1 Jan 31, 2019
1.0.0 Jul 18, 2018

#515 in Web programming

Download history 76/week @ 2023-12-05 113/week @ 2023-12-12 147/week @ 2023-12-19 65/week @ 2023-12-26 48/week @ 2024-01-02 137/week @ 2024-01-09 138/week @ 2024-01-16 118/week @ 2024-01-23 122/week @ 2024-01-30 105/week @ 2024-02-06 168/week @ 2024-02-13 166/week @ 2024-02-20 192/week @ 2024-02-27 218/week @ 2024-03-05 155/week @ 2024-03-12 174/week @ 2024-03-19

751 downloads per month
Used in 11 crates (10 directly)

Unlicense

21KB
528 lines

wallpaper crate docs

This Rust library gets and sets the desktop wallpaper/background.

The supported desktops are:

  • Windows
  • macOS
  • GNOME
  • KDE
  • Cinnamon
  • Unity
  • Budgie
  • XFCE
  • LXDE
  • MATE
  • Deepin
  • Most Wayland compositors (set only, requires swaybg)
  • i3 (set only, requires feh)

Examples

use 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());
}

If you want to set an image as background via an URL, make sure you activated the from_url feature of the wallpaper crate on Cargo.toml:

[dependencies]
wallpaper = { version = "3", features = ["from_url"] }

Then, on your main.rs:

use 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());
}

Dependencies

~0.3–14MB
~158K SLoC