Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # Rotate tiling of windows.
- #
- # This assumes windows are tiled like so, which is what window-vtile does:
- # +---------+---------+
- # | main | second |
- # | window | window |
- # | full +---------+
- # | height | third |
- # | | window |
- # +---------+---------+
- #
- # This script will "rotate" the second window to the main window, the main
- # window to the third window, and the third window to the main window:
- # +---------+---------+
- # | second | third |
- # | | |
- # | +---------+
- # | | main |
- # | | |
- # +---------+---------+
- #
- # And pressing it again will rotate it once more in the same direction:
- # +---------+---------+
- # | third | main |
- # | | |
- # | +---------+
- # | | second |
- # | | |
- # +---------+---------+
- #
- # And a third press will restore the original situation.
- set -euC
- IFS="
- "
- border=2
- titlebar=16
- #border=2
- #if [ -f ~/.cwmrc ]; then
- # border=$(( 2 *
- # $( (grep ^borderwidth ~/.cwmrc || echo "1 1") | awk '{print $2}' )
- # ))
- #fi
- # Find the main window by position.
- all_windows=$(xdotool search --name --desktop $(xdotool get_desktop) '')
- main_window=0
- for win in $all_windows; do
- eval $(xdotool getwindowgeometry --shell $win)
- [ $X -le 0 ] && [ $Y -le 0 ] && main_window=$win
- done
- # No main window found; use the active window.
- [ $main_window -eq 0 ] && main_window=$(xdotool getactivewindow)
- # Sort all the other windows in an array by Y-position, which means they're the
- # same order as on the screen
- other_windows=""
- for win in $all_windows; do
- [ $win -eq $main_window ] && continue
- eval $(xdotool getwindowgeometry --shell $win)
- other_windows=$(printf "$Y $win\n$other_windows")
- done
- sorted=$(echo "$other_windows" | sort -n)
- other_windows=""
- for w in $sorted; do
- other_windows=$(printf "$other_windows\n$(echo "$w" | cut -d ' ' -f 2)")
- done
- other_windows=$(echo "$other_windows" | tail -n+2)
- # Put main window to the bottom of the others.
- other_windows=$(printf "$other_windows\n$main_window")
- # Top window is new "main" window.
- main_window=$(echo "$other_windows" | head -n 1)
- other_windows=$(echo "$other_windows" | tail -n+2)
- # Now we can set the positions and resize!
- n_wins=$(echo "$other_windows" | wc -l)
- screen_width=$(xwininfo -root | grep Width | cut -d: -f2 | tr -d ' ')
- screen_height=$(xwininfo -root | grep Height | cut -d: -f2 | tr -d ' ')
- width=$(( $screen_width / 2 - $border ))
- height=$(( $screen_height - $border - $titlebar ))
- # Position and size the main window.
- xdotool windowmove $main_window 0 0
- xdotool windowsize $main_window $width $height
- # ... and the other windows.
- i=0
- for win in $other_windows; do
- xdotool windowmove $win $(( $width + $border )) \
- $(( $height / $n_wins * $i ))
- xdotool windowsize $win $width $(( $height / $n_wins ))
- i=$(( $i + 1 ))
- done
Advertisement
Add Comment
Please, Sign In to add comment