tile.sh 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # recover max native resolution
  4. CURRES=$(xrandr | sed -n 3p | awk '{print $1}')
  5. FULLW="$(cut -d'x' -f1 <<< $CURRES)"
  6. FULLH="$(cut -d'x' -f2 <<< $CURRES)"
  7. # taskbar pixel height
  8. TASKH=25 # hardcoded
  9. # active window id
  10. # ID="-r :ACTIVE:" # does not work as consistently as the call to xdotool
  11. ID="-i -r `xdotool getwindowfocus`"
  12. # disable maximized attribute
  13. wmctrl $ID -b remove,maximized_vert
  14. wmctrl $ID -b remove,maximized_horz
  15. case "$1" in
  16. w)
  17. # tile left
  18. W=$(($FULLW / 2))
  19. H=$(($FULLH - $TASKH))
  20. X=0
  21. Y=0
  22. ;;
  23. e)
  24. # tile right
  25. W=$(($FULLW / 2))
  26. H=$(($FULLH - $TASKH))
  27. X=$W
  28. Y=0
  29. ;;
  30. n)
  31. # tile top
  32. W=$FULLW
  33. H=$((($FULLH - $TASKH) / 2))
  34. X=0
  35. Y=0
  36. ;;
  37. s)
  38. # tile bottom
  39. W=$FULLW
  40. H=$((($FULLH - $TASKH) / 2))
  41. X=0
  42. Y=$H
  43. ;;
  44. esac
  45. # resize
  46. wmctrl $ID -e 0,$X,$Y,$W,$H