Advertisement
Dobbie03

t2

Jan 13th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # t2 - PLACEMENT DAY
  4.  
  5. # Special thanks to grocid for gtile, on which this project is heavily based.
  6. # https://github.com/grocid/gtile
  7.  
  8. # Usage: t2 PLACEMENT [margin]
  9.  
  10. # The script takes one mandatory argument: a 4-character string that defines
  11. # the placement of the window. The substrings are explained in the code comments
  12. # that accompany each variable.
  13.  
  14. # The optional second argument defines the padding margin between
  15. # windows. The default value is wide but maintains decent readability on
  16. # large screens.
  17.  
  18. # The script is generally pretty easy to extend for more general cases,
  19. # such as using more than 2 non-fullscreen vertical slices to tile or using
  20. # hexadecimal letters to allow for more than 9 horizontal slices.
  21. # I may eventually write them in myself if demand is there, but note that
  22. # these exceed my own use case, so motivation is weak at the moment.
  23.  
  24. # Since it was written especially with MATE in mind, it has a built-in
  25. # safeguard to prevent accidentally tiling the Caja desktop window, but this
  26. # can easily be accomplished for the desktop/root-like windows of other
  27. # environments as well.
  28.  
  29. if [ "$(xdotool getactivewindow getwindowname)" = "x-caja-desktop" ]
  30. then
  31. echo "Yeah, not movin' that one."
  32. exit 2
  33. fi
  34.  
  35. # Config - Change these to match your own environment ##########################
  36.  
  37. # You guessed it.
  38. screen_width=7680
  39.  
  40. # If and only if you have a *bottom* panel.
  41. panel_height=24
  42.  
  43. # This is a stupid way to format this, but it's also in prep to re-write
  44. # it to be grabbed by xrandr.
  45. screen_height=$(( 2160 - $panel_height ))
  46.  
  47.  
  48. # Tiling preferences ###########################################################
  49.  
  50. # [0-9] Number of horizontal tile slices
  51. divs=${1:0:1}
  52.  
  53. # [0-9] First horizontal slice to occupy
  54. x0=$(( ${1:1:1} - 1 ))
  55.  
  56. # [0-9] Last horizontal slice to occupy
  57. # (Note that the script will fail out if $x0 > $x1.
  58. # $x0 = $x1 is acceptable and gives a single-slice-width
  59. # window.
  60. x1=$(( ${1:2:1} - 1 ))
  61.  
  62. # [fhl] Vertical placement
  63. # l=lower half-screen
  64. # h=higher half-screen
  65. # f=fullscreen
  66. yp=${1:3:1}
  67.  
  68. margin=${margin:-48}
  69.  
  70. if [ ! -z "$2" ]
  71. then
  72. margin="$2"
  73. fi
  74.  
  75. # Window Placement #############################################################
  76.  
  77. # Basic (/single-)tile width.
  78. t_width=$(( $(( $screen_width / $divs )) - $(( $(( $divs + 1 )) * $margin )) / $divs ))
  79.  
  80. # Horizontal placement of the left edge.
  81. c=$(( $x0 * $(( $t_width + $margin )) + $margin ))
  82.  
  83. width=$(( $(( $x1 - $x0 + 1 )) * $t_width + $(( $(( $x1 - $x0 )) * $margin )) ))
  84.  
  85. case "$yp" in
  86. "h")
  87. height=$(( $(( $screen_height - $(( 3 * $margin )) )) / 2 ))
  88. # Vertical placement of the upper edge.
  89. d=$margin
  90. ;;
  91. "f")
  92. height=$(( $screen_height - $(( 2 * $margin )) ))
  93. d=$margin
  94. ;;
  95. "l")
  96. height=$(( $(( $screen_height - $(( 3 * $margin )) )) / 2 ))
  97. d=$(( $height + 2 * $margin ))
  98. ;;
  99. *)
  100. echo "Usage: $(basename $0) [0-9][0-9][0-9][flh]"
  101. exit 3
  102. ;;
  103. esac
  104.  
  105. xdotool getactivewindow windowsize $width $height windowmove $c $d
  106.  
  107. unset width height c d
  108.  
  109. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement