Skip to content

Instantly share code, notes, and snippets.

@drasill
Last active November 3, 2022 10:29
Show Gist options
  • Save drasill/d3f8def77643742678a9a5a235cd71fa to your computer and use it in GitHub Desktop.
Save drasill/d3f8def77643742678a9a5a235cd71fa to your computer and use it in GitHub Desktop.
bspwm : External Rules & Config for right-stacked windows
#! /bin/sh
# ~/.config/bspwm/bspwmrc
#...
bspc config external_rules_command ~/.config/bspwm/scripts/external_rules.sh
#! /bin/sh
# ~/.config/bspwm/scripts/external_rules.sh
# If a preselection exists, use it
has_presel=$(bspc query --nodes --node '.!automatic')
if [ ! -z $has_presel ]; then
exit 0
fi
# Check if root node is horizontal (sorry you need "jq" for this)
firstSplit=$(bspc query -T -d -n '@/' | jq -r '.splitType')
if [ $firstSplit = 'horizontal' ]; then
# Horizontal mode, create the main window on the left
echo "node=@/"
echo "split_dir=west"
echo "split_ratio=0.7"
exit 0
fi
# Otherwise, it depends on the number of existing (non-float) windows
num=$(bspc query -N -n '.leaf.!floating' -d | wc -l)
if [ $num -eq 0 ]; then
# No window, just put it here
exit 0
elif [ $num -eq 1 ]; then
# One window, split east
echo "split_dir=east"
echo "split_ratio=0.7"
else
# More than one window, split south
echo "node=@/2"
echo "split_dir=south"
echo "split_ratio=0.5"
fi
# ~/.config/sxhkd/sxhkdrc
# Useful commands to work with the right-stacked windows
# balance windows
super + b
bspc node @parent -B
# zoom (swap to biggest window)
super + z
bspc node -s biggest.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment