#graphics #sdl #windows


Use SDL to actively render to the desktop background

1 unstable release

0.1.0 Jul 20, 2023

#110 in Rendering


80 lines


Use SDL2 to actively render to the desktop background. Use simple functions to get access to either the desktop background window, or a Rust-SDL2 canvas bound to it. Then, you can render whatever you want for ultimate customization.


As of now, only Windows is supported. sdl2_wallpaper has only been developed with Windows 10, so that is the only OS that is expected to work. I also haven't seen if the MinGW SDL2 development libraries work with this yet. For setting up Rust-SDL2 I've used both cargo-vcpkg and the "bundled" feature successfully.


Prerequisite: Make sure you have Rust-SDL2 installed, and that it is working.

There are two easy installation options for sdl2_wallpaper.

  1. Use Cargo from the terminal
cargo add sdl2_wallpaper
  1. Add the dependency to your Cargo.toml file
sdl2_wallpaper = "0.1.0"


(Based on the Rust-SDL2 example)

use sdl2::pixels::Color;
use sdl2::event::Event;
use std::time::Duration;

fn main() {
    let sdl = sdl2::init().unwrap();
    let video_subsystem = sdl.video().unwrap();
    // The only real difference here from the Rust-SDL2 example is
    // how we get the window/canvas.

    let mut canvas = sdl2_wallpaper::get_canvas(video_subsystem).unwrap();
    // If you'd rather get the window and then build the canvas from that:

    // let window = sdl2_wallpaper::get_window(video_subsystem).unwrap();
    // [maybe do something to your window]
    // let mut canvas = window.into_canvas().build().unwrap()

    canvas.set_draw_color(Color::RGB(0, 64, 255));

    let mut event_pump = sdl.event_pump().unwrap();
    let mut i = 0;
    'running: loop {
        i = (i + 1) % 255;
        canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
        for event in event_pump.poll_iter() {
            match event {
                Event::Quit { .. } => break 'running,
                _ => {}
        std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));


Pull requests are very welcome. Please feel free to make this more rusty! For major updates, like supporting another OS, please open an issue first to discuss what you want, as well as a course of action.

Since this is a new package, there is so much to add to this and I'm sure we'll find bugs. Let's work together!


MIT OR Apache-2.0


~303K SLoC