Skip to main content

Overview

The wallpaper-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

Launches an interactive Rofi menu showing all wallpapers with thumbnail previews.

What It Does

Step-by-Step Execution

  1. Dependency Check
    • Verifies rofi is installed
    • Exits with error if rofi is missing
  2. Wallpapers Directory Check
    • Checks if ~/.config/wallpapers exists
    • Sends notification and exits gracefully if directory is missing
  3. 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
  4. 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
  5. Wallpaper Application
    • Validates selected wallpaper file exists
    • Saves wallpaper path to ~/.config/sway/wallpaper
    • Kills existing swaybg process
    • Launches new swaybg with selected wallpaper in fill mode
    • Sends success notification with wallpaper thumbnail

Configuration

Wallpapers Directory

FONDOS_DIR
string
default:"~/.config/wallpapers"
Directory containing wallpaper images. All image files in this directory will be available for selection.

Rofi Theme

THEME_PATH
string
Rofi theme file used for the wallpaper selection menu.

Wallpaper State File

SWAY_WALL_FILE
string
default:"~/.config/sway/wallpaper"
File storing the path to the currently active wallpaper. Read by Sway on startup.

Wallpaper Storage

Directory Structure

All files in this directory are treated as potential wallpapers. The script uses bash’s nullglob option, so non-existent patterns are safely ignored.

Adding Wallpapers

Notifications

The script uses notify-send for user feedback:

Success

Errors

Directory Not Found

No Images Found

File Not Found

Rofi Error

Error Handling

rofi Not Installed

Install rofi: 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

Sends notification and exits with code 1.

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

Displays Rofi menu with all wallpapers and thumbnail previews.

Keybinding in Sway

Add to ~/.config/sway/config:

Waybar Integration

Example Waybar custom module:

Load Wallpaper on Startup

Add to ~/.config/sway/config:
Or use the autostart script:

Organize Wallpapers by Category

The script only scans the top level of ~/.config/wallpapers/. Subdirectories are not searched.

Batch Download Wallpapers

swaybg Options

The script uses swaybg -m fill by default. You can modify the script to use different scaling modes:

Available Modes

  • stretch - Stretch to fill, ignoring aspect ratio
  • fill - Preserve aspect ratio, crop to fill (default)
  • fit - Preserve aspect ratio, letterbox if needed
  • center - Center image without scaling
  • tile - Tile the image
  • solid_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:
Example contents:
This file is read by:
  • 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:
This theme controls:
  • Window size and position
  • Icon size for thumbnails
  • Colors and fonts
  • Layout and spacing
Example customization:

Temporary Files

The script creates temporary files for Rofi input:
These are automatically cleaned up on exit using a trap:

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
  • theme-switcher.sh - Complete theme switching (includes wallpaper)
  • setwallpaper.sh - Set wallpaper from command line or scripts
  • autostart.sh - Restore wallpaper on Sway startup

Dependencies

Required

  • rofi - Application launcher with icon support
  • swaybg - Wallpaper utility for Wayland

Optional

  • notify-send (libnotify) - Desktop notifications

Troubleshooting

Thumbnails Not Showing

Ensure Rofi is compiled with icon support:
If not, reinstall rofi with icon support enabled.

Wallpaper Not Changing

Check if swaybg is running:
Manually test swaybg:

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