Skip to main content

Overview

The theme-switcher.sh script provides an interactive theme switcher for Sway using Rofi. It displays available themes with wallpaper previews and applies comprehensive theme changes including Kitty terminal colors, Waybar styling, Rofi colors, Sway window decorations, and wallpapers.
Themes are stored in ~/.config/themes/ with each theme in its own directory containing configuration files and wallpapers.

Location

Usage

Interactive Mode

Launches Rofi with theme previews for selection.

Direct Application

string
Name of the theme directory in ~/.config/themes/ to apply directly (skips Rofi selection)

What It Does

Step-by-Step Execution

  1. Theme Discovery
    • Scans ~/.config/themes/ for theme directories
    • Looks for wallpaper previews (.jpg, .png, .webp)
    • Builds Rofi menu with theme names and preview icons
  2. Theme Selection
    • Displays interactive Rofi menu (if no theme specified)
    • Shows wallpaper preview thumbnails for each theme
    • Uses custom Rofi theme: ~/.config/rofi/styles/_core/theme-switcher.rasi
  3. Backup Creation
    • Creates timestamped backups of existing configurations
    • Format: original.bak-YYYYMMDD-HHMMSS
    • Backs up before each component is modified
  4. Kitty Configuration
    • Copies theme’s kitty/ directory to ~/.config/kitty
    • Applies color scheme and terminal styling
  5. Waybar Configuration
    • Copies colors.css and style.css to ~/.config/waybar
    • Converts Hyprland-specific config to Sway format
    • Generates config-sway.jsonc with module replacements:
      • hyprland/workspaces → sway/workspaces
      • hyprland/window → sway/window
      • Special workspace toggle → kitty -e btop
  6. Sway Window Theme
    • Applies sway/theme.conf for window decorations
    • Sets border colors, title bar colors, and fonts
  7. Rofi Color Palette
    • Uses theme’s rofi-style/_core/palette.rasi if available
    • Otherwise, auto-generates from sway/theme.conf variables:
      • Extracts $bg, $fg, $active, $inactive colors
      • Extracts font configuration
      • Creates ~/.config/rofi/styles/_core/palette.rasi
  8. Wallpaper Application
    • Finds wallpaper file (wallpaper.jpg, .png, or .webp)
    • Saves path to ~/.config/sway/wallpaper
    • Kills existing swaybg process
    • Launches new swaybg with selected wallpaper
  9. Service Reloads
    • Restarts Waybar with new configuration
    • Reloads Sway to apply theme changes
    • Sends desktop notification on completion

Theme Structure

Each theme directory should follow this structure:

Required Files

file
required
Theme wallpaper image. At least one format must be present.

Optional Files

directory
Kitty terminal configuration files. Entire directory is copied to ~/.config/kitty.
file
Waybar color definitions (CSS variables).
file
Waybar styling and layout.
file
Waybar module configuration. Automatically converted from Hyprland to Sway format.
file
Sway window decoration theme with color variables:
  • $bg - Background color
  • $fg - Foreground color
  • $active - Active window color
  • $inactive - Inactive window color
  • font - Font definition
file
Custom Rofi color palette. If not provided, auto-generated from sway/theme.conf.

Sway Theme Configuration Format

Example sway/theme.conf:

Auto-Generated Rofi Palette

When no custom Rofi palette is provided, the script generates one from Sway theme variables:

Current Theme Tracking

The currently active theme is saved to:
This file contains the theme name and can be read by other scripts.

Notifications

The script sends desktop notifications using notify-send:

Success

Errors

Error Handling

Themes Directory Missing

Create the themes directory and add theme subdirectories.

Rofi Not Found

Install rofi: sudo pacman -S rofi

No Themes Available

Add at least one theme directory.

Theme Not Found

The specified theme directory doesn’t exist.

No Wallpaper

Each theme must have a wallpaper.jpg, wallpaper.png, or wallpaper.webp file.

Missing swaybg

Install swaybg: sudo pacman -S swaybg

Exit Codes

  • 0: Success (theme applied) or cancelled by user
  • 1: Error (missing dependencies, theme not found, or no wallpaper)

Examples

Interactive Theme Selection

Displays Rofi menu with all available themes and wallpaper previews.

Apply Specific Theme

Directly applies the “catppuccin-mocha” theme without showing Rofi menu.

Keybinding in Sway

Add to ~/.config/sway/config:

Create New Theme

Backup Management

Backups are created with timestamps. Clean old backups periodically:

Integration with Waybar

Example Waybar module for theme switching:

Dependencies

  • rofi - Application launcher (for theme selection UI)
  • swaybg - Wallpaper utility (for applying wallpapers)
  • swaymsg - Sway IPC tool (for reloading configuration)
  • waybar - Status bar (optional, for bar theming)
  • notify-send - Desktop notifications (optional)

Notes

  • Themes are applied system-wide and persist across reboots
  • The script is designed to work with both Hyprland and Sway themes (auto-converts)
  • Backups are created automatically to prevent data loss
  • Rofi theme preview requires icons support (-show-icons flag)
  • The script uses set -euo pipefail for strict error handling

Source Code

View the full source: .config/rofi/scripts/theme-switcher.sh (186 lines) Author: Fravelz