Guest User

Untitled

a guest
Oct 25th, 2022
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Rotate tiling of windows.
  4. #
  5. # This assumes windows are tiled like so, which is what window-vtile does:
  6. # +---------+---------+
  7. # | main | second |
  8. # | window | window |
  9. # | full +---------+
  10. # | height | third |
  11. # | | window |
  12. # +---------+---------+
  13. #
  14. # This script will "rotate" the second window to the main window, the main
  15. # window to the third window, and the third window to the main window:
  16. # +---------+---------+
  17. # | second | third |
  18. # | | |
  19. # | +---------+
  20. # | | main |
  21. # | | |
  22. # +---------+---------+
  23. #
  24. # And pressing it again will rotate it once more in the same direction:
  25. # +---------+---------+
  26. # | third | main |
  27. # | | |
  28. # | +---------+
  29. # | | second |
  30. # | | |
  31. # +---------+---------+
  32. #
  33. # And a third press will restore the original situation.
  34.  
  35. set -euC
  36. IFS="
  37. "
  38.  
  39. border=2
  40. titlebar=16
  41. #border=2
  42. #if [ -f ~/.cwmrc ]; then
  43. # border=$(( 2 *
  44. # $( (grep ^borderwidth ~/.cwmrc || echo "1 1") | awk '{print $2}' )
  45. # ))
  46. #fi
  47.  
  48. # Find the main window by position.
  49. all_windows=$(xdotool search --name --desktop $(xdotool get_desktop) '')
  50. main_window=0
  51. for win in $all_windows; do
  52. eval $(xdotool getwindowgeometry --shell $win)
  53. [ $X -le 0 ] && [ $Y -le 0 ] && main_window=$win
  54. done
  55.  
  56. # No main window found; use the active window.
  57. [ $main_window -eq 0 ] && main_window=$(xdotool getactivewindow)
  58.  
  59. # Sort all the other windows in an array by Y-position, which means they're the
  60. # same order as on the screen
  61. other_windows=""
  62. for win in $all_windows; do
  63. [ $win -eq $main_window ] && continue
  64.  
  65. eval $(xdotool getwindowgeometry --shell $win)
  66. other_windows=$(printf "$Y $win\n$other_windows")
  67. done
  68. sorted=$(echo "$other_windows" | sort -n)
  69. other_windows=""
  70. for w in $sorted; do
  71. other_windows=$(printf "$other_windows\n$(echo "$w" | cut -d ' ' -f 2)")
  72. done
  73. other_windows=$(echo "$other_windows" | tail -n+2)
  74.  
  75. # Put main window to the bottom of the others.
  76. other_windows=$(printf "$other_windows\n$main_window")
  77.  
  78. # Top window is new "main" window.
  79. main_window=$(echo "$other_windows" | head -n 1)
  80. other_windows=$(echo "$other_windows" | tail -n+2)
  81.  
  82. # Now we can set the positions and resize!
  83. n_wins=$(echo "$other_windows" | wc -l)
  84. screen_width=$(xwininfo -root | grep Width | cut -d: -f2 | tr -d ' ')
  85. screen_height=$(xwininfo -root | grep Height | cut -d: -f2 | tr -d ' ')
  86. width=$(( $screen_width / 2 - $border ))
  87. height=$(( $screen_height - $border - $titlebar ))
  88.  
  89. # Position and size the main window.
  90. xdotool windowmove $main_window 0 0
  91. xdotool windowsize $main_window $width $height
  92.  
  93. # ... and the other windows.
  94. i=0
  95. for win in $other_windows; do
  96. xdotool windowmove $win $(( $width + $border )) \
  97. $(( $height / $n_wins * $i ))
  98. xdotool windowsize $win $width $(( $height / $n_wins ))
  99. i=$(( $i + 1 ))
  100. done
  101.  
Advertisement
Add Comment
Please, Sign In to add comment