Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script assumes a monitor is divided up into the following sections:
- #
- # 25% 50% 25%
- # +----------+--------------------+----------+
- # | | | |
- # | 1 | | 4 |
- # | | | |
- # +----------+ 3 +----------+
- # | | | |
- # | 2 | | 5 |
- # | | | |
- # +----------+--------------------+----------+
- # How to use:
- # Pass in the Panel #, along with the value you need:
- # e.g. panel_finder.sh -p 1 -v startX
- #
- # The following values are available:
- #
- # startX - The starting X value (top-left)
- # startY - The starting Y value (top-left)
- # width - The width of the panel
- # height - the height of the panel
- #
- # @TODO: Add convenience functions to give bottom-right X,Y
- # @TODO: Add gap functionality
- # -------------------- RND --------------------
- round()
- {
- echo $(printf %.2f $(echo "scale=$2;((10^$2)*$1)+0.5)/(10^$2)" | bc))
- };
- #### Get initial values
- gap=5
- # % of width of side columns, expressed as a decimal
- sideColumnWidthRatio=".25"
- # number of rows in each Side column. Current Max = 2
- numSideColumnRows=2
- # use xrandr utility + awk to get the screen width & height in pixels
- screenWidth=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
- screenHeight=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f2)
- # Determine actual width of columns, based on GAP and requested ratio size
- # this is what we want to achieve, but because bash doesn't support floating-point,
- # we have to get creative
- # sideColumnWidth=$(( $screenWidth * $sideColumnWidthRatio - $gap | bc -l))
- sw=$( echo "$screenWidth*$sideColumnWidthRatio" | bc -l)
- # After we get the value, we basically FLOOR by dropping everything .+*
- sw=${sw%.*}
- sideColumnWidth=$(( $sw - $gap ))
- mainColumnWidth=$(( $screenWidth - $sideColumnWidth * 2))
- # determine side column panel heights, adjusting for Number of Rows and Gaps (NumRows-1)
- sideColumnPanelHeight=$(( $screenHeight / $numSideColumnRows - $gap * ($numSideColumnRows - 1) ))
- # -------------------- Panel 1 --------------------
- panel1_startX=0
- panel1_startY=0
- panel1_width=$sideColumnWidth
- panel1_height=$sideColumnPanelHeight
- # -------------------- Panel 2 --------------------
- panel2_startX=0
- panel2_startY=$(( $panel1_height + $gap ))
- panel2_width=$sideColumnWidth
- panel2_height=$sideColumnPanelHeight
- # -------------------- Panel 3 --------------------
- panel3_startX=$(( $sideColumnWidth + $gap))
- panel3_startY=0
- panel3_width=$mainColumnWidth
- panel3_height=$screenHeight
- # -------------------- Panel 4 --------------------
- panel4_startX=$(( $sideColumnWidth + $mainColumnWidth + $gap * 2))
- panel4_startY=0
- panel4_width=$sideColumnWidth
- panel4_height=$sideColumnPanelHeight
- # -------------------- Panel 5 --------------------
- panel5_startX=$panel4_startX
- panel5_startY=$(( $panel4_height + $gap ))
- panel5_width=$sideColumnWidth
- panel5_height=$sideColumnPanelHeight
- # -------------------- MAIN --------------------
- while getopts p:v: flag
- do
- case "${flag}" in
- p) panel=panel${OPTARG};;
- v) value=${OPTARG};;
- esac
- done
- varName="${panel}_${value}"
- echo "${!varName}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement