Advertisement
onejdc

panel_finder.sh

Sep 17th, 2023 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.37 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. # @TODO: Add convenience functions to give bottom-right X,Y
  28. # @TODO: Add gap functionality
  29.  
  30.  
  31.  
  32. # -------------------- RND --------------------
  33. round()
  34. {
  35.   echo $(printf %.2f $(echo "scale=$2;((10^$2)*$1)+0.5)/(10^$2)" | bc))
  36. };
  37.  
  38.  
  39. #### Get initial values
  40. gap=5
  41.  
  42. # % of width of side columns, expressed as a decimal
  43. sideColumnWidthRatio=".25"
  44.  
  45. # number of rows in each Side column. Current Max = 2
  46. numSideColumnRows=2
  47.  
  48. # use xrandr utility + awk to get the screen width & height in pixels
  49. screenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
  50. screenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
  51.  
  52. # Determine actual width of columns, based on GAP and requested ratio size
  53.  
  54. # this is what we want to achieve, but because bash doesn't support floating-point,
  55. # we have to get creative
  56. # sideColumnWidth=$(( $screenWidth * $sideColumnWidthRatio - $gap | bc -l))
  57. sw=$( echo "$screenWidth*$sideColumnWidthRatio" | bc -l)
  58. # After we get the value, we basically FLOOR by dropping everything .+*
  59. sw=${sw%.*}
  60. sideColumnWidth=$(( $sw - $gap ))
  61. mainColumnWidth=$(( $screenWidth - $sideColumnWidth * 2))
  62.  
  63. # determine side column panel heights, adjusting for Number of Rows and Gaps (NumRows-1)
  64. sideColumnPanelHeight=$(( $screenHeight / $numSideColumnRows - $gap * ($numSideColumnRows - 1) ))
  65.  
  66. # -------------------- Panel 1 --------------------
  67. panel1_startX=0
  68. panel1_startY=0
  69. panel1_width=$sideColumnWidth
  70. panel1_height=$sideColumnPanelHeight
  71.  
  72. # -------------------- Panel 2 --------------------
  73. panel2_startX=0
  74. panel2_startY=$(( $panel1_height + $gap ))
  75. panel2_width=$sideColumnWidth
  76. panel2_height=$sideColumnPanelHeight
  77.  
  78. # -------------------- Panel 3 --------------------
  79. panel3_startX=$(( $sideColumnWidth + $gap))
  80. panel3_startY=0
  81. panel3_width=$mainColumnWidth
  82. panel3_height=$screenHeight
  83.  
  84. # -------------------- Panel 4 --------------------
  85. panel4_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap * 2))
  86. panel4_startY=0
  87. panel4_width=$sideColumnWidth
  88. panel4_height=$sideColumnPanelHeight
  89.  
  90. # -------------------- Panel 5 --------------------
  91. panel5_startX=$panel4_startX
  92. panel5_startY=$(( $panel4_height + $gap ))
  93. panel5_width=$sideColumnWidth
  94. panel5_height=$sideColumnPanelHeight
  95.  
  96.  
  97. # -------------------- MAIN --------------------
  98. while getopts p:v: flag
  99. do
  100.     case "${flag}" in
  101.         p) panel=panel${OPTARG};;
  102.         v) value=${OPTARG};;
  103.     esac
  104. done
  105.  
  106.  
  107. varName="${panel}_${value}"
  108. echo "${!varName}"
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement