Advertisement
onejdc

panel_finder.sh

Sep 20th, 2023 (edited)
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script assumes a monitor is divided up into the following sections:
  4. #
  5. #     25%             50%              25%
  6. # +----------+--------------------+----------+
  7. # |          |                    |          |
  8. # |    1     |                    |     4    |
  9. # |          |                    |          |
  10. # +----------+         3          +----------+
  11. # |          |                    |          |
  12. # |    2     |                    |     5    |
  13. # |          |                    |          |
  14. # +----------+--------------------+----------+
  15.  
  16. # How to use:
  17. # Pass in the Panel #, along with the value you need:
  18. # e.g.   panel_finder.sh -p 1 -v startX
  19. #
  20. # The following values are available:
  21. #
  22. #   startX  - The starting X value (top-left)
  23. #   startY  - The starting Y value (top-left)
  24. #   width   - The width of the panel
  25. #   height  - the height of the panel
  26. #
  27. # You can also pass in an optional -l flag for layout, giving 3 or 5
  28. # the default is 5 panels
  29. #
  30. # @TODO: Add convenience functions to give bottom-right X,Y
  31. # @TODO: Add gap functionality
  32.  
  33.  
  34.  
  35. # -------------------- RND --------------------
  36. round()
  37. {
  38.   echo $(printf %.2f $(echo "scale=$2;((10^$2)*$1)+0.5)/(10^$2)" | bc))
  39. };
  40.  
  41.  
  42. #### Get initial values
  43. gap=5
  44. layout=5
  45. herbstString=false
  46.  
  47. # % of width of side columns, expressed as a decimal
  48. sideColumnWidthRatio=".25"
  49.  
  50. # number of rows in each Side column. Current Max = 2
  51. numSideColumnRows=2
  52.  
  53. # use xrandr utility + awk to get the screen width & height in pixels
  54. screenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
  55. screenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
  56.  
  57. # Determine actual width of columns, based on GAP and requested ratio size
  58.  
  59. # this is what we want to achieve, but because bash doesn't support floating-point,
  60. # we have to get creative
  61. # sideColumnWidth=$(( $screenWidth * $sideColumnWidthRatio - $gap | bc -l))
  62. sw=$( echo "$screenWidth*$sideColumnWidthRatio" | bc -l)
  63. # After we get the value, we basically FLOOR by dropping everything .+*
  64. sw=${sw%.*}
  65. sideColumnWidth=$(( $sw - $gap ))
  66. mainColumnWidth=$(( $screenWidth - $sideColumnWidth * 2))
  67.  
  68. # determine side column panel heights, adjusting for Number of Rows and Gaps (NumRows-1)
  69. sideColumnPanelHeight=$(( $screenHeight / $numSideColumnRows - $gap * ($numSideColumnRows - 1) ))
  70.  
  71.  
  72. #-----------------------------------------------------------------------------------------------
  73. #                                           Layouts
  74. # ----------------------------------------------------------------------------------------------
  75. #
  76. #  5 Panel Layout
  77. # -------------------- Panel 1 --------------------
  78. panel5_1_startX=0
  79. panel5_1_startY=0
  80. panel5_1_width=$sideColumnWidth
  81. panel5_1_height=$sideColumnPanelHeight
  82.  
  83. # -------------------- Panel 2 --------------------
  84. panel5_2_startX=0
  85. panel5_2_startY=$(( $panel1_height + $gap ))
  86. panel5_2_width=$sideColumnWidth
  87. panel5_2_height=$sideColumnPanelHeight
  88.  
  89. # -------------------- Panel 3 --------------------
  90. panel5_3_startX=$(( $sideColumnWidth + $gap))
  91. panel5_3_startY=0
  92. panel5_3_width=$mainColumnWidth
  93. panel5_3_height=$screenHeight
  94.  
  95. # -------------------- Panel 4 --------------------
  96. panel5_4_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap * 2))
  97. panel5_4_startY=0
  98. panel5_4_width=$sideColumnWidth
  99. panel5_4_height=$sideColumnPanelHeight
  100.  
  101. # -------------------- Panel 5 --------------------
  102. panel5_5_startX=$panel4_startX
  103. panel5_5_startY=$(( $panel4_height + $gap ))
  104. panel5_5_width=$sideColumnWidth
  105. panel5_5_height=$sideColumnPanelHeight
  106.  
  107.  
  108.  
  109.  
  110.  
  111. # ===========================================================
  112. # 3 Panel Layout
  113. # ===========================================================
  114.  
  115. # -------------------- Panel 1 --------------------
  116. panel3_1_startX=0
  117. panel3_1_startY=0
  118. panel3_1_width=$sideColumnWidth
  119. panel3_1_height=$screenHeight
  120.  
  121. #--------------------- Panel 2 --------------------
  122. panel3_2_startX=$(( $sideColumnWidth + $gap))
  123. panel3_2_startY=0
  124. panel3_2_width=$mainColumnWidth
  125. panel3_2_height=$screenHeight
  126.  
  127. #--------------------- Panel 3 --------------------
  128. panel3_3_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap *2))
  129. panel3_3_startY=0
  130. panel3_3_width=$sideColumnWidth
  131. panel3_3_height=$screenHeight
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. # -------------------- MAIN --------------------
  142. while getopts p:v:l:h: flag
  143. do
  144.     case "${flag}" in
  145.         p) panel_number=${OPTARG};;
  146.         v) value=${OPTARG};;
  147.         l) layout=${OPTARG:-layout};;
  148.         h) herbst=${OPTARG:-herbstString};;
  149.     esac
  150. done
  151.  
  152. panel_name="panel${layout}_${panel_number}_${value}"
  153. #varName="${pane}_${value}"
  154. #echo "${!varName}"
  155.  
  156.  
  157. # Display the result for a single value
  158. # or optionally for `herbstclient setmonitors <STR>`
  159.  
  160. if [ "$herbst" = false ] ; then
  161.  
  162.   echo "${!panel_name}"
  163.   exit 1
  164. fi
  165.  
  166. # Build the herbst string; widthXHeight+offset+0
  167. #  I think the last 0 is for a tag, but I really don't know
  168. echo "${panel3_1_width}x${panel3_1_height}+0+0 ${panel3_2_width}x${panel3_2_height}+${panel3_2_startX}+0 ${panel3_3_width}x${panel3_3_height}+${panel3_3_startX}+0"
  169.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement