Skip to content

Instantly share code, notes, and snippets.

@DuaneNielsen
Created February 17, 2026 17:13
Show Gist options
  • Select an option

  • Save DuaneNielsen/9c31da242bcd351ddce81d3c2a69866c to your computer and use it in GitHub Desktop.

Select an option

Save DuaneNielsen/9c31da242bcd351ddce81d3c2a69866c to your computer and use it in GitHub Desktop.
Spotify toggle setup for niri + waybar

Spotify Toggle Setup for Niri + Waybar

A clean Spotify integration for niri that gives you a floating, toggle-able Spotify window controlled from waybar.

Features

  • Click "Spotify" in waybar to show/hide the window
  • Spotify opens as a floating window in the top-right corner
  • Window remembers its position if you drag it
  • Track info shows in waybar with play/pause, next, previous controls
  • Hidden Spotify moves to workspace 9 (out of the way but keeps playing)

Files

1. Niri Window Rule (~/.config/niri/config.kdl)

Add this to your window rules section:

// Spotify as floating window (top-right)
window-rule {
    match app-id="Spotify"
    open-floating true
    default-column-width { fixed 700; }
    default-window-height { fixed 500; }
    default-floating-position x=32 y=32 relative-to="top-right"
}

2. Waybar Config (~/.config/waybar/config)

Add these modules to your modules-right:

"modules-right": ["custom/spotify-app", "custom/spotify-track", ...]

And add the module definitions:

"custom/spotify-app": {
    "format": " {}",
    "exec": "echo Spotify",
    "interval": 60,
    "on-click": "~/.config/waybar/scripts/spotify-toggle.sh"
},
"custom/spotify-track": {
    "format": "{}",
    "max-length": 35,
    "interval": 1,
    "exec": "~/.config/waybar/scripts/spotify-track.sh",
    "on-click": "playerctl -p spotify play-pause",
    "on-click-right": "playerctl -p spotify next",
    "on-click-middle": "playerctl -p spotify previous"
}

3. Toggle Script (~/.config/waybar/scripts/spotify-toggle.sh)

#!/bin/bash

spotify_info=$(niri msg --json windows | jq -r '.[] | select(.app_id == "Spotify")')
spotify_id=$(echo "$spotify_info" | jq -r '.id // empty')
is_focused=$(echo "$spotify_info" | jq -r '.is_focused // false')

if [ -z "$spotify_id" ]; then
    # Launch Spotify
    spotify &
elif [ "$is_focused" = "true" ]; then
    # Spotify is focused, hide it to workspace 9
    niri msg action move-window-to-workspace --window-id "$spotify_id" --focus false 9
else
    # Bring it back to workspace 1 and focus
    niri msg action move-window-to-workspace --window-id "$spotify_id" 1
    niri msg action focus-window --id "$spotify_id"
fi

4. Track Script (~/.config/waybar/scripts/spotify-track.sh)

#!/bin/bash
player_status=$(playerctl -p spotify status 2>/dev/null)
if [ "$player_status" = "Playing" ]; then
    echo "$(playerctl -p spotify metadata artist 2>/dev/null) - $(playerctl -p spotify metadata title 2>/dev/null)"
elif [ "$player_status" = "Paused" ]; then
    echo "$(playerctl -p spotify metadata artist 2>/dev/null) - $(playerctl -p spotify metadata title 2>/dev/null)"
else
    echo ""
fi

Dependencies

sudo apt install playerctl jq

Usage

Action Result
Click " Spotify" Toggle window visibility (launch if not running)
Click track name Play/pause
Right-click track Next track
Middle-click track Previous track

Notes

  • Requires niri v25.01+ for default-floating-position
  • Spotify hides to workspace 9 when toggled off
  • Window position persists after dragging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment