-
-
Save emanuele6/9eab3f7867ea446f5e9bc6ce5561ebdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
case "$#" in | |
'1') ;; | |
'0') echo "No arguments given." >&2; exit 2 ;; | |
*) echo "Too many arguments." >&2; exit 2 ;; | |
esac | |
dir=$1 | |
case "$dir" in | |
'west'|'east'|'south'|'north') ;; | |
*) echo "invalid argument: $1" >&2; exit 2 ;; | |
esac | |
ensure_tiled() | |
{ | |
# if the focused node is not a window, we don't need to do anything. | |
bspc query -N -n focused.window > /dev/null \ | |
|| return | |
# let's not change the state of the focused window to tiled if | |
# the (user) layout of the focused desktop is not tiled. | |
bspc query -D -d focused.user_tiled > /dev/null \ | |
|| return | |
# if the state of the focused window is neither tiled nor pseudo_tiled, | |
# change its state to its last state; | |
# if its state is still neither tiled nor pseudo_tiled, change its state | |
# to tiled. | |
if | |
bspc node focused.fullscreen -t '~fullscreen' \ | |
|| bspc node focused.floating -t '~floating' | |
then | |
bspc node 'focused.!tiled.!pseudo_tiled.window' -t tiled | |
fi | |
} | |
# if no node is focused, exit. | |
bspc query -N -n > /dev/null \ | |
|| exit | |
# if the focused node is the root node, just call ensure_tiled and exit. | |
bspc query -N -n '@/.focused' > /dev/null && { | |
ensure_tiled | |
exit | |
} | |
case "$dir" in | |
'west'|'north') | |
# ensure that the focused node is the 1st child of the root node. | |
bspc node '@/1.!focused' -s '@/2.focused' || { | |
bspc node '@/1.!focused#focused' -n '@/' \ | |
&& bspc node '@/1.!focused' -s '@/2.focused' | |
} | |
;; | |
'east'|'south') | |
# ensure that the focused node is the 2nd child of the root node. | |
bspc node '@/2.!focused' -s '@/1.focused' \ | |
|| bspc node '@/2.!focused#focused' -n '@/' | |
;; | |
esac | |
case "$dir" in | |
'west'|'east') | |
# ensure that the split type of the root node is vertical. | |
bspc node '@/.!vertical' -R -90 \ | |
&& bspc node '@brother' -R 90 | |
;; | |
'north'|'south') | |
# ensure that the split type of the root node is horizontal. | |
bspc node '@/.!horizontal' -R 90 \ | |
&& bspc node '@brother' -R -90 | |
;; | |
esac | |
ensure_tiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Move the focused node to the given side of the tiled area. | |
super + {Left,Up,Right,Down} | |
bspside {west,north,east,south} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The current version uses new bspwm features not released in 0.9.10 to simplify the code; if you want an equivalent version that is release compatible, see this revision.