Bspwm Better Scratchpad

Table of Contents

Better scratchpad bspwm

Preface

The scratchpad scripts I found for bspwm SUCK. Some either stop working if you kill the terminal or bug out when you manage your window states. Here's a script I wrote that get's the job done RIGHT!

bspwm-scratch.png

I'm running tmux if you were wondering.

Setup stuff

The "scratchy" script checks to see if a terminal with the classname "scratchy" exists. If it doesn't exist, it creates it. If it does exist, it hides it.

>> /path/to/scratchy
#!/bin/sh

id=$(xdotool search --class scratchy);
if [ -z "$id" ]; then
        st -c scratchy;
else
        if [ ! -f /tmp/hide_scratch ]; then
                touch /tmp/hide_scratch && xdo hide "$id"
        elif [ -f /tmp/hide_scratch ]; then
                rm /tmp/hide_scratch && xdo show "$id"
        fi
fi

Next we'll assign special attributes for the window with the classname scratchy in our bspwmrc. I have it configured to automatically adjust the window position based on the size of the monitor. To get the window to be exactly centered, just do (1/2 monitor width)-(1/2 window width) as the X offset

>> /path/to/bspwmrc

# Calculate the center of the screen for a 600x400 scratchpad
scratchpad_xy="600x400"
display_xy=$(xdpyinfo | grep -i dimensions | awk '{ print $2 }')
half_display=$(echo $display_xy | tr 'x' ' ' | cut -f1 -d' ' | xargs -I _ echo _/2 | bc)
half_scratchpad=$(echo $scratchpad_xy | tr 'x' ' ' | cut -f1 -d' ' | xargs -I _ echo _/2 | bc)
offset=$(echo ${half_display}-${half_scratchpad} | bc)

# rectangle=WidthxHeight+Xoffset+Yoffset
bspc rule -a scratchy sticky=on state=floating rectangle=${scratchpad_xy}+${offs et}+0
>> /path/to/sxhkdrc
super + semicolon
        scratchy