Git Product home page Git Product logo

wallpaper.rs's Introduction

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

wallpaper.rs's People

Contributors

alphastrata avatar andr35 avatar chhe avatar gmurayama avatar lrazovic avatar msrd0 avatar reujab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wallpaper.rs's Issues

Too many unnecessary dependencies when not using `set_from_url`

I am myself developing a crate to create wallpapers, and as it is now I feel reluctant to use wallpaper as a dependency because the set_from_url pulls in many dependencies which I am not using (I only need the set_from_path function), and I would feel bad forcing my users to compile reqwest, url and all of their many dependencies.
Apart from this single drawback, wallpaper is the best crate of its kind that I could find, and I would love for it to be a bit more lightweight for my use-case.

Case in point:

$ cd wallpaper.rs
$ cargo tree | wc -l
312

I know that there are duplicates, but this is still a bit much.

Proposal: make reqwest and url optional dependencies. Of course, they would be opt-out to avoid breaking any other crates.

If this proposal seems reasonable to you, I already have a pull request ready that implements it by adding a "from-url" feature enabled by default and that one can opt out of:

$ cd wallpaper.rs
$ cargo tree --no-default-features | wc -l
5

[Broken] Gnome 43.3

This simple example does not change my background:

fn main() {
  wallpaper::set_from_path("/home/septias/Pictures/wallpapers/t3_10aryph.png");
}

Wallpaper doesnt change on MacOS

When using this library on MacOS, the wallpaper does not change. Only the login screen changes after executing "killall Dock" in the command line, but the wallpaper remains unchanged.

publish v4.0.0 to crates.io

Currently for gnome dark mode, I am having to point to this git repository - it would be pretty helpful if you pushed 4.0.0 to crates.io
:)

macos get default wallpaper failed

For macos 14, default wallpaper is /System/Library/CoreServices/DefaultDesktop.heic, wallpaper::get() return Err("osascript exited with status code 1")

osascript -e 'tell application "System Events" to picture of current desktop'

Doesn't work on manjaro

I'm trying to run this minimal example

use wallpaper;

fn main() {
    wallpaper::set_from_path(
        "<private>/t3_reaw76.jpeg",
    )
    .unwrap()
}

but it doesn't set the new background even though the image exists an can be set manually.

Linux: 5.15.46-1
rust: stable @ 1.61.0 (2022-05-18)

<gnome-version>
 <platform>42</platform>
 <minor>2</minor>
 <micro>0</micro>
 <distributor>Arch Linux</distributor>
 <!--<date></date>-->
</gnome-version>

XFCE error changing wallpaper

When I try to change the wallpaper in XFCE (Arch Linux) I get this error:
thread 'main' panicked at 'called Result::unwrap()on anErr value: "xfconf-query exited with status code 1"', src/libcore/result.rs:1084:5

This is because this library uses this command to change the wallpaper in XFCE: xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image -s PATH, but in Arch (I do not know other OS) the property is /backdrop/screen0/monitorLVDS1/workspace0/last-image instead of /backdrop/screen0/monitor0/workspace0/last-image

[BUG] master does not compile at apple and windows

It looks like that the current master is broken on windows and mac:

❯ cargo check --target x86_64-apple-darwin
    Checking wallpaper v4.0.0 (https://github.com/reujab/wallpaper.rs.git#20270387)
    Checking clap v3.2.23
error[E0433]: failed to resolve: use of undeclared crate or module `ini`
  --> /home/lukas/.cargo/git/checkouts/wallpaper.rs-e56f8913492c51cc/2027038/src/error.rs:14:24
   |
14 |     InvalidIni(#[from] ini::ini::Error),
   |                        ^^^ use of undeclared crate or module `ini`

error[E0412]: cannot find type `Path` in this scope
  --> /home/lukas/.cargo/git/checkouts/wallpaper.rs-e56f8913492c51cc/2027038/src/macos.rs:20:14
   |
20 |     P: AsRef<Path> + std::fmt::Display,
   |              ^^^^ not found in this scope
   |
help: consider importing this struct
   |
1  | use std::path::Path;
   |

error[E0308]: mismatched types
  --> /home/lukas/.cargo/git/checkouts/wallpaper.rs-e56f8913492c51cc/2027038/src/macos.rs:28:39
   |
18 | pub fn set_from_path<P>(path: P) -> Result<()>
   |                      - this type parameter
...
28 |                 enquote::enquote('"', path),
   |                 ----------------      ^^^^ expected `&str`, found type parameter `P`
   |                 |
   |                 arguments to this function are incorrect
   |
   = note:   expected reference `&str`
           found type parameter `P`
note: function defined here
  --> /home/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/enquote-1.1.0/src/lib.rs:19:8
   |
19 | pub fn enquote(quote: char, s: &str) -> String {
   |        ^^^^^^^

Some errors have detailed explanations: E0308, E0412, E0433.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `wallpaper` due to 3 previous errors
❯ cargo check --target x86_64-pc-windows-gnu
    Checking wallpaper v4.0.0 (https://github.com/reujab/wallpaper.rs.git#20270387)
    Checking clap v3.2.23
error[E0433]: failed to resolve: use of undeclared crate or module `ini`
  --> /home/lukas/.cargo/git/checkouts/wallpaper.rs-e56f8913492c51cc/2027038/src/error.rs:14:24
   |
14 |     InvalidIni(#[from] ini::ini::Error),
   |                        ^^^ use of undeclared crate or module `ini`

error[E0433]: failed to resolve: use of undeclared crate or module `enquote`
  --> /home/lukas/.cargo/git/checkouts/wallpaper.rs-e56f8913492c51cc/2027038/src/error.rs:17:21
   |
17 |     Enquote(#[from] enquote::Error),
   |                     ^^^^^^^ use of undeclared crate or module `enquote`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `wallpaper` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

Linux does work fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.