Overview
Thewallpaper-switcher.sh script provides a quick way to change your wallpaper without modifying other theme settings. It displays a Rofi menu with thumbnail previews of all wallpapers in your wallpapers directory and applies the selected wallpaper using swaybg.
This script only changes the wallpaper, not colors or other theme elements. Use
theme-switcher.sh for comprehensive theme changes.Location
Usage
What It Does
Step-by-Step Execution
-
Dependency Check
- Verifies
rofiis installed - Exits with error if rofi is missing
- Verifies
-
Wallpapers Directory Check
- Checks if
~/.config/wallpapersexists - Sends notification and exits gracefully if directory is missing
- Checks if
-
Wallpaper Discovery
- Scans
~/.config/wallpapers/for all image files - Supports any image format (jpg, png, webp, etc.)
- Creates temporary file with wallpaper list and thumbnail paths
- Scans
-
Interactive Selection
- Displays Rofi menu with:
- Wallpaper filenames
- Thumbnail previews using
-show-icons - Custom theme:
~/.config/rofi/styles/_core/wallpaper-switcher.rasi
- Handles Rofi errors gracefully
- Displays Rofi menu with:
-
Wallpaper Application
- Validates selected wallpaper file exists
- Saves wallpaper path to
~/.config/sway/wallpaper - Kills existing
swaybgprocess - Launches new
swaybgwith selected wallpaper in fill mode - Sends success notification with wallpaper thumbnail
Configuration
Wallpapers Directory
Directory containing wallpaper images. All image files in this directory will be available for selection.
Rofi Theme
Rofi theme file used for the wallpaper selection menu.
Wallpaper State File
File storing the path to the currently active wallpaper. Read by Sway on startup.
Wallpaper Storage
Directory Structure
nullglob option, so non-existent patterns are safely ignored.
Adding Wallpapers
Notifications
The script usesnotify-send for user feedback:
Success
Errors
Directory Not Found
No Images Found
File Not Found
Rofi Error
Error Handling
rofi Not Installed
sudo pacman -S rofi
Wallpapers Directory Missing
Sends notification and exits gracefully (no error code).No Wallpapers Found
Sends notification and exits gracefully (no error code).Selected File Not Found
Rofi Execution Error
Captures stderr and displays truncated error message (max 220 characters) in notification.Exit Codes
- 0: Success (wallpaper changed) or cancelled by user (Esc pressed)
- 1: Error (rofi not installed or selected file not found)
Examples
Standard Usage
Keybinding in Sway
Add to~/.config/sway/config:
Waybar Integration
Example Waybar custom module:Load Wallpaper on Startup
Add to~/.config/sway/config:
Organize Wallpapers by Category
Batch Download Wallpapers
swaybg Options
The script usesswaybg -m fill by default. You can modify the script to use different scaling modes:
Available Modes
stretch- Stretch to fill, ignoring aspect ratiofill- Preserve aspect ratio, crop to fill (default)fit- Preserve aspect ratio, letterbox if neededcenter- Center image without scalingtile- Tile the imagesolid_color- Use solid color (requires color instead of image)
Custom Scaling
Modify line 57 in the script:Current Wallpaper Tracking
The current wallpaper path is saved to:- Sway configuration on startup
- Other scripts that need to know the current wallpaper
- Theme switcher when applying themes
Rofi Configuration
The script uses a custom Rofi theme located at:- Window size and position
- Icon size for thumbnails
- Colors and fonts
- Layout and spacing
Temporary Files
The script creates temporary files for Rofi input:Performance Considerations
- Large wallpaper collections: Rofi may take a moment to load thumbnails for 100+ images
- High-resolution images: Thumbnails are generated on-the-fly by Rofi
- Network storage: Accessing wallpapers over network shares may be slower
Related Scripts
theme-switcher.sh- Complete theme switching (includes wallpaper)setwallpaper.sh- Set wallpaper from command line or scriptsautostart.sh- Restore wallpaper on Sway startup
Dependencies
Required
rofi- Application launcher with icon supportswaybg- Wallpaper utility for Wayland
Optional
notify-send(libnotify) - Desktop notifications
Troubleshooting
Thumbnails Not Showing
Ensure Rofi is compiled with icon support:Wallpaper Not Changing
Check if swaybg is running:Permission Errors
Ensure the script is executable:Rofi Theme Missing
If the Rofi theme file is missing, Rofi will use the default theme:Source Code
View the full source:.config/rofi/scripts/wallpaper-switcher.sh (63 lines)
Author: Fravelz