Giter Club home page Giter Club logo

windows-wallpaper's Introduction

windows-wallpaper

Manage the desktop wallpaper on Windows

Requires Windows 10 or later.

Install

Download the binary and put it somewhere in your %path%.

Usage

# Set
wallpaper set unicorn.jpg

# Set with scaling options
wallpaper set unicorn.jpg --scale [center | stretch | tile |  span | fit | fill]

# Get
wallpaper get
> /Users/sindresorhus/unicorn.jpg

Build

Inside the project's folder:

cargo build --release

Related

  • wallpaper - Get or set the desktop wallpaper.

windows-wallpaper's People

Contributors

beyluta avatar brandon93s avatar martial-plains avatar sindresorhus avatar tangdaoyuan 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-wallpaper's Issues

Rewrite in Rust

I think Rust would be much more maintainable than C++.

I asked ChatGPT to convert the existing C++ to Rust. That may be a good starting point:

extern crate com;

use com::{com_interface, ComRc, ComItf};
use std::ffi::OsString;
use std::io::{self, Write};
use winapi::{LPWSTR, MAX_PATH, WPSTYLE_SPAN, WPSTYLE_CENTER, WPSTYLE_TILE, WPSTYLE_STRETCH, WPSTYLE_KEEPASPECT};

#[com_interface("6D5140C1-7436-11CE-8034-00AA006009FA")]
pub trait IActiveDesktop: ComItf {
fn GetWallpaper(&self, wp: LPWSTR, len: i32, flags: i32) -> HRESULT;
fn SetWallpaper(&self, wp: LPWSTR, flags: i32) -> HRESULT;
fn SetWallpaperOptions(&self, opts: &WALLPAPEROPT, flags: i32) -> HRESULT;
fn ApplyChanges(&self, flags: i32) -> HRESULT;
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
struct WALLPAPEROPT {
dwSize: u32,
dwStyle: i32,
}

fn get_wallpaper(sz_wallpaper: &mut [u16]) -> io::Result<()> {
unsafe {
let result = CoInitialize(std::ptr::null_mut());
if result != S_OK {
return Err(io::Error::new(
io::ErrorKind::Other,
"Failed to initialize COM",
));
}
let mut p_desk: *mut IActiveDesktop = std::ptr::null_mut();
let hr = CoCreateInstance(
&CLSID_ActiveDesktop,
std::ptr::null_mut(),
CLSCTX_INPROC_SERVER,
&IID_IActiveDesktop,
&mut p_desk as *mut *mut IActiveDesktop as *mut *mut std::ffi::c_void,
);
if hr != S_OK {
return Err(io::Error::new(
io::ErrorKind::Other,
"Failed to get the desktop wallpaper",
));
}
(*p_desk).GetWallpaper(sz_wallpaper.as_mut_ptr(), MAX_PATH, 0);
(*p_desk).Release();
CoFreeUnusedLibraries();
CoUninitialize();
}
Ok(())
}

fn set_wallpaper(full_path: &[u16], wp_style: i32) -> io::Result<()> {
unsafe {
let result = CoInitialize(std::ptr::null_mut());
if result != S_OK {
return Err(io::Error::new(
io::ErrorKind::Other,
"Failed to initialize COM",
));
}
let mut p_desk: *mut IActiveDesktop = std::ptr::null_mut();
let hr = CoCreateInstance(
&CLSID_ActiveDesktop,
std::ptr::null_mut(),

(It's a little bit truncated)

Unicode issue

Lets say we have an image called få.jpg. Running wallpaper få.jpg correctly sets the desktop wallpaper to that image, but when doing wallpaper afterwards to get the path back the encoding is corrupted:

C:\Users\sindresorhus\Desktop\f�.jpg

My C skills are noobish at best and would really appreciate some guidance on this :)

Compiled with GCC on Windows 8.1.

Use return, not exit()

Even though it's pretty innocuous in this program, try to use return 0; instead of exit(0); when in the main function.

Cannot set Windows wallpaper

Hi I am developing a tool where I tried to use your program. But in some case I cannot set wallpaper use the following command:
wallpaper set [Filepath] --scale tile

This is the file I used
_tmp_new.zip

And in some other moment I did see it works, after that I kept trying but always failed.

Hope you can help me. I really like the simplicity and user-friendliness of this tool and would like to incorporate it into my work. Thank you!

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.