This library uses the _XROOTPMAP_ID and ESETROOT_PMAP_ID attributes. It sets them appropriately when updating
the wallpaper, which should ensure compatibility with most other tools.
These examples use sharp to transform the raw pixel data into images and vice-versa.
This library only speaks raw 3 channels RGB buffers.
This is a helper method to get the physical screen layout on the X screen. This is useful for multi-screen
configurations, as this library doesn't handle it for you.
import { getScreens } from '@cyyynthia/x11-wallpaper'const screens = await getScreens()console.log(screens) // Output of type `ScreenConfig` - See the index.d.ts for more details.
Multi-screen example usage
Set a wallpaper per-screen
import sharp from 'sharp'import { getScreens, setWallpaper } from '../src/index.js'// Retrieve screen congfigurationconst screens = await getScreens()// Create the imageconst img = sharp({ create: { width: screens.width, height: screens.height, channels: 3, background: '#000', },})// Load our wallpapersconst WALLPAPER_PATHS = { outputName: '...', ... } // Output name is the name of the screen (e.g. "DP-0" or "HDMI-0")const layers = []for (
Get per-screen wallpapers
import sharp from 'sharp'import { getScreens, getWallpaper } from '../src/index.js'// Retrieve screen congfigurationconst screens = await getScreens()// Retrieve & parse wallpaperconst wallpaperRaw = await getWallpaper()const wallpaper = sharp(wallpaperRaw.data, { raw: { width: wallpaperRaw.width, height: wallpaperRaw.height, channels: 3, }})// Save wallpapers to diskfor (const screen of screens.screens) { await wallpaper.clone() .extract