BSPWM - Moving windows out of the way


This time I want to show you my attempt on a Scratchpad like feature for BSPWM. It is not exactly a Scratchpad like the one of the I3 window manager, but you could easily modify my code to make it more Scratchpadly (Scratchpad windows are hidden and floating, I don’t care about floating).

I added the following keyboard shortcuts to my sxhkrc. The first one hides the current focused window. The second shortcut helps me to find the hidden window I want to unhide.

Code sxhkrc:

# hide window
super + period
    bspc node -g hidden

# unhide window
super + ctrl + period
    ${HOME}/.config/bspwm/bspcmd unhide

If I want to get a previously hidden window back, I hit the defined shortcut and the script bspcmd with the parameter unhide is called.

The bspcmd file is a bash script containing a set of functions to improve my workflow with BSPWM. For this post, I have shortened it to only show the necessary parts, when executed with unhide as parameter.

The script also requires two additional programms:

  • xtitle output the window title of the given window ID (WID)
  • rofi a window switcher, application launcher and dmenu replacement

Code bspcmd:

#!/bin/bash

CMD=${1:-help}; shift

help() {
    echo "Available commands:"
    echo "  * unhide - select and unhide window"
}

unhide() {
    action=${1:-list}
    case $action in
        "list")
            selection=`for id in $(bspc query -N -n .hidden); do
                title=$(xtitle $id)
                [[ -z "$title" ]] && title="<unnamed>"
                echo $id $title
            done | rofi -dmenu -i -p "Hidden windows" | cut -f1 -d' '`
            
            [[ -z "$selection" ]] && exit 1

            bspc node $selection -g hidden=off
            ;;
    esac
}

case $CMD in
    "help")
        help
        ;;
    "unhide")
        unhide $1
        ;;
    *)
        help
        ;;
esac

The unhide() function gathers all hidden windows, looks up the window title (if available) and displays a list using Rofi. On selecting a list entry, the hidden flag will be removed for that particular window so it will be displayed again.

KTHXBYE.